-
Notifications
You must be signed in to change notification settings - Fork 155
Parser Extension in Detail
When you call Parboiled.createParser to construct an instance of your parser class for the first time parboiled for Java internally runs its parser extension logic to augment you parser class with all kinds of special functionality. In order to do that parboiled creates a new, artificial subclass of your parser class that lives in the same package and has the name of your parser class suffixed with “$$parboiled”. Because of this basic approach your parser class must not be private or final, since otherwise parboiled would not be able to subclass it.
The automatically created parser subclass contains method overrides for all methods returning Rule instances. These overrides might at some point delegate to their super methods (the original rule method you defined in your parser class) or they might completely rewrite their supers method body without actually calling it.
These rule methods extensions require a complete rewrite of the method body and therefore do not call their super method:
These rule method extensions can be applied without a method rewrite and call the super method if the method does not also require a transformation listed above:
Normally you don’t have to care about the question whether an extension requires a method rewrite or not. However, in debugging scenarios, where you want to set a breakpoint in a rule method in order to trace its execution, your breakpoint will not be hit if the rule method has been rewritten by parboileds parser extension logic. So, for example, if you want to debug a rule method containing explicit or implicit action expressions you will have to temporarily convert these action expressions to explicit anonymous inner Action classes in order to prevent parboiled from completely rewriting the rule method.
All parser methods not returning Rule objects are left untouched by parboileds parser extension logic. In smaller parsers these often implement simple parser actions and can be directly used in rule methods, as long as they are not private.
- Introduction
- ... Motivation
- ... Features
- ... Simple Java Example
- ... Simple Scala Example
- ... RegEx vs. parboiled vs. Parser Generators
- ... Projects using parboiled
- Installation
- Concepts
- ... The Big Picture
- ... The Rule Tree
- ... The Value Stack
- ... The Parse Tree
- ... AST Construction
- ... Parse Error Handling
- parboiled for Java
- ... Rule Construction in Java
- ... Parser Action Expressions
- ... Working with the Value Stack
- ... Action Variables
- ... Parser Extension in Detail
- ... Style Guide
- ... Java Examples
- ...... ABC Grammar
- ...... Calculators
- ...... Time Parser
- ...... Java Parser
- ...... Markdown processor
- parboiled for Scala
- ... Rule Construction in Scala
- ... Parser Actions in Scala
- ... Parser Testing in Scala
- ... Scala Examples
- ...... Simple Calculator
- ...... JSON Parser
- Advanced Topics
- ... Handling Whitespace
- ... Parsing Performance Tuning
- ... Indentation Based Grammars
- ... The ProfilingParseRunner
- ... Grammar and Parser Debugging
- ... Thread Safety
- Building parboiled
- parboiled-core Javadoc API
- parboiled-java Javadoc API
- parboiled-scala Scaladoc API
- Change Log
- Patch Policy