public SymbolMatch make(ParseSpecification specification, int offset, String text) { if (specification.matchesFor(WikiWord.symbolType)) { int length = findWikiWordLength(text); if (length > 0) { Symbol wikiWord = new Symbol(new WikiWord(sourcePage), text.substring(0, length), offset); wikiWord.evaluateVariables(new String[]{WikiWord.REGRACE_LINK}, variableSource); return new SymbolMatch(wikiWord, offset, length); } } if (specification.matchesFor(SymbolType.EMail) && isEmailAddress(text)) { return new SymbolMatch(SymbolType.EMail, text, offset); } return new SymbolMatch(SymbolType.Text, text, offset); }
public SymbolMatch findMatch(Character startCharacter, SymbolMatcher matcher) { if (parent != null) { SymbolMatch parentMatch = parent.findMatch(startCharacter, matcher); if (parentMatch.isMatch()) return parentMatch; } for (Matchable candidate: getMatchTypes(startCharacter)) { SymbolMatch match = matcher.makeMatch(candidate); if (match.isMatch()) return match; } return SymbolMatch.noMatch; } }
private Step makeNextStep(final ParseSpecification specification, final int startPosition) { input.setOffset(startPosition); int newNext = startPosition; Symbol matchSymbol = null; while (!input.isEnd()) { SymbolMatch match = specification.findMatch(input, startPosition, symbols); if (match.isMatch()) { matchSymbol = match.getSymbol(); newNext = input.getOffset() + match.getMatchLength(); break; } input.moveNext(); } if (input.getOffset() > startPosition) { SymbolMatch match = textMaker.make(specification, startPosition, input.substringFrom(startPosition)); return new Step(match.getSymbol(), startPosition + match.getMatchLength()); } if (input.isEnd()) { return new Step(Symbol.emptySymbol, input.getOffset()); } return new Step(matchSymbol, newNext); }
public Symbol makeLiteral(SymbolType terminator) { input.setOffset(next); while (!input.isEnd()) { SymbolMatch match = terminator.makeMatch(input, symbols); if (match.isMatch()) { symbols.add(new Symbol(terminator)); Symbol result = new Symbol(SymbolType.Text, input.substringFrom(next), next); next = input.getOffset() + match.getMatchLength(); return result; } input.moveNext(); } Symbol result = new Symbol(SymbolType.Text, input.substringFrom(next), next); next = input.getOffset(); symbols.add(Symbol.emptySymbol); return result; }
private Step makeNextStep(final ParseSpecification specification, final int startPosition) { input.setOffset(startPosition); int newNext = startPosition; Symbol matchSymbol = null; while (!input.isEnd()) { SymbolMatch match = specification.findMatch(input, startPosition, symbols); if (match.isMatch()) { matchSymbol = match.getSymbol(); newNext = input.getOffset() + match.getMatchLength(); break; } input.moveNext(); } if (input.getOffset() > startPosition) { SymbolMatch match = textMaker.make(specification, startPosition, input.substringFrom(startPosition)); return new Step(match.getSymbol(), startPosition + match.getMatchLength()); } if (input.isEnd()) { return new Step(Symbol.emptySymbol, input.getOffset()); } return new Step(matchSymbol, newNext); }
public Symbol makeLiteral(SymbolType terminator) { input.setOffset(next); while (!input.isEnd()) { SymbolMatch match = terminator.makeMatch(input, symbols); if (match.isMatch()) { symbols.add(new Symbol(terminator)); Symbol result = new Symbol(SymbolType.Text, input.substringFrom(next), next); next = input.getOffset() + match.getMatchLength(); return result; } input.moveNext(); } Symbol result = new Symbol(SymbolType.Text, input.substringFrom(next), next); next = input.getOffset(); symbols.add(Symbol.emptySymbol); return result; }
public SymbolMatch findMatch(Character startCharacter, SymbolMatcher matcher) { if (parent != null) { SymbolMatch parentMatch = parent.findMatch(startCharacter, matcher); if (parentMatch.isMatch()) return parentMatch; } for (Matchable candidate: getMatchTypes(startCharacter)) { SymbolMatch match = matcher.makeMatch(candidate); if (match.isMatch()) return match; } return SymbolMatch.noMatch; } }
public SymbolMatch make(ParseSpecification specification, int offset, String text) { if (specification.matchesFor(WikiWord.symbolType)) { int length = findWikiWordLength(text); if (length > 0) { Symbol wikiWord = new Symbol(new WikiWord(sourcePage), text.substring(0, length), offset); wikiWord.evaluateVariables(new String[]{WikiWord.REGRACE_LINK}, variableSource); return new SymbolMatch(wikiWord, offset, length); } } if (specification.matchesFor(SymbolType.EMail) && isEmailAddress(text)) { return new SymbolMatch(SymbolType.EMail, text, offset); } return new SymbolMatch(SymbolType.Text, text, offset); }
@Override public SymbolMatch makeMatch(Matchable candidate) { if (input.getOffset() != startPosition || !ignores(candidate)) { SymbolMatch match = candidate.makeMatch(input, symbols); if (match.isMatch()) return match; } return SymbolMatch.noMatch; } });
@Override public SymbolMatch makeMatch(ScanString input, SymbolStream symbols) { for (Matcher matcher: getWikiMatchers()) { Maybe<Integer> matchLength = matcher.makeMatch(input, symbols); if (!matchLength.isNothing()) return new SymbolMatch(this, input, matchLength.getValue()); } return SymbolMatch.noMatch; }
@Override public SymbolMatch makeMatch(Matchable candidate) { if (input.getOffset() != startPosition || !ignores(candidate)) { SymbolMatch match = candidate.makeMatch(input, symbols); if (match.isMatch()) return match; } return SymbolMatch.noMatch; } });
@Override public SymbolMatch makeMatch(ScanString input, SymbolStream symbols) { for (Matcher matcher: getWikiMatchers()) { Maybe<Integer> matchLength = matcher.makeMatch(input, symbols); if (!matchLength.isNothing()) return new SymbolMatch(this, input, matchLength.getValue()); } return SymbolMatch.noMatch; }