[GrammarKit] Predicated/context dependent parse
已回答
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.
请先登录再写评论。
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.