Package apg
Class Parser.RuleCallback
- java.lang.Object
-
- apg.Parser.RuleCallback
-
- Enclosing class:
- Parser
public static class Parser.RuleCallback extends java.lang.Object
The base class for all rule callback functions.
-
-
Field Summary
Fields Modifier and Type Field Description Parser.CallbackData
callbackData
Parser-provisioned data available to all rule callback functions
-
Constructor Summary
Constructors Constructor Description RuleCallback(Parser parser)
Base class constructor for the rule callback functions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
postBranch(int offset, int length)
Called by the parser just following the parsing of the syntax tree branch below this rule node.int
preBranch(int offset)
Called by the parser just prior to parsing the syntax tree branch below this rule node.
-
-
-
Field Detail
-
callbackData
public final Parser.CallbackData callbackData
Parser-provisioned data available to all rule callback functions
-
-
Constructor Detail
-
RuleCallback
public RuleCallback(Parser parser)
Base class constructor for the rule callback functions.- Parameters:
parser
- the Parser object to attach this callback function to.
-
-
Method Detail
-
preBranch
public int preBranch(int offset) throws java.lang.Exception
Called by the parser just prior to parsing the syntax tree branch below this rule node. This callback function can do nothing, perform semantic actions or can function fully as a terminal node, skipping the parser's processing of the branch below entirely.- Parameters:
offset
- offset into the input string of the first character of the phrase to be matched.- Returns:
- the return value can be a phrase length,
L
, indicating to the parser that this is a terminal node, or-1
to continue normally. If acting as a terminal node the parser will skip normal processing of the branch below and the phrase length must be in the range0 <= L <=(n-1)
, wheren
is the remaining number of characters in the input string. - Throws:
java.lang.Exception
- thrown if the callback function returns an illegal value. An illegal value would be a phrase lengthL >= n
, for example.
-
postBranch
public int postBranch(int offset, int length) throws java.lang.Exception
Called by the parser just following the parsing of the syntax tree branch below this rule node. This callback function can do nothing, perform semantic actions or override the parser's result, acting as a terminal node.- Parameters:
offset
- offset into the input string of the first character of the matched phrase, if any.length
- length of the parser's matched phrase or-1
if no phrase was matched.- Returns:
- the return value can be a phrase length,
L
, indicating to the parser that this is a terminal node overriding the parser's result, or-1
to continue normally. If acting as a terminal node, the phrase length must be in the range0 <= L <=(n-1)
, wheren
is the remaining number of characters in the input string. - Throws:
java.lang.Exception
- thrown if the callback function returns an illegal value. An illegal value would be a phrase lengthL >= n
, for example.
-
-