Replies: 6 comments
-
It seems like the solution was simply to create an object of the logic parser and use that within the body of the subrule. It's probably better than importing rules anyways, which sounds messy even if it were possible. |
Beta Was this translation helpful? Give feedback.
-
That seems like a good solution in terms of separation of concerns. |
Beta Was this translation helpful? Give feedback.
-
There are a few patterns I am aware of in terms of structuring multiple parsers. InheritanceMixin like approachI think the mixin like approach which are basically utility functions that are passed the parser's Generally Chevrotain is just plain JavaScript, So I am sure other ways to compose parsers will be possible... |
Beta Was this translation helpful? Give feedback.
-
@bd82 By subsets of the token vectors, did you mean overlaps between them? Luckily for my use case, there is minimal overlap (whitespace being the only one) and all I needed to do was to parse the logical sentences and put them in a TS object for the subrule, so not much interaction there. Thanks for linking the inheritance examples, that's more what I was thinking of when I first wanted to share rules and I'll reference them if I ever run into anything deeper than my current issue. On a sort of unrelated note, I am finishing up my two parsers but there is one slight issue:
This is a simplified BNF of the language (it has nothing to do with the inheritance issue). If I were to add rules for these as they are, I get an error about ambiguous lookaheads since |
Beta Was this translation helpful? Give feedback.
-
Let me re-pharse:
EditI think I made a wrong assumption that the two parsers call each other... |
Beta Was this translation helpful? Give feedback.
-
You have a couple of separate issues here: Left RecursionYour Common Prefix AmbiguityChevrotain is a lookahead parser, it need to be able to choose an alternative by looking at most K tokens ahead.
Generally I would avoid BACKTRACKING if possible. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a parser that requires a subrule from a second parser I've made. The second parser deals with propositional logic (ϕ → ψ, ¬ϕ, etc.), and the parser using it contains one rule that uses the second parser's default rule (
theorem
), shown below:I'm using embedded semantics in TypeScript (if that makes any difference), shown below:
I tried something like this
but it fails to run after the self-analysis.
I know I can just duplicate the rules, but I was wondering if there is a better way to go about this. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions