48 if (count(self::$_specials) > 0) {
52 self::$_specials = array(
53 '(',
')',
'<',
'>',
'[',
']',
54 ':',
';',
'@',
',',
'.',
'"',
60 self::$_grammar[
'NO-WS-CTL'] =
'[\x01-\x08\x0B\x0C\x0E-\x19\x7F]';
61 self::$_grammar[
'WSP'] =
'[ \t]';
62 self::$_grammar[
'CRLF'] =
'(?:\r\n)';
63 self::$_grammar[
'FWS'] =
'(?:(?:'.self::$_grammar[
'WSP'].
'*'.
64 self::$_grammar[
'CRLF'].
')?'.self::$_grammar[
'WSP'].
')';
65 self::$_grammar[
'text'] =
'[\x00-\x08\x0B\x0C\x0E-\x7F]';
66 self::$_grammar[
'quoted-pair'] =
'(?:\\\\'.self::$_grammar[
'text'].
')';
67 self::$_grammar[
'ctext'] =
'(?:'.self::$_grammar[
'NO-WS-CTL'].
68 '|[\x21-\x27\x2A-\x5B\x5D-\x7E])';
70 self::$_grammar[
'ccontent'] =
'(?:'.self::$_grammar[
'ctext'].
'|'.
71 self::$_grammar[
'quoted-pair'].
'|(?1))';
72 self::$_grammar[
'comment'] =
'(\((?:'.self::$_grammar[
'FWS'].
'|'.
73 self::$_grammar[
'ccontent'].
')*'.self::$_grammar[
'FWS'].
'?\))';
74 self::$_grammar[
'CFWS'] =
'(?:(?:'.self::$_grammar[
'FWS'].
'?'.
75 self::$_grammar[
'comment'].
')*(?:(?:'.self::$_grammar[
'FWS'].
'?'.
76 self::$_grammar[
'comment'].
')|'.self::$_grammar[
'FWS'].
'))';
77 self::$_grammar[
'qtext'] =
'(?:'.self::$_grammar[
'NO-WS-CTL'].
78 '|[\x21\x23-\x5B\x5D-\x7E])';
79 self::$_grammar[
'qcontent'] =
'(?:'.self::$_grammar[
'qtext'].
'|'.
80 self::$_grammar[
'quoted-pair'].
')';
81 self::$_grammar[
'quoted-string'] =
'(?:'.self::$_grammar[
'CFWS'].
'?"'.
82 '('.self::$_grammar[
'FWS'].
'?'.self::$_grammar[
'qcontent'].
')*'.
83 self::$_grammar[
'FWS'].
'?"'.self::$_grammar[
'CFWS'].
'?)';
84 self::$_grammar[
'atext'] =
'[a-zA-Z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\}\|~]';
85 self::$_grammar[
'atom'] =
'(?:'.self::$_grammar[
'CFWS'].
'?'.
86 self::$_grammar[
'atext'].
'+'.self::$_grammar[
'CFWS'].
'?)';
87 self::$_grammar[
'dot-atom-text'] =
'(?:'.self::$_grammar[
'atext'].
'+'.
88 '(\.'.self::$_grammar[
'atext'].
'+)*)';
89 self::$_grammar[
'dot-atom'] =
'(?:'.self::$_grammar[
'CFWS'].
'?'.
90 self::$_grammar[
'dot-atom-text'].
'+'.self::$_grammar[
'CFWS'].
'?)';
91 self::$_grammar[
'word'] =
'(?:'.self::$_grammar[
'atom'].
'|'.
92 self::$_grammar[
'quoted-string'].
')';
93 self::$_grammar[
'phrase'] =
'(?:'.self::$_grammar[
'word'].
'+?)';
94 self::$_grammar[
'no-fold-quote'] =
'(?:"(?:'.self::$_grammar[
'qtext'].
95 '|'.self::$_grammar[
'quoted-pair'].
')*")';
96 self::$_grammar[
'dtext'] =
'(?:'.self::$_grammar[
'NO-WS-CTL'].
97 '|[\x21-\x5A\x5E-\x7E])';
98 self::$_grammar[
'no-fold-literal'] =
'(?:\[(?:'.self::$_grammar[
'dtext'].
99 '|'.self::$_grammar[
'quoted-pair'].
')*\])';
102 self::$_grammar[
'id-left'] =
'(?:'.self::$_grammar[
'dot-atom-text'].
'|'.
103 self::$_grammar[
'no-fold-quote'].
')';
104 self::$_grammar[
'id-right'] =
'(?:'.self::$_grammar[
'dot-atom-text'].
'|'.
105 self::$_grammar[
'no-fold-literal'].
')';
108 self::$_grammar[
'local-part'] =
'(?:'.self::$_grammar[
'dot-atom'].
'|'.
109 self::$_grammar[
'quoted-string'].
')';
110 self::$_grammar[
'dcontent'] =
'(?:'.self::$_grammar[
'dtext'].
'|'.
111 self::$_grammar[
'quoted-pair'].
')';
112 self::$_grammar[
'domain-literal'] =
'(?:'.self::$_grammar[
'CFWS'].
'?\[('.
113 self::$_grammar[
'FWS'].
'?'.self::$_grammar[
'dcontent'].
')*?'.
114 self::$_grammar[
'FWS'].
'?\]'.self::$_grammar[
'CFWS'].
'?)';
115 self::$_grammar[
'domain'] =
'(?:'.self::$_grammar[
'dot-atom'].
'|'.
116 self::$_grammar[
'domain-literal'].
')';
117 self::$_grammar[
'addr-spec'] =
'(?:'.self::$_grammar[
'local-part'].
'@'.
118 self::$_grammar[
'domain'].
')';
130 if (array_key_exists($name, self::$_grammar)) {
131 return self::$_grammar[$name];
134 "No such grammar '".$name.
"' defined."
146 return self::$_grammar;
156 return self::$_specials;
170 foreach (array_merge(array(
'\\'), array_diff(self::$_specials, $exclude), $include) as $char) {
171 $token = str_replace($char,
'\\'.$char, $token);