Neg 1.1.0 is out. Neg is a small PEG parser library, very un-awesome and naive. One could say it’s a small brother of Parslet.
The bulk of the work from 1.0.0 to 1.1.0 was the removal of the “UnconsumedInputError”.
Consider this parser:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class BlockParser < Neg::Parser
parser do
blocks == nl? + block + (nl + block) * 0 + nl?
block == sp? + `begin` + sp + _('a-z') + nl + body + sp? + `end`
body == ((line | block) + nl) * 0
line == sp + `line`
nl == _("\s\n") * 1
nl? == _("\s\n") * 0
sp == _(" ") * 1
sp? == _(" ") * 0
end
end
It’s meant for parsing begin blocks, nested or given in succession:
So far, so good. But the parser becomes kind of unhelpful when it’s fed something like:
Neg 1.0.0, would just raise an UnconsumedInputError and say something like “I could parse that, but there’s trailing input I couldn’t parse, it starts at ‘begin c’”.
Neg 1.1.0, will instead raise a ParseError stating it couldn’t find the end somewhere after “begin c”.
This 1.1.0 also introduce a #flattened_results helper for the Translator. It’s used in the JSON sample, the arith sample and the scheme sample. It comes in handy when translating for a parse rule like:
It flattens alls the values into a single array.
- source: https://github.com/jmettraux/neg
- issues: https://github.com/jmettraux/neg/issues
- irc: freenode.net #ruote