Home | History | Annotate | Download | only in syntax
      1 // Copyright 2012 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // DO NOT EDIT. This file is generated by mksyntaxgo from the RE2 distribution.
      6 
      7 /*
      8 Package syntax parses regular expressions into parse trees and compiles
      9 parse trees into programs. Most clients of regular expressions will use the
     10 facilities of package regexp (such as Compile and Match) instead of this package.
     11 
     12 Syntax
     13 
     14 The regular expression syntax understood by this package when parsing with the Perl flag is as follows.
     15 Parts of the syntax can be disabled by passing alternate flags to Parse.
     16 
     17 
     18 Single characters:
     19   .              any character, possibly including newline (flag s=true)
     20   [xyz]          character class
     21   [^xyz]         negated character class
     22   \d             Perl character class
     23   \D             negated Perl character class
     24   [[:alpha:]]    ASCII character class
     25   [[:^alpha:]]   negated ASCII character class
     26   \pN            Unicode character class (one-letter name)
     27   \p{Greek}      Unicode character class
     28   \PN            negated Unicode character class (one-letter name)
     29   \P{Greek}      negated Unicode character class
     30 
     31 Composites:
     32   xy             x followed by y
     33   x|y            x or y (prefer x)
     34 
     35 Repetitions:
     36   x*             zero or more x, prefer more
     37   x+             one or more x, prefer more
     38   x?             zero or one x, prefer one
     39   x{n,m}         n or n+1 or ... or m x, prefer more
     40   x{n,}          n or more x, prefer more
     41   x{n}           exactly n x
     42   x*?            zero or more x, prefer fewer
     43   x+?            one or more x, prefer fewer
     44   x??            zero or one x, prefer zero
     45   x{n,m}?        n or n+1 or ... or m x, prefer fewer
     46   x{n,}?         n or more x, prefer fewer
     47   x{n}?          exactly n x
     48 
     49 Implementation restriction: The counting forms x{n,m}, x{n,}, and x{n}
     50 reject forms that create a minimum or maximum repetition count above 1000.
     51 Unlimited repetitions are not subject to this restriction.
     52 
     53 Grouping:
     54   (re)           numbered capturing group (submatch)
     55   (?P<name>re)   named & numbered capturing group (submatch)
     56   (?:re)         non-capturing group
     57   (?flags)       set flags within current group; non-capturing
     58   (?flags:re)    set flags during re; non-capturing
     59 
     60   Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:
     61 
     62   i              case-insensitive (default false)
     63   m              multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
     64   s              let . match \n (default false)
     65   U              ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)
     66 
     67 Empty strings:
     68   ^              at beginning of text or line (flag m=true)
     69   $              at end of text (like \z not Perl's \Z) or line (flag m=true)
     70   \A             at beginning of text
     71   \b             at ASCII word boundary (\w on one side and \W, \A, or \z on the other)
     72   \B             not at ASCII word boundary
     73   \z             at end of text
     74 
     75 Escape sequences:
     76   \a             bell (== \007)
     77   \f             form feed (== \014)
     78   \t             horizontal tab (== \011)
     79   \n             newline (== \012)
     80   \r             carriage return (== \015)
     81   \v             vertical tab character (== \013)
     82   \*             literal *, for any punctuation character *
     83   \123           octal character code (up to three digits)
     84   \x7F           hex character code (exactly two digits)
     85   \x{10FFFF}     hex character code
     86   \Q...\E        literal text ... even if ... has punctuation
     87 
     88 Character class elements:
     89   x              single character
     90   A-Z            character range (inclusive)
     91   \d             Perl character class
     92   [:foo:]        ASCII character class foo
     93   \p{Foo}        Unicode character class Foo
     94   \pF            Unicode character class F (one-letter name)
     95 
     96 Named character classes as character class elements:
     97   [\d]           digits (== \d)
     98   [^\d]          not digits (== \D)
     99   [\D]           not digits (== \D)
    100   [^\D]          not not digits (== \d)
    101   [[:name:]]     named ASCII class inside character class (== [:name:])
    102   [^[:name:]]    named ASCII class inside negated character class (== [:^name:])
    103   [\p{Name}]     named Unicode property inside character class (== \p{Name})
    104   [^\p{Name}]    named Unicode property inside negated character class (== \P{Name})
    105 
    106 Perl character classes (all ASCII-only):
    107   \d             digits (== [0-9])
    108   \D             not digits (== [^0-9])
    109   \s             whitespace (== [\t\n\f\r ])
    110   \S             not whitespace (== [^\t\n\f\r ])
    111   \w             word characters (== [0-9A-Za-z_])
    112   \W             not word characters (== [^0-9A-Za-z_])
    113 
    114 ASCII character classes:
    115   [[:alnum:]]    alphanumeric (== [0-9A-Za-z])
    116   [[:alpha:]]    alphabetic (== [A-Za-z])
    117   [[:ascii:]]    ASCII (== [\x00-\x7F])
    118   [[:blank:]]    blank (== [\t ])
    119   [[:cntrl:]]    control (== [\x00-\x1F\x7F])
    120   [[:digit:]]    digits (== [0-9])
    121   [[:graph:]]    graphical (== [!-~] == [A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])
    122   [[:lower:]]    lower case (== [a-z])
    123   [[:print:]]    printable (== [ -~] == [ [:graph:]])
    124   [[:punct:]]    punctuation (== [!-/:-@[-`{-~])
    125   [[:space:]]    whitespace (== [\t\n\v\f\r ])
    126   [[:upper:]]    upper case (== [A-Z])
    127   [[:word:]]     word characters (== [0-9A-Za-z_])
    128   [[:xdigit:]]   hex digit (== [0-9A-Fa-f])
    129 
    130 */
    131 package syntax
    132