Class Terminals.Builder

java.lang.Object
org.jparsec.Terminals.Builder
Enclosing class:
Terminals

public final class Terminals.Builder extends Object
Builds Terminals instance by defining the words and keywords recognized. The following example implements a calculator with logical operators:
  Terminals terms = Terminals
      .operators("<", ">", "=", ">=", "<=")
      .words(Scanners.IDENTIFIER)
      .caseInsensitiveKeywords("and", "or")
      .build();
  Parser<String> var = Terminals.identifier();
  Parser<Integer> integer = Terminals.IntegerLiteral.PARSER.map(...);
  Parser<?> and = terms.token("and");
  Parser<?> lessThan = terms.token("<");
  ...
  Parser<?> parser = grammar.from(
      terms.tokenizer().or(IntegerLiteral.TOKENIZER), Scanners.WHITSPACES.optional());
Since:
2.2
Author:
Ben Yu
  • Method Details

    • keywords

      public Terminals.Builder keywords(String... keywords)
      Defines keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, call token(keyword).

      Note that if you call keywords or caseInsensitiveKeywords(String...) multiple times on the same Terminals.Builder instance, the last call overwrites previous calls.

    • keywords

      public Terminals.Builder keywords(Collection<String> keywords)
      Defines keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, call token(keyword).

      Note that if you call keywords or caseInsensitiveKeywords(String...) multiple times on the same Terminals.Builder instance, the last call overwrites previous calls.

    • caseInsensitiveKeywords

      public Terminals.Builder caseInsensitiveKeywords(String... keywords)
      Defines case insensitive keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, call token(keyword).

      Note that if you call keywords or caseInsensitiveKeywords(String...) multiple times on the same Terminals.Builder instance, the last call overwrites previous calls.

    • caseInsensitiveKeywords

      public Terminals.Builder caseInsensitiveKeywords(Collection<String> keywords)
      Defines case insensitive keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, call token(keyword).

      Note that if you call keywords or caseInsensitiveKeywords(String...) multiple times on the same Terminals.Builder instance, the last call overwrites previous calls.

    • tokenizeWordsWith

      public Terminals.Builder tokenizeWordsWith(Function<String,?> wordMap)
      Configures alternative tokenization strategy for words (except keywords).
    • build

      public Terminals build()
      Builds a new Terminals instance that recognizes words defined in this builder.