Nico Rehwaldt
2022
Context sensitive languages require full context for parsing.
a + b
# can be arithmetic operation (a) + (b)
# or name (a,+,b)
# depending on <grammar> + <context>
Be able to parse the token steam ourselves (programmatically) and produce tokens
input -> token(s)
Track internal parse state as the parser operates
context + (shift/reduce symbol) -> new context
Information can be fed into tokenizer to implement contextual parsing
import {
parser,
trackVariables
} from 'lezer-feel';
const contextTracker = trackVariables({
'if foo then bar': 1
});
const contextualParser = parser.configure({
contextTracker
});
// recognizes <if foo then bar> as a <VariableName>
contextualParser.parse('if foo then bar');
Handling context sensitivity at the core (language level) simplifies downstream jobs styling, interpreting, and introspection.