T - U - public class Action<T,U extends T> extends Parser<U>
subject parser matches. The
Callback class is passed the matching portion of the parse
text. Note that the Action parser wraps around its subject. It
will parse exactly the same text that its subject parser parses.
Parser p = Chset.ALPHA.plus().action(new Callback() {
public void handle(char[] buf, int start, int end, Object data) {
StringBuffer str = (StringBuffer) data;
str.delete(0, str.length());
str.append(buf, start, end - start);
}
});
StringBuffer buf = new StringBuffer();
p.parse("a") -> matches "a", buf == "a"
p.parse("abcde") -> matches "abcde", buf == "abcde"
p.parse("a0") -> matches "a", buf == "a"
p.parse("0") -> no match, buf unchanged| Constructor and Description |
|---|
Action(Parser<T> subject,
Callback<U> callback)
Class constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
parse(char[] buf,
int start,
int end,
U data)
Matches the
subject parser against the current state of the
buffer being parsed. |
public int parse(char[] buf,
int start,
int end,
U data)
subject parser against the current state of the
buffer being parsed. If the subject parser hits (returns a
result other than NO_MATCH), callback.handle
will be invoked and passed the matching region of the parse buffer.parse in class Parser<U extends T>buf - The character array to match against.start - The start offset of data within the character array to match
against.end - The end offset of data within the character array to match
against.data - User defined object that is passed to
Callback.handle when an Action fires.Parser.parse(char[], int, int, T)