Reputation: 439
Hi I am a newbie for Jison and was trying to learn it. I try the online jison parser calculator code on http://techtonik.github.io/jison/try/. It is working fine for the expression
5*PI^2.
But when I added a new expression on a newline, the parser will not take the newline and try to parse another expression as if it is on the same line.
Input :
5*PI^2
23+56
Parser takes it as :
5*PI^223+56
This fails, hence I want to know how to parse newline in jison parsor.
Upvotes: 1
Views: 365
Reputation: 1650
The problem here is that the Jison parser expects a single expression to parse, and it tries to evaluate whether the ENTIRE text is valid as a whole. What you've given it in this case is TWO separate expressions that don't evaluate correctly together, which is why it fails. If, for example, you evaluate
5*PI^2
+
23+56
Then it has no problems. This is because Jison is trying to parse the entire value it's given, and it allows you to break complex expressions up over multiple lines.
However, that doesn't stop you from evaluating lines individually if you want to. Instead of passing the parse function the entire text from the field, just split the text into an array using JavaScript's string split method (splitting on the new-line character, '\n'), then loop through and pass each line of the content to the parse function separately.
Upvotes: 3