diff options
author | emkael <emkael@tlen.pl> | 2017-01-18 20:07:16 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-01-18 20:07:16 +0100 |
commit | 9a9c04512e5dcb77c7fe5d850e3f2a0250cc160e (patch) | |
tree | fed46b5f4c2ed3a050bb1a7ad7c6d0a3ea844d55 /lib/querypath/src/QueryPath/CSS/Token.php | |
parent | c5bcf8f74fb80b7e163663845b0d6e35cabface3 (diff) |
* Motor Sport Magazine feed provider
Diffstat (limited to 'lib/querypath/src/QueryPath/CSS/Token.php')
-rw-r--r-- | lib/querypath/src/QueryPath/CSS/Token.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/querypath/src/QueryPath/CSS/Token.php b/lib/querypath/src/QueryPath/CSS/Token.php new file mode 100644 index 0000000..3c31ef4 --- /dev/null +++ b/lib/querypath/src/QueryPath/CSS/Token.php @@ -0,0 +1,60 @@ +<?php +/** @file + * Parser tokens. + */ +namespace QueryPath\CSS; +/** + * Tokens for CSS. + * This class defines the recognized tokens for the parser, and also + * provides utility functions for error reporting. + * + * @ingroup querypath_css + */ +final class Token { + const char = 0; + const star = 1; + const rangle = 2; + const dot = 3; + const octo = 4; + const rsquare = 5; + const lsquare = 6; + const colon = 7; + const rparen = 8; + const lparen = 9; + const plus = 10; + const tilde = 11; + const eq = 12; + const pipe = 13; + const comma = 14; + const white = 15; + const quote = 16; + const squote = 17; + const bslash = 18; + const carat = 19; + const dollar = 20; + const at = 21; // This is not in the spec. Apparently, old broken CSS uses it. + + // In legal range for string. + const stringLegal = 99; + + /** + * Get a name for a given constant. Used for error handling. + */ + static function name($const_int) { + $a = array('character', 'star', 'right angle bracket', + 'dot', 'octothorp', 'right square bracket', 'left square bracket', + 'colon', 'right parenthesis', 'left parenthesis', 'plus', 'tilde', + 'equals', 'vertical bar', 'comma', 'space', 'quote', 'single quote', + 'backslash', 'carat', 'dollar', 'at'); + if (isset($a[$const_int]) && is_numeric($const_int)) { + return $a[$const_int]; + } + elseif ($const_int == 99) { + return 'a legal non-alphanumeric character'; + } + elseif ($const_int == FALSE) { + return 'end of file'; + } + return sprintf('illegal character (%s)', $const_int); + } +} |