[GrammarKit] Predicated/context dependent parse

Answered

Hi there,

in a grammar (GrammarKit .bnf for an Oberon-2 dialect) of my plugin there are two constructs for which the correct parse depends on thec context.

More concretely those two are procedure call and type guard:

// example for procedure call
maybe_proc(param);

// example for type guard ("if variable <name> has type <Type>...")
dummy := name(Type).field

My current idea for handling this is to use a predicate in the type guard rule to check that name is a variable and/or Type refers to a type. For this I would need to collect the relevant info during parse. I was thinking about using the PsiBuilder's user data for storing the info.

So I am wondering whether it is a sensible approach and what the best way for collecting and storing the required info is.

0
1 comment

Hi,

Getting information about the type during parsing would require resolving and potentially parsing other files. Parsing should be fast, and this approach doesn't sound performant.

I suggest handling both cases with the same tree structure and handling them appropriately at the annotator, completion, reference, etc. levels.

0

Please sign in to leave a comment.