public static Parser<?> term(String term) { return TERMS.token(term); }
/** * Returns a {@link Terminals} object for lexing the operators with names specified in * {@code ops}. Operators are lexed as {@link Tokens.Fragment} with {@link Tag#RESERVED} tag. * For example, to get the parser for operator "?", simply call {@code token("?")}. * * <p>If words and keywords need to be parsed, they can be configured via {@link #words}. * * @param ops the operator names. * @return the Terminals instance. */ public static Terminals operators(String... ops) { return operators(asList(ops)); }
/** * Returns a {@link Terminals} object for lexing and parsing the operators with names specified in * {@code ops}, and for lexing and parsing the keywords case insensitively. Parsers for operators * and keywords can be obtained through {@link #token}; parsers for identifiers through * {@link #identifier}. * * <p>In detail, keywords and operators are lexed as {@link Tokens.Fragment} with * {@link Tag#RESERVED} tag. Words that are not among {@code keywords} are lexed as * {@code Fragment} with {@link Tag#IDENTIFIER} tag. * * <p>A word is defined as an alphanumeric string that starts with {@code [_a - zA - Z]}, * with 0 or more {@code [0 - 9_a - zA - Z]} following. * * @param ops the operator names. * @param keywords the keyword names. * @return the Terminals instance. * @deprecated Use {@code operators(ops) * .words(Scanners.IDENTIFIER) * .caseInsensitiveKeywords(keywords) * .build()} instead. */ @Deprecated public static Terminals caseInsensitive(String[] ops, String[] keywords) { return operators(ops).words(Scanners.IDENTIFIER).caseInsensitiveKeywords(asList(keywords)).build(); }
public static Parser<?> phrase(String phrase) { return TERMS.phrase(phrase.split("\\s+")); } }
/** * Returns a {@link Parser} that recognizes {@link Tokens.Fragment} token values * tagged with one of {@code tags}. */ public static Parser<String> fragment(final Object... tags) { return Parsers.token(fromFragment(tags)); }
/** * Returns a {@link Terminals} object for lexing the operators with names specified in * {@code ops}. Operators are lexed as {@link Tokens.Fragment} with {@link Tag#RESERVED} tag. * For example, to get the parser for operator "?", simply call {@code token("?")}. * * <p>If words and keywords need to be parsed, they can be configured via {@link #words}. * * @param ops the operator names. * @return the Terminals instance. * @since 2.2 */ public static Terminals operators(Collection<String> ops) { return new Terminals(Operators.lexicon(ops)); }
/** * Returns a {@link Terminals} object for lexing and parsing the operators with names specified in * {@code ops}, and for lexing and parsing the keywords case sensitively. Parsers for operators * and keywords can be obtained through {@link #token}; parsers for identifiers through * {@link #identifier}. * * <p>In detail, keywords and operators are lexed as {@link Tokens.Fragment} with * {@link Tag#RESERVED} tag. Words that are not among {@code keywords} are lexed as * {@code Fragment} with {@link Tag#IDENTIFIER} tag. * * @param wordScanner the scanner that returns a word in the language. * @param ops the operator names. * @param keywords the keyword names. * @return the Terminals instance. * @deprecated Use {@code operators(ops) * .words(wordScanner) * .keywords(keywords) * .build()} instead. */ @Deprecated public static Terminals caseSensitive( Parser<String> wordScanner, String[] ops, String[] keywords) { return operators(ops) .words(wordScanner) .keywords(keywords) .build(); }
public static Parser<?> phrase(String phrase) { return TERMS.phrase(phrase.split("\\s")); } }
private Parser<Token> term(String name) { return terminals.token(name); }
/** * Returns a {@link Terminals} object for lexing and parsing the operators with names specified in * {@code ops}, and for lexing and parsing the keywords case sensitively. Parsers for operators * and keywords can be obtained through {@link #token}; parsers for identifiers through * {@link #identifier}. * * <p>In detail, keywords and operators are lexed as {@link Tokens.Fragment} with * {@link Tag#RESERVED} tag. Words that are not among {@code keywords} are lexed as * {@code Fragment} with {@link Tag#IDENTIFIER} tag. * * <p>A word is defined as an alphanumeric string that starts with {@code [_a - zA - Z]}, * with 0 or more {@code [0 - 9_a - zA - Z]} following. * * @param ops the operator names. * @param keywords the keyword names. * @return the Terminals instance. * @deprecated Use {@code operators(ops) * .words(Scanners.IDENTIFIER) * .keywords(keywords) * .build()} instead. */ @Deprecated public static Terminals caseSensitive(String[] ops, String[] keywords) { return operators(ops).words(Scanners.IDENTIFIER).keywords(asList(keywords)).build(); }
private Parser<Token> term(String name) { return terminals.token(name); }
/** * Returns a {@link Terminals} object for lexing and parsing the operators with names specified in * {@code ops}, and for lexing and parsing the keywords case insensitively. Parsers for operators * and keywords can be obtained through {@link #token}; parsers for identifiers through * {@link #identifier}. * * <p>In detail, keywords and operators are lexed as {@link Tokens.Fragment} with * {@link Tag#RESERVED} tag. Words that are not among {@code keywords} are lexed as * {@code Fragment} with {@link Tag#IDENTIFIER} tag. * * @param wordScanner the scanner that returns a word in the language. * @param ops the operator names. * @param keywords the keyword names. * @return the Terminals instance. * @deprecated Use {@code operators(ops) * .words(wordScanner) * .caseInsensitiveKeywords(keywords) * .build()} instead. */ @Deprecated public static Terminals caseInsensitive( Parser<String> wordScanner, String[] ops, String[] keywords) { return operators(ops) .words(wordScanner) .caseInsensitiveKeywords(keywords) .build(); }
static Parser<?> oneOf(String... names) { return TERMS.token(names); }
static Parser<?> term(String name) { return TERMS.token(name); }
/** * A {@link Parser} that parses all adjacent characters in {@code operator} as individual * {@link Token} and only succeeds if these tokens are adjacent. A {@code Token} representing * the entire {@code operator} is returned. */ public static Parser<Token> adjacent(String operator) { List<Parser<Token>> parsers = new ArrayList<Parser<Token>>(operator.length()); for (int i = 0; i < operator.length(); i++) { parsers.add(TERMS.token(Character.toString(operator.charAt(i)))); } return adjacent(Parsers.list(parsers), Parsers.expect(operator)); }
public static Parser<?> term(String name) { if (name.equals(">>")) { // manually do the exclusion so that ">>>" never gets interpreted partially as ">>", // even if it can be interpreted as ">" followed by ">>" or three ">"s. return adjacent(">>>").not().next(adjacent(">>")); } if (name.equals("<<") || name.equals(">>>")) { return adjacent(name); } return TERMS.token(name); }