@Override public <V> boolean match(final MatcherContext<V> context) { final InputBuffer buffer = context.getInputBuffer(); final boolean success = buffer.test(context.getCurrentIndex(), chars); if (success) { context.advanceIndex(2); context.createNode(); } return success; }
// @SuppressWarnings("unchecked") protected AbcNode( Node node, InputBuffer parseInputBuffer, List<ParseError> parseErrors, AbcInputBuffer abcInputBuffer) { super(null); if (node != null) { this.label = node.getLabel(); this.value = parseInputBuffer.extract(node.getStartIndex(), node.getEndIndex()); Position pos = parseInputBuffer.getPosition(node.getStartIndex()); int sourceStartIndex = abcInputBuffer.getIndex(pos); int sourceEndIndex = sourceStartIndex + value.length(); setCharStreamPosition( new CharStreamPosition(pos.line, pos.column, sourceStartIndex, sourceEndIndex)); this.childs = new ArrayList(node.getChildren().size()); Iterator it = node.getChildren().iterator(); while (it.hasNext()) { AbcNode abcn = new AbcNode((Node) it.next(), parseInputBuffer, parseErrors, abcInputBuffer); abcn.parent = this; childs.add(abcn); } if (!hasError() /*(childs.size() == 0)*/ && node.hasError()) { this.errors = new ArrayList(); it = parseErrors.iterator(); while (it.hasNext()) { ParseError pe = (ParseError) it.next(); String peValue = pe.getInputBuffer().extract(pe.getStartIndex(), pe.getEndIndex()); String peMsg = pe.getErrorMessage(); Position pePos = pe.getInputBuffer().getPosition(pe.getStartIndex()); int peIndex = abcInputBuffer.getIndex(pePos); CharStreamPosition csp = new CharStreamPosition( pePos.line, pePos.column, peIndex, peIndex + (peValue.length() > 0 ? peValue.length() : 1)); // if ((pe.getStartIndex() >= node.getStartIndex()) // && (pe.getStartIndex() </*=*/ node.getEndIndex())) { if ((peIndex >= sourceStartIndex) && ((peIndex < sourceEndIndex) || (sourceStartIndex == sourceEndIndex))) { errors.add(new AbcParseError(peMsg, peValue, csp)); } } } } else { this.label = "AbcFile-Error"; this.value = ""; int nbL = parseInputBuffer.getLineCount(); for (int i = 1; i <= nbL; i++) this.value += parseInputBuffer.extractLine(i) + "\n"; this.childs = new ArrayList(0); setCharStreamPosition(new CharStreamPosition(1, 1, 0, 1)); if (parseErrors != null) { this.errors = new ArrayList(); Iterator it = parseErrors.iterator(); while (it.hasNext()) { ParseError pe = (ParseError) it.next(); errors.add(new AbcParseError(pe.getErrorMessage(), value, getCharStreamPosition())); } } } }