public void addError(String message) { MatcherContext matcherContext = (MatcherContext) getContext(); matcherContext.markError(); List parseErrors = matcherContext.getParseErrors(); parseErrors.add(new BasicParseError(matcherContext.getInputBuffer(), parseErrors.size(), message)); }
@Override public void beforeParse(final PreParseEvent<V> event) { nodeIds.put(-1, -1); final org.parboiled.buffers.InputBuffer legacyBuffer = event.getContext().getInputBuffer(); inputBuffer = CharSequenceInputBuffer.fromLegacy(legacyBuffer); nrChars = inputBuffer.length(); nrLines = inputBuffer.getLineCount(); startTime = System.currentTimeMillis(); }
public void addError(String message) { MatcherContext matcherContext = (MatcherContext) getContext(); matcherContext.markError(); List parseErrors = matcherContext.getParseErrors(); parseErrors.add(new BasicParseError(matcherContext.getInputBuffer(), parseErrors.size(), message)); }
protected ParsingResult<V> createParsingResult(boolean matched, MatcherContext<V> rootContext) { return new ParsingResult<V>(matched, rootContext.getNode(), getValueStack(), getParseErrors(), rootContext.getInputBuffer()); } }
private void print(MatcherContext<?> context, boolean matched) { Position pos = context.getInputBuffer().getPosition(context.getCurrentIndex()); MatcherPath path = context.getPath(); MatcherPath prefix = lastPath != null ? path.commonPrefix(lastPath) : null; if (prefix != null && prefix.length() > 1) getLog().receive("..(" + (prefix.length() - 1) + ")../"); getLog().receive(path.toString(prefix != null ? prefix.parent : null)); String line = context.getInputBuffer().extractLine(pos.line); getLog().receive(", " + (matched ? "matched" : "failed") + ", cursor at " + pos.line + ':' + pos.column + " after \"" + line.substring(0, Math.min(line.length(), pos.column - 1)) + "\"\n"); lastPath = path; } }
@Override public boolean match(MatcherContext context) { if (!context.fastStringMatching()) { return super.match(context); } if (!context.getInputBuffer().test(context.getCurrentIndex(), characters)) return false; context.advanceIndex(characters.length); context.createNode(); return true; } }
@SuppressWarnings({"unchecked"}) public <V> boolean match(MatcherContext<V> context) { if (skipInPredicates && context.inPredicate()) return true; // actions need to run in the parent context MatcherContext parentContext = context.getParent(); if (!contextAwares.isEmpty()) { for (ContextAware contextAware : contextAwares) { contextAware.setContext(parentContext); } } try { Object valueStackSnapshot = context.getValueStack().takeSnapshot(); if (!action.run(parentContext)) { // failing actions are not allowed to change the ValueStack context.getValueStack().restoreSnapshot(valueStackSnapshot); return false; } // since we initialize the actions own context only partially in getSubContext(MatcherContext) // (in order to be able to still access the previous subcontexts fields in action expressions) // we need to make sure to not accidentally advance the current index of our parent with some old // index from a previous subcontext, so we explicitly set the marker here context.setCurrentIndex(parentContext.getCurrentIndex()); return true; } catch (ActionException e) { context.getParseErrors().add(new ActionError(context.getInputBuffer(), context.getCurrentIndex(), e.getMessage(), context.getPath(), e)); return false; } }
InputBuffer buffer = context.getInputBuffer(); char c = context.getCurrentChar(); int endIx = -1;