Bob Foster wrote: >> Number <- ?'-' >> ('0' | [1-9] *[0-9]) >> ?('.' +[0-9]) >> ?([eE] ?[+-] +[0-9]) > > Isn't ('0' | [1-9] *[0-9]) equivalent to ([0-9] *[0-9])? Feel free to ignore > this comment if you don't think it is interesting. One could nitpick > grammars all day long. :)
No, thanks for mentioning that. The intention is to not allow numbers like 01, 000583.8131, etc. At first, I thought you'd found a error in the grammar but then I remembered that alternation/ordered choice has the lowest precedence. http://waxeye.org/manual.html#_precedence I think, I did some experiments and found that, most of the time, giving alternation the lowest precedence results in shorter grammars. As it happens, the PEG paper also does this. Here it is from Waxeye's grammar: Alternation <- Sequence *(Alt Sequence) Sequence <- +Unit Here it is from the PEG paper: Expression <- Sequence (SLASH Sequence)* Sequence <- Prefix* In this case, I think, there really is a typo. Shouldn't it be 'Prefix+'? Going back to the JSON grammar, here are some examples of the precedence rules saving a few extra parentheses: String <- :'"' *( :'\\' Escaped | !'\\' !'"' . ) :'"' Escaped <- 'u' [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] | ["/\\bfnrt] There is an error in the top level rule, though. It accepts more than one value so, '01' is correctly parsed as two numbers but would be better off as an error. I've changed it now. Old: Json <- Ws *Value New: Json <- Ws Value Orlando. _______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg