Skip to content

How to use splparser.cmdrules.common

salspaugh edited this page Feb 13, 2013 · 7 revisions

How to use splparser.cmdrules.common

Although the syntax of SPL commands can be quite idiosyncratic, there is overlap in their rules. In order to avoid redundancy (each parser containing copies of the same rules), parsers can import rules from splparser.cmdrules.common. Doing this is highly recommended. If you wish to use these rules (and you should), you need to be careful to define all the requisite tokens, which are noted below.

At a high-level, there are two types of common rules: those which can be used with search-style lexers, and those which can be used with eval-style lexers. The main difference between these two types of lexers is that the former is able to tokenize commonly occurring complex data types, such as email addresses, IP addresses, hostnames, etc., whereas the latter can't do that because characters which commonly occur in these data types (such as '.' and '-') are used as operators for arithmetic, string manipulation, and so on. Thus, these two types of lexers necessarily tokenize the same strings differently. For example, consider the string day-average. search-style lexers can and should tokenize this as:

ID

whereas eval-style lexers can and should tokenize this as:

WORD MINUS WORD

because subtraction is a valid eval operator.

If your command uses eval functions, then you should use eval-style lexers. Otherwise, please use search-style lexers. You should define a new lexer for each command, but almost all commands should be able to use either splparser.cmdparsers.searchregexes or splparser.cmdparsers.evalregexes, so think very hard if you are not doing this.

The modules within this package are as follows:

splparser.common.asrules

These are very simple rules for as, which is used by many SPL commands. These rules match both the uppercase and lowercase version of the word "as".

Required tokens (respectively):

  • ASLC
  • ASUC

splparser.common.byrules

Similar to the previous module (splparser.cmdparsers.common.asrules).

Required tokens (respectively):

  • BYLC

  • BYUC

    splparser.common.evalfnexprrules splparser.common.fieldlistrules

    splparser.common.fieldrules splparser.common.simplefieldlistrules splparser.common.simplefieldrules splparser.common.simplevaluerules splparser.common.statsfnrules splparser.common.uminusrules splparser.common.valuerules

Clone this wiki locally