|
|
The topic of this article may not meet Wikipedia's notability guidelines for products and services. Please help to establish notability by adding reliable, secondary sources about the topic. If notability cannot be established, the article is likely to be merged, redirected, or deleted. (March 2010) |
| This article relies on references to primary sources or sources affiliated with the subject, rather than references from independent authors and third-party publications. Please add citations from reliable sources. (March 2010) |
| Developer(s) | Mathias Doenitz |
|---|---|
| Initial release | November 12, 2009 |
| Development status | Active |
| Written in | Java |
| Operating system | Cross-platform |
| License | Apache License 2.0 |
| Website | http://www.parboiled.org/ |
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.
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
With parboiled this rule description can be translated directly into the following Java code:
import org.parboiled.BaseParser; public class CalculatorParser extends BaseParser<Object> { public Rule expression() { return sequence( term(), zeroOrMore( sequence( firstOf('+', '-'), term() ) ) ); } public Rule term() { return sequence( factor(), zeroOrMore( sequence( firstOf('*', '/'), factor() ) ) ); } public Rule factor() { return firstOf( number(), sequence('(', expression(), ')') ); } public Rule number() { return oneOrMore(charRange('0', '9')); } }
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:
String input = "1+2"; CalculatorParser parser = Parboiled.createParser(CalculatorParser.class); ParsingResult<?> result = ReportingParseRunner.run(parser.expression(), input); String parseTreePrintOut = ParseTreeUtils.printNodeTree(result); System.out.println(parseTreePrintOut);
| This computer library article is a stub. You can help Wikipedia by expanding it. |
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)