PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/php-pear-CodeGen-PECL-1.1.3/CodeGen_PECL-1.1.3/PECL/Tools/ProtoLexer.php

#
PHP | 304 lines | 267 code | 31 blank | 6 comment | 13 complexity | d5f11e4cebc8b30d5927cf9dba167b8c MD5 | raw file
  1. <?php
  2. class CodeGen_PECL_Tools_ProtoLexer
  3. {
  4. private $data;
  5. public $token;
  6. public $value;
  7. private $line;
  8. private $count;
  9. function __construct($data)
  10. {
  11. $this->data = $data;
  12. $this->count = 0;
  13. $this->line = 1;
  14. }
  15. private $_yy_state = 1;
  16. private $_yy_stack = array();
  17. function yylex()
  18. {
  19. return $this->{'yylex' . $this->_yy_state}();
  20. }
  21. function yypushstate($state)
  22. {
  23. array_push($this->_yy_stack, $this->_yy_state);
  24. $this->_yy_state = $state;
  25. }
  26. function yypopstate()
  27. {
  28. $this->_yy_state = array_pop($this->_yy_stack);
  29. }
  30. function yybegin($state)
  31. {
  32. $this->_yy_state = $state;
  33. }
  34. function yylex1()
  35. {
  36. $tokenMap = array (
  37. 1 => 0,
  38. 2 => 0,
  39. 3 => 0,
  40. 4 => 0,
  41. 5 => 0,
  42. 6 => 0,
  43. 7 => 0,
  44. 8 => 0,
  45. 9 => 0,
  46. 10 => 0,
  47. 11 => 0,
  48. 12 => 0,
  49. 13 => 2,
  50. 16 => 0,
  51. 17 => 0,
  52. );
  53. if ($this->count >= strlen($this->data)) {
  54. return false; // end of input
  55. }
  56. $yy_global_pattern = "/^([ \t\n]+)|^(\\()|^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)/";
  57. do {
  58. if (preg_match($yy_global_pattern, substr($this->data, $this->count), $yymatches)) {
  59. $yysubmatches = $yymatches;
  60. $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
  61. if (!count($yymatches)) {
  62. throw new Exception('Error: lexing failed because a rule matched' .
  63. 'an empty string. Input "' . substr($this->data,
  64. $this->count, 5) . '... state 1');
  65. }
  66. next($yymatches); // skip global match
  67. $this->token = key($yymatches); // token number
  68. if ($tokenMap[$this->token]) {
  69. // extract sub-patterns for passing to lex function
  70. $yysubmatches = array_slice($yysubmatches, $this->token + 1,
  71. $tokenMap[$this->token]);
  72. } else {
  73. $yysubmatches = array();
  74. }
  75. $this->value = current($yymatches); // token value
  76. $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
  77. if ($r === null) {
  78. $this->count += strlen($this->value);
  79. $this->line += substr_count($this->value, "\n");
  80. // accept this token
  81. return true;
  82. } elseif ($r === true) {
  83. // we have changed state
  84. // process this token in the new state
  85. return $this->yylex();
  86. } elseif ($r === false) {
  87. $this->count += strlen($this->value);
  88. $this->line += substr_count($this->value, "\n");
  89. if ($this->count >= strlen($this->data)) {
  90. return false; // end of input
  91. }
  92. // skip this token
  93. continue;
  94. } else { $yy_yymore_patterns = array(
  95. 1 => array(0, "^(\\()|^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  96. 2 => array(0, "^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  97. 3 => array(0, "^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  98. 4 => array(0, "^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  99. 5 => array(0, "^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  100. 6 => array(0, "^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  101. 7 => array(0, "^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  102. 8 => array(0, "^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  103. 9 => array(0, "^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  104. 10 => array(0, "^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  105. 11 => array(0, "^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  106. 12 => array(0, "^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  107. 13 => array(2, "^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  108. 16 => array(2, "^(0x[0-9a-fA-F]+)"),
  109. 17 => array(2, ""),
  110. );
  111. // yymore is needed
  112. do {
  113. if (!strlen($yy_yymore_patterns[$this->token][1])) {
  114. throw new Exception('cannot do yymore for the last token');
  115. }
  116. $yysubmatches = array();
  117. if (preg_match('/' . $yy_yymore_patterns[$this->token][1] . '/',
  118. substr($this->data, $this->count), $yymatches)) {
  119. $yysubmatches = $yymatches;
  120. $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
  121. next($yymatches); // skip global match
  122. $this->token += key($yymatches) + $yy_yymore_patterns[$this->token][0]; // token number
  123. $this->value = current($yymatches); // token value
  124. $this->line = substr_count($this->value, "\n");
  125. if ($tokenMap[$this->token]) {
  126. // extract sub-patterns for passing to lex function
  127. $yysubmatches = array_slice($yysubmatches, $this->token + 1,
  128. $tokenMap[$this->token]);
  129. } else {
  130. $yysubmatches = array();
  131. }
  132. }
  133. $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
  134. } while ($r !== null && !is_bool($r));
  135. if ($r === true) {
  136. // we have changed state
  137. // process this token in the new state
  138. return $this->yylex();
  139. } elseif ($r === false) {
  140. $this->count += strlen($this->value);
  141. $this->line += substr_count($this->value, "\n");
  142. if ($this->count >= strlen($this->data)) {
  143. return false; // end of input
  144. }
  145. // skip this token
  146. continue;
  147. } else {
  148. // accept
  149. $this->count += strlen($this->value);
  150. $this->line += substr_count($this->value, "\n");
  151. return true;
  152. }
  153. }
  154. } else {
  155. throw new Exception('Unexpected input at line' . $this->line .
  156. ': ' . $this->data[$this->count]);
  157. }
  158. break;
  159. } while (true);
  160. } // end function
  161. function yy_r1_1($yy_subpatterns)
  162. {
  163. return false;
  164. }
  165. function yy_r1_2($yy_subpatterns)
  166. {
  167. $this->token = CodeGen_PECL_Tools_ProtoParser::PAR_OPEN;
  168. }
  169. function yy_r1_3($yy_subpatterns)
  170. {
  171. $this->token = CodeGen_PECL_Tools_ProtoParser::PAR_CLOSE;
  172. }
  173. function yy_r1_4($yy_subpatterns)
  174. {
  175. $this->token = CodeGen_PECL_Tools_ProtoParser::SQUARE_OPEN;
  176. }
  177. function yy_r1_5($yy_subpatterns)
  178. {
  179. $this->token = CodeGen_PECL_Tools_ProtoParser::SQUARE_CLOSE;
  180. }
  181. function yy_r1_6($yy_subpatterns)
  182. {
  183. $this->token = CodeGen_PECL_Tools_ProtoParser::EQ;
  184. }
  185. function yy_r1_7($yy_subpatterns)
  186. {
  187. $this->token = CodeGen_PECL_Tools_ProtoParser::COMMA;
  188. }
  189. function yy_r1_8($yy_subpatterns)
  190. {
  191. $this->token = CodeGen_PECL_Tools_ProtoParser::SEMICOLON;
  192. }
  193. function yy_r1_9($yy_subpatterns)
  194. {
  195. $this->token = CodeGen_PECL_Tools_ProtoParser::ELLIPSE;
  196. }
  197. function yy_r1_10($yy_subpatterns)
  198. {
  199. $this->token = CodeGen_PECL_Tools_ProtoParser::AMPERSAND;
  200. }
  201. function yy_r1_11($yy_subpatterns)
  202. {
  203. switch ($this->value) {
  204. case "void":
  205. $this->token = CodeGen_PECL_Tools_ProtoParser::VOID;
  206. break;
  207. case "bool":
  208. case "boolean":
  209. $this->token = CodeGen_PECL_Tools_ProtoParser::BOOL;
  210. break;
  211. case "int":
  212. case "integer":
  213. case "long":
  214. $this->token = CodeGen_PECL_Tools_ProtoParser::INT;
  215. break;
  216. case "float":
  217. case "double":
  218. $this->token = CodeGen_PECL_Tools_ProtoParser::FLOAT;
  219. break;
  220. case "string":
  221. $this->token = CodeGen_PECL_Tools_ProtoParser::STRING;
  222. break;
  223. case "array":
  224. $this->token = CodeGen_PECL_Tools_ProtoParser::ARRAY_;
  225. break;
  226. case "class":
  227. case "object":
  228. $this->token = CodeGen_PECL_Tools_ProtoParser::CLASS_;
  229. break;
  230. case "resource":
  231. $this->token = CodeGen_PECL_Tools_ProtoParser::RESOURCE;
  232. break;
  233. case "mixed":
  234. $this->token = CodeGen_PECL_Tools_ProtoParser::MIXED;
  235. break;
  236. case "callback":
  237. $this->token = CodeGen_PECL_Tools_ProtoParser::CALLBACK;
  238. break;
  239. case "stream":
  240. $this->token = CodeGen_PECL_Tools_ProtoParser::STREAM;
  241. break;
  242. case "true":
  243. $this->token = CodeGen_PECL_Tools_ProtoParser::TRUE_;
  244. break;
  245. case "false":
  246. $this->token = CodeGen_PECL_Tools_ProtoParser::FALSE_;
  247. break;
  248. case "null":
  249. $this->token = CodeGen_PECL_Tools_ProtoParser::NULL_;
  250. break;
  251. default:
  252. $this->token = CodeGen_PECL_Tools_ProtoParser::NAME;
  253. break;
  254. }
  255. }
  256. function yy_r1_12($yy_subpatterns)
  257. {
  258. $this->token = CodeGen_PECL_Tools_ProtoParser::STRVAL;
  259. }
  260. function yy_r1_13($yy_subpatterns)
  261. {
  262. $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  263. }
  264. function yy_r1_16($yy_subpatterns)
  265. {
  266. $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  267. }
  268. function yy_r1_17($yy_subpatterns)
  269. {
  270. $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  271. }
  272. }