javascript - Unexpected Behaviour with parsing this grammar with PEG.js -
I'm new to the world of formal grammar. I tried to use but I did not know how to run a parser. I am trying to develop a grammar for DSL and I have it ():
start = expr operator = "show" lparen st: string ws rparen {console.log (7 )} / "Show" lparen ex: expr rparen {console.log (8)} expr = op: operator ws ex: expr {console.log (1)} / st: string ws ex: expr {console.log (2 }} / St: string ws op: operator {console.log (3)} / op: operator ws str: string {console.log (4)} / st: string ws {console.log (5)} / op: Operate Ws {console.log (6)} lparen = ws "(" ws rparen = ws ")" ws integer "integer" = number: [0-9] + {return parseInt (digits.join (""), 10) ; } String "string" = quotation_mark character: char * quotation_mark {return chars.join (""); } "Return" \ / "b" {return "\ b";} / ws "whitespace" = [\ t \ n \ r] * char = unescaped / escape sequence: "Return" "return" \ "" {return ""} "" return "\" "{return" "}" / return " $ (Hexdig hexdig hexdig hexdig) {return string.framecorder (parasent (number, 16))} {return sequence;} escape = "\\" quotation_mark = '' 'unchanged = [\ x20- \ x21 \ x23] - \ X5B \ x5D- \ u10FFFF] / * ----- Core ABNF Rule ----- * / / * See RFC 4234, Appendix B (http://tools.ietf.org/html/rfc4627). * / Digit = [0- 9] hexide = [0-9A-F] i {;} when tested on this : Show ("ABC") should not be a console show 7 6?
Instead it shows 7 7 7 6
The last 3 days I'm threatening my mind from anyone, anywhere Parsimonius!
Parsers must try this before op: operator ws ex: expr and op: operator ws str: string op: Operator ws . It does not know that this will not work unless nothing is found beyond ) .
In this way, once it gets through the operator rule, one does not see another expression, so this backtracks for the second time operator sees , and it still does not work because there is no string after it, in the end, on the third attempt, it sees the operator and then the last The rule is successful. Your call has been made for
console.log (7) because the operator rule itself is successful, even if expr rules.
Comments
Post a Comment