@Override public boolean matchesFor(SymbolType symbolType) { return symbolType instanceof Path || super.matchesFor(symbolType); }
@Override protected Translation getTranslation(SymbolType symbolType) { if(symbolType instanceof SymbolTypeDecorator){ SymbolType applicable = ((SymbolTypeDecorator)symbolType).isApplicable(this); return applicable.getHtmlTranslation(); } return symbolType.getHtmlTranslation(); }
public SymbolTypeDecorator(String symbolTypeName, SymbolType baseSymbolType) { super(symbolTypeName); this.baseSymbolType = baseSymbolType; this.wikiRule(baseSymbolType.getWikiRule()); for(Matcher m: baseSymbolType.getWikiMatchers()){ this.wikiMatcher(m); } this.htmlTranslation(this); }
Symbol cellSeparator = parser.getCurrent(); if (!cellSeparator.isType(SymbolType.Newline) && !cellSeparator.isType(SymbolType.Whitespace)) { SymbolType plainTextCellSeparator = new SymbolType("PlainTextCellSeparator"); plainTextCellSeparator.wikiMatcher(new Matcher().string(cellSeparator.getContent().substring(0, 1))); plainTextTableTypes = new SymbolProvider(new SymbolType[] {SymbolType.Newline, SymbolType.ClosePlainTextTable, Evaluator.symbolType, Literal.symbolType, Variable.symbolType, plainTextCellSeparator});
public SymbolProvider add(SymbolType symbolType) { if (matchesFor(symbolType)) return this; symbolTypes.add(symbolType); for (Matcher matcher: symbolType.getWikiMatchers()) { for (char first: matcher.getFirsts()) { if (!currentDispatch.containsKey(first)) currentDispatch.put(first, new ArrayList<Matchable>()); currentDispatch.get(first).add(symbolType); } } return this; }
@Override public Maybe<Symbol> parse(Symbol current, Parser parser) { Symbol next = parser.moveNext(1); if (next.isType(WikiWord.symbolType)) { return new Maybe<>(current.add(next)); } if (next.isType(Alias.symbolType)) { Maybe<Symbol> alias = next.getType().getWikiRule().parse(next, parser); if (!alias.isNothing()) return new Maybe<>(current.add(alias.getValue())); } return Symbol.nothing; } }
private Maybe<String> parseVariableValue(Parser parser, Symbol next) { SymbolType close = next.getType().closeType(); if (close == SymbolType.Empty) return Maybe.noString; return parser.parseToAsString(close); }
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; }
Symbol cellSeparator = parser.getCurrent(); if (!cellSeparator.isType(SymbolType.Newline) && !cellSeparator.isType(SymbolType.Whitespace)) { SymbolType plainTextCellSeparator = new SymbolType("PlainTextCellSeparator"); plainTextCellSeparator.wikiMatcher(new Matcher().string(cellSeparator.getContent().substring(0, 1))); plainTextTableTypes = new SymbolProvider(new SymbolType[] {SymbolType.Newline, SymbolType.ClosePlainTextTable, Evaluator.symbolType, Literal.symbolType, Variable.symbolType, plainTextCellSeparator});
public SymbolProvider add(SymbolType symbolType) { if (matchesFor(symbolType)) return this; symbolTypes.add(symbolType); for (Matcher matcher: symbolType.getWikiMatchers()) { for (char first: matcher.getFirsts()) { if (!currentDispatch.containsKey(first)) currentDispatch.put(first, new ArrayList<Matchable>()); currentDispatch.get(first).add(symbolType); } } return this; }
@Override public Maybe<Symbol> parse(Symbol current, Parser parser) { Symbol next = parser.moveNext(1); if (next.isType(WikiWord.symbolType)) { return new Maybe<>(current.add(next)); } if (next.isType(Alias.symbolType)) { Maybe<Symbol> alias = next.getType().getWikiRule().parse(next, parser); if (!alias.isNothing()) return new Maybe<>(current.add(alias.getValue())); } return Symbol.nothing; } }
private Maybe<String> parseVariableValue(Parser parser, Symbol next) { SymbolType close = next.getType().closeType(); if (close == SymbolType.Empty) return Maybe.noString; return parser.parseToAsString(close); }
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; }
@Override public boolean matchesFor(SymbolType symbolType) { return symbolType instanceof Path || super.matchesFor(symbolType); }
public SymbolTypeDecorator(String symbolTypeName, SymbolType baseSymbolType) { super(symbolTypeName); this.baseSymbolType = baseSymbolType; this.wikiRule(baseSymbolType.getWikiRule()); for(Matcher m: baseSymbolType.getWikiMatchers()){ this.wikiMatcher(m); } this.htmlTranslation(this); }
@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; }
/** * * @param parser parser * @param scanner scanner * @return a possible value if parser should stop. */ public Maybe<Symbol> parseSymbol(Parser parser, Scanner scanner) { while (true) { Scanner backup = new Scanner(scanner); scanner.moveNextIgnoreFirst(this); if (scanner.isEnd()) return Maybe.nothingBecause("scanner is at end of buffer"); Symbol currentToken = scanner.getCurrent(); int startOffset = currentToken.getStartOffset(); if (endsOn(currentToken.getType()) || parser.parentOwns(currentToken.getType(), this)) { scanner.copy(backup); return Maybe.nothingBecause("At termination symbol or parent owns symbol"); } if (terminatesOn(currentToken.getType())) return Maybe.nothingBecause("At termination symbol"); Rule currentRule = currentToken.getType().getWikiRule(); Maybe<Symbol> parsedSymbol = currentRule.parse(currentToken, parser); if (parsedSymbol.isNothing()) { ignoreFirst(currentToken.getType()); scanner.copy(backup); } else { parsedSymbol.getValue().setStartOffset(startOffset).setEndOffset(scanner.getOffset()); clearIgnoresFirst(); return parsedSymbol; } } }
@Override protected Translation getTranslation(SymbolType symbolType) { if(symbolType instanceof SymbolTypeDecorator){ SymbolType applicable = ((SymbolTypeDecorator)symbolType).isApplicable(this); return applicable.getHtmlTranslation(); } return symbolType.getHtmlTranslation(); }
public boolean isType(SymbolType type) { return this.type.matchesFor(type); } public boolean isStartCell() { return isType(Table.symbolType) || isType(SymbolType.EndCell); }
@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; }