@Override boolean apply(ParseContext ctxt) { ctxt.result = ctxt.getIndex(); return true; } @Override public String toString() {
@Override public String toString() { return source.subSequence(getIndex(), source.length()).toString(); } }
@Override boolean apply(ParseContext ctxt) { int begin = ctxt.getIndex(); if (!Parser.this.apply(ctxt)) { return false; } String source = ctxt.source.subSequence(begin, ctxt.getIndex()).toString(); @SuppressWarnings("unchecked") WithSource<T> withSource = new WithSource<T>((T) ctxt.result, source); ctxt.result = withSource; return true; } @Override public String toString() {
@Override boolean apply(ParseContext ctxt) { ctxt.result = new SourceLocation(ctxt.getIndex(), ctxt.locator); return true; } @Override public String toString() {
@Override public void push(String name) { this.current = current.addChild(name, getIndex()); } @Override public void pop() {
private TreeNode current = new TreeNode(rootName, getIndex());
@Override public void pop() { current.setEndIndex(getIndex()); this.current = current.parent(); } @Override public TreeNode getCurrentNode() {
final ParseTree buildParseTree() { TreeNode currentNode = trace.getCurrentNode(); if (currentNode == null) return null; return currentNode.freeze(getIndex()).toParseTree(); }
final ParseTree buildErrorParseTree() { // The current node is partially done because there was an error. // So orphanize it. But at the same time, all ancestor nodes should have their endIndex set to // where we are now. if (currentErrorNode == null) return null; return currentErrorNode.orphanize().freeze(getIndex()).toParseTree(); }
@Private final void raise(ErrorType type, Object subject) { if (errorSuppressed) return; if (at < currentErrorAt) return; if (overrideErrorType != ErrorType.NONE) type = overrideErrorType; if (at > currentErrorAt) { setErrorState(at, getIndex(), type); errors.add(subject); return; } // now error location is same if (type.ordinal() < currentErrorType.ordinal()) { return; } if (type.ordinal() > currentErrorType.ordinal()) { setErrorState(at, getIndex(), type); errors.add(subject); return; } // now even error type is same if (type.mergeable) { // merge expected error. errors.add(subject); } }
@Override boolean apply(ParseContext ctxt) { if (!lexer.apply(ctxt)) return false; Token[] tokens = lexer.getReturn(ctxt); ParserState parserState = new ParserState( ctxt.module, ctxt.source, tokens, 0, ctxt.locator, ctxt.getIndex(), tokens); ctxt.getTrace().startFresh(parserState); return ctxt.applyNested(parser, parserState); }
final boolean applyNested(Parser<?> parser, ParseContext nestedState) { // nested is either the token-level parser, or the inner scanner of a subpattern. try { if (parser.apply(nestedState)) { set(nestedState.step, at, nestedState.result); return true; } // index on token level is the "at" on character level set(step, nestedState.getIndex(), null); // always copy error because there could be false alarms in the character level. // For example, a "or" parser nested in a "many" failed in one of its branches. copyErrorFrom(nestedState); return false; } finally { trace.setStateAs(nestedState.trace); } }