org.codehaus.jparsec
Class Terminals.Builder

java.lang.Object
  extended by org.codehaus.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

Method Summary
 Terminals build()
          Builds a new Terminals instance that recognizes words defined in this builder.
 Terminals.Builder caseInsensitiveKeywords(Collection<String> keywords)
          Defines case insensitive keywords.
 Terminals.Builder caseInsensitiveKeywords(String... keywords)
          Defines case insensitive keywords.
 Terminals.Builder keywords(Collection<String> keywords)
          Defines keywords.
 Terminals.Builder keywords(String... keywords)
          Defines keywords.
 Terminals.Builder tokenizeWordsWith(Map<String,?> wordMap)
          Configures alternative tokenization strategy for words (except keywords).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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(java.lang.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(java.lang.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(java.lang.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(java.lang.String...) multiple times on the same Terminals.Builder instance, the last call overwrites previous calls.


tokenizeWordsWith

public Terminals.Builder tokenizeWordsWith(Map<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.



Copyright © 2014. All rights reserved.