Package org.jparsec

Class Operators


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

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

      Fields 
      Modifier and Type Field Description
      private static java.util.Comparator<java.lang.String> LONGER_STRING_FIRST  
    • Constructor Summary

      Constructors 
      Constructor Description
      Operators()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static Lexicon lexicon​(java.util.Collection<java.lang.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 java.lang.String[] sort​(java.lang.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 Detail

      • LONGER_STRING_FIRST

        private static final java.util.Comparator<java.lang.String> LONGER_STRING_FIRST
    • Constructor Detail

      • Operators

        Operators()
    • Method Detail

      • lexicon

        static Lexicon lexicon​(java.util.Collection<java.lang.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 java.lang.String[] sort​(java.lang.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.