Package org.jparsec

Class Lexicon

  • Direct Known Subclasses:
    Terminals

    class Lexicon
    extends java.lang.Object
    A Lexicon is a group of lexical words that can be tokenized by a single tokenizer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) Parser<?> tokenizer
      The scanner that recognizes any of the lexical word.
      (package private) java.util.function.Function<java.lang.String,​java.lang.Object> words
      Maps lexical word name to token value.
    • Constructor Summary

      Constructors 
      Constructor Description
      Lexicon​(java.util.function.Function<java.lang.String,​java.lang.Object> words, Parser<?> tokenizer)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <F,​T>
      java.util.function.Function<F,​T>
      fallback​(java.util.function.Function<F,​T> function, java.util.function.Function<? super F,​? extends T> defaultFunction)
      Returns a Function that delegates to function and falls back to defaultFunction for null return values.
      Parser<?> phrase​(java.lang.String... tokenNames)
      A Parser that recognizes a sequence of tokens identified by tokenNames, as an atomic step.
      Parser<Token> token​(java.lang.String tokenName)
      A Parser that recognizes the token identified by tokenName.
      Parser<Token> token​(java.lang.String... tokenNames)
      A Parser that recognizes a token identified by any of tokenNames.
      Parser<?> tokenizer()
      Returns the tokenizer that tokenizes all terminals (operators, keywords, identifiers etc.) managed in this instance.
      (package private) Lexicon union​(Lexicon that)
      Returns a Lexicon instance that's a union of this and that.
      (package private) java.lang.Object word​(java.lang.String name)
      Gets the token value identified by the token text.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • words

        final java.util.function.Function<java.lang.String,​java.lang.Object> words
        Maps lexical word name to token value.
      • tokenizer

        final Parser<?> tokenizer
        The scanner that recognizes any of the lexical word.
    • Constructor Detail

      • Lexicon

        Lexicon​(java.util.function.Function<java.lang.String,​java.lang.Object> words,
                Parser<?> tokenizer)
    • Method Detail

      • tokenizer

        public Parser<?> tokenizer()
        Returns the tokenizer that tokenizes all terminals (operators, keywords, identifiers etc.) managed in this instance.
      • phrase

        public Parser<?> phrase​(java.lang.String... tokenNames)
        A Parser that recognizes a sequence of tokens identified by tokenNames, as an atomic step.
      • token

        public Parser<Token> token​(java.lang.String... tokenNames)
        A Parser that recognizes a token identified by any of tokenNames.
      • token

        public Parser<Token> token​(java.lang.String tokenName)
        A Parser that recognizes the token identified by tokenName.
      • word

        java.lang.Object word​(java.lang.String name)
        Gets the token value identified by the token text. This text is the operator or the keyword.
        Parameters:
        name - the token text.
        Returns:
        the token object.
        Throws:
        java.lang.IllegalArgumentException - if the token object does not exist.
      • fallback

        static <F,​T> java.util.function.Function<F,​T> fallback​(java.util.function.Function<F,​T> function,
                                                                           java.util.function.Function<? super F,​? extends T> defaultFunction)
        Returns a Function that delegates to function and falls back to defaultFunction for null return values.