I need help distinguish math operations and string concatenations with function calls in them #1437
-
I am trying to write a PL/SQL parser and first off I want to say that Chevrotain works great and I like to use it very much 👍🏽 . Yesterday I stumbled into a problem where I want to distinguish string concatenations from math operations when both call a function in them. I guess it's a logical error by my code and no bug that's why I am writing this in the discussion section. I reduced my code to the following where only the problematic part is in. This is ready to use in the Playground: This is the test input. Note that all these all are valid PL/SQL values, some are numbers some strings. So I want all these statements to be parsed correctly. Problematic is the value rule. Regarding which of the rules I thought that backtracking could fix this but this seems to not be the case. I guess increasing lookahead wouldn't make sense because the first So how can I effectively distinguish math operations and string concatenations to make all the statements parse? And is the root problem that both string and math expressions can be a function? Thank you very much for your time 😃 . |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Remove the semantics from the syntactic analysis. Don't try to figure out if its a string concatenation or a number addition during parse time. Build a more general "expression" during parse time and figure out what it means in a post-parsing. |
Beta Was this translation helpful? Give feedback.
Remove the semantics from the syntactic analysis. Don't try to figure out if its a string concatenation or a number addition during parse time. Build a more general "expression" during parse time and figure out what it means in a post-parsing.
Said post-parsing steps may also perform validations to assert that correct operands types match the operators used.