Puneet Varma (Editor)

Parboiled (Java)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Developer(s)
  
Mathias Doenitz

Written in
  
Java

Development status
  
Active

Operating system
  
Cross-platform

Initial release
  
November 12, 2009; 7 years ago (2009-11-12)

Stable release
  
1.1.7 / 9 February 2015; 2 years ago (2015-02-09)

parboiled is an open-source Java library released under an Apache License. It provides support for defining PEG parsers directly in Java source code.

parboiled is commonly used as an alternative for regular expressions or parser generators (like ANTLR or JavaCC), especially for smaller and medium-size applications.

Apart from providing the constructs for grammar definition parboiled implements a complete recursive descent parser with support for abstract syntax tree construction, parse error reporting and parse error recovery.

Example

Since parsing with parboiled does not require a separate lexing phase and there is no special syntax to learn for grammar definition parboiled makes it comparatively easy to build custom parsers quickly.

Consider this the following classic “calculator” example, with these rules in a simple pseudo notation

ExpressionTerm ((‘+’ / ‘-’) Term)* TermFactor (('*' / '/') Factor)* FactorNumber / '(' Expression ')' Number ← [0-9]+

With parboiled this rule description can be translated directly into the following Java code:

The class defines the parser rules for the language (yet without any actions), which could be used to parse actual input with code such as this:

References

Parboiled (Java) Wikipedia


Similar Topics