Package org.jparsec

Class Operators

java.lang.Object
org.jparsec.Operators

final class Operators extends Object
Helper class for creating parsers and lexers for operators.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    A suite is a list of overlapping operators, where some operators are prefixes of other operators.
    private static final class 
    A list of suites in the reverse order of the suites.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Comparator<String>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static Lexicon
    lexicon(Collection<String> operatorNames)
    Gets a Lexicon instance with Tokens.reserved(String) as each operator's value and a lexer that strives to try the shortest operator first.
    (package private) static String[]
    sort(String... names)
    Sorts names into a new array by putting short string first, unless a shorter string is a prefix of a longer string, in which case, the longer string is before the prefix string.

    Methods inherited from class java.lang.Object

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

    • LONGER_STRING_FIRST

      private static final Comparator<String> LONGER_STRING_FIRST
  • Constructor Details

    • Operators

      Operators()
  • Method Details

    • lexicon

      static Lexicon lexicon(Collection<String> operatorNames)
      Gets a Lexicon instance with Tokens.reserved(String) as each operator's value and a lexer that strives to try the shortest operator first.

      Safely speaking, we can always start from the longest operator and falls back to shorter ones. Yet shorter operators are more often used than longer ones and the scanning of them is faster. However, scanning shorter operators first has the chance that a "==" is mistakenly scanned as "=" followed by another "=". In order to avoid this, we analyze the prefix relationship and make sure that prefixes are scanned after prefixes.

    • sort

      static String[] sort(String... names)
      Sorts names into a new array by putting short string first, unless a shorter string is a prefix of a longer string, in which case, the longer string is before the prefix string.