phpDocumentor PHP_LexerGenerator
[ class tree: PHP_LexerGenerator ] [ index: PHP_LexerGenerator ] [ all elements ]

File_ChessPGN lexer generated php code

  1. <?php
  2. //require_once 'File/ChessPGN/Parser.php';
  3. require_once dirname(__FILE__'/Parser.php';
  4.  
  5. class File_ChessPGN_Lexer
  6. {
  7.     const TAGOPEN File_ChessPGN_Parser::TAGOPEN// [
  8.         const TAGNAME File_ChessPGN_Parser::TAGNAME// ]
  9.         const TAGCLOSE File_ChessPGN_Parser::TAGCLOSE// ]
  10.         const STRING File_ChessPGN_Parser::STRING// ]
  11.         const NAG File_ChessPGN_Parser::NAG// $1 $2, etc.
  12.         const GAMEEND File_ChessPGN_Parser::GAMEEND// * 1-0 0-1
  13.         const PAWNMOVE File_ChessPGN_Parser::PAWNMOVE// e4, e8=Q, exd8=R
  14.         const PIECEMOVE File_ChessPGN_Parser::PIECEMOVE// Nf2, Nab2, N3d5, Qxe4, Qexe4, Q3xe4
  15.         const PLACEMENTMOVE File_ChessPGN_Parser::PLACEMENTMOVE// N@f2, P@d5
  16.         const CHECK File_ChessPGN_Parser::CHECK// +
  17.         const MATE File_ChessPGN_Parser::MATE// #
  18.         const DIGIT File_ChessPGN_Parser::DIGIT// 0-9
  19.         const MOVEANNOT File_ChessPGN_Parser::MOVEANNOT// ! ? !! ?? !? ?!
  20.         const RAVOPEN File_ChessPGN_Parser::RAVOPEN// (
  21.         const RAVCLOSE File_ChessPGN_Parser::RAVCLOSE// )
  22.         const PERIOD File_ChessPGN_Parser::PERIOD// .
  23.         const COMMENTOPEN File_ChessPGN_Parser::COMMENTOPEN// {
  24.         const COMMENTCLOSE File_ChessPGN_Parser::COMMENTCLOSE// }
  25.         const COMMENT File_ChessPGN_Parser::COMMENT// anything
  26.         const CASTLE File_ChessPGN_Parser::CASTLE// O-O O-O-O
  27.  
  28.     
  29.     private $input;
  30.     private $N;
  31.     public $token;
  32.     public $value;
  33.     public $line;
  34.     private $_string;
  35.     private $debug 0;
  36.     
  37.     function __construct($data)
  38.     {
  39.         $this->input str_replace("\r\n""\n"$data);
  40.         $this->0;
  41.     }
  42.  
  43.  
  44.     private $_yy_state 1;
  45.     private $_yy_stack array();
  46.  
  47.     function yylex()
  48.     {
  49.         return $this->{'yylex' $this->_yy_state}();
  50.     }
  51.  
  52.     function yypushstate($state)
  53.     {
  54.         array_push($this->_yy_stack$this->_yy_state);
  55.         $this->_yy_state $state;
  56.     }
  57.  
  58.     function yypopstate()
  59.     {
  60.         $this->_yy_state array_pop($this->_yy_stack);
  61.     }
  62.  
  63.     function yybegin($state)
  64.     {
  65.         $this->_yy_state $state;
  66.     }
  67.  
  68.  
  69.  
  70.     function yylex1()
  71.     {
  72.         $tokenMap array (
  73.               => 0,
  74.               => 0,
  75.               => 0,
  76.               => 0,
  77.               => 0,
  78.               => 0,
  79.               => 0,
  80.               => 0,
  81.               => 0,
  82.               10 => 0,
  83.             );
  84.         if ($this->>= strlen($this->input)) {
  85.             return false// end of input
  86.         }
  87.         $yy_global_pattern "/^(\\[)|^(\\()|^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)/";
  88.  
  89.         do {
  90.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  91.                 $yysubmatches $yymatches;
  92.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  93.                 if (!count($yymatches)) {
  94.                     throw new Exception('Error: lexing failed because a rule matched' .
  95.                         'an empty string.  Input "' substr($this->input,
  96.                         $this->N5'... state YYINITIAL');
  97.                 }
  98.                 next($yymatches)// skip global match
  99.                 $this->token key($yymatches)// token number
  100.                 if ($tokenMap[$this->token]{
  101.                     // extract sub-patterns for passing to lex function
  102.                     $yysubmatches array_slice($yysubmatches$this->token 1,
  103.                         $tokenMap[$this->token]);
  104.                 else {
  105.                     $yysubmatches array();
  106.                 }
  107.                 $this->value current($yymatches)// token value
  108.                 $r $this->{'yy_r1_' $this->token}($yysubmatches);
  109.                 if ($r === null{
  110.                     $this->+= strlen($this->value);
  111.                     $this->line += substr_count("\n"$this->value);
  112.                     // accept this token
  113.                     return true;
  114.                 elseif ($r === true{
  115.                     // we have changed state
  116.                     // process this token in the new state
  117.                     return $this->yylex();
  118.                 elseif ($r === false{
  119.                     $this->+= strlen($this->value);
  120.                     $this->line += substr_count("\n"$this->value);
  121.                     if ($this->>= strlen($this->input)) {
  122.                         return false// end of input
  123.                     }
  124.                     // skip this token
  125.                     continue;
  126.                 else {                    $yy_yymore_patterns array(
  127.         => "^(\\()|^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  128.         => "^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  129.         => "^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  130.         => "^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  131.         => "^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  132.         => "^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  133.         => "^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  134.         => "^(O-O-O|O-O)|^([ \n\t]+)",
  135.         => "^([ \n\t]+)",
  136.         10 => "",
  137.     );
  138.  
  139.                     // yymore is needed
  140.                     do {
  141.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  142.                             throw new Exception('cannot do yymore for the last token');
  143.                         }
  144.                         if (preg_match($yy_yymore_patterns[$this->token],
  145.                               substr($this->input$this->N)$yymatches)) {
  146.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  147.                             next($yymatches)// skip global match
  148.                             $this->token key($yymatches)// token number
  149.                             $this->value current($yymatches)// token value
  150.                             $this->line substr_count("\n"$this->value);
  151.                         }
  152.                     while ($this->{'yy_r1_' $this->token}(!== null);
  153.                     // accept
  154.                     $this->+= strlen($this->value);
  155.                     $this->line += substr_count("\n"$this->value);
  156.                     return true;
  157.                 }
  158.             else {
  159.                 throw new Exception('Unexpected input at line' $this->line .
  160.                     ': ' $this->input[$this->N]);
  161.             }
  162.             break;
  163.         while (true);
  164.     // end function
  165.  
  166.  
  167.     
  168.  
  169.  
  170.     const YYINITIAL 1;
  171.     function yy_r1_1($yy_subpatterns)
  172.     {
  173.  
  174.     if ($this->debugecho 'new tag ['.$this->value."]\n";
  175.     $this->token self::TAGOPEN;
  176.     $this->yybegin(self::INTAG);
  177.     }
  178.     function yy_r1_2($yy_subpatterns)
  179.     {
  180.  
  181.     $this->yybegin(self::INMOVES);
  182.     if ($this->debugecho '->found rav ['.$this->value."]\n";
  183.     $this->token self::RAVOPEN;
  184.     }
  185.     function yy_r1_3($yy_subpatterns)
  186.     {
  187.  
  188.     // end of game
  189.     if ($this->debugecho 'found game end ['.$this->value."]\n";
  190.     $this->token self::GAMEEND;
  191.     }
  192.     function yy_r1_4($yy_subpatterns)
  193.     {
  194.  
  195.     $this->yybegin(self::INMOVES);
  196.     if ($this->debugecho '->found digit ['.$this->value."]\n";
  197.     $this->token self::DIGIT;
  198.     }
  199.     function yy_r1_5($yy_subpatterns)
  200.     {
  201.  
  202.     $this->yybegin(self::INMOVES);
  203.     if ($this->debugecho '->found pawn move ['.$this->value."]\n";
  204.     $this->token self::PAWNMOVE;
  205.     }
  206.     function yy_r1_6($yy_subpatterns)
  207.     {
  208.  
  209.     $this->yybegin(self::INMOVES);
  210.     if ($this->debugecho '->found piece move ['.$this->value."]\n";
  211.     $this->token self::PIECEMOVE;
  212.     }
  213.     function yy_r1_7($yy_subpatterns)
  214.     {
  215.  
  216.     $this->yybegin(self::INMOVES);
  217.     if ($this->debugecho '->found placement move ['.$this->value."]\n";
  218.     $this->token self::PLACEMENTMOVE;
  219.     }
  220.     function yy_r1_8($yy_subpatterns)
  221.     {
  222.  
  223.     if ($this->debugecho 'new comment ['.$this->value."]\n";
  224.     $this->yypushstate(self::INCOMMENT);
  225.     $this->token self::COMMENTOPEN;
  226.     }
  227.     function yy_r1_9($yy_subpatterns)
  228.     {
  229.  
  230.     $this->yybegin(self::INMOVES);
  231.     if ($this->debugecho 'found castle move ['.$this->value."]\n";
  232.     $this->token self::CASTLE;
  233.     }
  234.     function yy_r1_10($yy_subpatterns)
  235.     {
  236.  
  237.     // cycle to next token
  238.     return false;
  239.     }
  240.  
  241.  
  242.     function yylex2()
  243.     {
  244.         $tokenMap array (
  245.               => 0,
  246.               => 0,
  247.               => 0,
  248.               => 0,
  249.               => 0,
  250.               => 0,
  251.               => 0,
  252.               => 0,
  253.               => 0,
  254.               10 => 0,
  255.               11 => 0,
  256.               12 => 0,
  257.               13 => 0,
  258.               14 => 0,
  259.               15 => 0,
  260.               16 => 0,
  261.             );
  262.         if ($this->>= strlen($this->input)) {
  263.             return false// end of input
  264.         }
  265.         $yy_global_pattern "/^(\\()|^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))/";
  266.  
  267.         do {
  268.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  269.                 $yysubmatches $yymatches;
  270.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  271.                 if (!count($yymatches)) {
  272.                     throw new Exception('Error: lexing failed because a rule matched' .
  273.                         'an empty string.  Input "' substr($this->input,
  274.                         $this->N5'... state INMOVES');
  275.                 }
  276.                 next($yymatches)// skip global match
  277.                 $this->token key($yymatches)// token number
  278.                 if ($tokenMap[$this->token]{
  279.                     // extract sub-patterns for passing to lex function
  280.                     $yysubmatches array_slice($yysubmatches$this->token 1,
  281.                         $tokenMap[$this->token]);
  282.                 else {
  283.                     $yysubmatches array();
  284.                 }
  285.                 $this->value current($yymatches)// token value
  286.                 $r $this->{'yy_r2_' $this->token}($yysubmatches);
  287.                 if ($r === null{
  288.                     $this->+= strlen($this->value);
  289.                     $this->line += substr_count("\n"$this->value);
  290.                     // accept this token
  291.                     return true;
  292.                 elseif ($r === true{
  293.                     // we have changed state
  294.                     // process this token in the new state
  295.                     return $this->yylex();
  296.                 elseif ($r === false{
  297.                     $this->+= strlen($this->value);
  298.                     $this->line += substr_count("\n"$this->value);
  299.                     if ($this->>= strlen($this->input)) {
  300.                         return false// end of input
  301.                     }
  302.                     // skip this token
  303.                     continue;
  304.                 else {                    $yy_yymore_patterns array(
  305.         => "^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  306.         => "^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  307.         => "^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  308.         => "^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  309.         => "^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  310.         => "^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  311.         => "^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  312.         => "^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  313.         => "^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  314.         10 => "^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  315.         11 => "^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  316.         12 => "^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  317.         13 => "^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  318.         14 => "^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  319.         15 => "^(\\))",
  320.         16 => "",
  321.     );
  322.  
  323.                     // yymore is needed
  324.                     do {
  325.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  326.                             throw new Exception('cannot do yymore for the last token');
  327.                         }
  328.                         if (preg_match($yy_yymore_patterns[$this->token],
  329.                               substr($this->input$this->N)$yymatches)) {
  330.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  331.                             next($yymatches)// skip global match
  332.                             $this->token key($yymatches)// token number
  333.                             $this->value current($yymatches)// token value
  334.                             $this->line substr_count("\n"$this->value);
  335.                         }
  336.                     while ($this->{'yy_r2_' $this->token}(!== null);
  337.                     // accept
  338.                     $this->+= strlen($this->value);
  339.                     $this->line += substr_count("\n"$this->value);
  340.                     return true;
  341.                 }
  342.             else {
  343.                 throw new Exception('Unexpected input at line' $this->line .
  344.                     ': ' $this->input[$this->N]);
  345.             }
  346.             break;
  347.         while (true);
  348.     // end function
  349.  
  350.  
  351.     
  352.  
  353.  
  354.     const INMOVES 2;
  355.     function yy_r2_1($yy_subpatterns)
  356.     {
  357.  
  358.     if ($this->debugecho '->found rav ['.$this->value."]\n";
  359.     $this->token self::RAVOPEN;
  360.     }
  361.     function yy_r2_2($yy_subpatterns)
  362.     {
  363.  
  364.     // end of game
  365.     $this->yybegin(self::YYINITIAL);
  366.     if ($this->debugecho 'found game end ['.$this->value."]\n";
  367.     $this->token self::GAMEEND;
  368.     }
  369.     function yy_r2_3($yy_subpatterns)
  370.     {
  371.  
  372.     if ($this->debugecho '->found digit ['.$this->value."]\n";
  373.     $this->token self::DIGIT;
  374.     }
  375.     function yy_r2_4($yy_subpatterns)
  376.     {
  377.  
  378.     if ($this->debugecho '->found pawn move ['.$this->value."]\n";
  379.     $this->token self::PAWNMOVE;
  380.     }
  381.     function yy_r2_5($yy_subpatterns)
  382.     {
  383.  
  384.     if ($this->debugecho '->found piece move ['.$this->value."]\n";
  385.     $this->token self::PIECEMOVE;
  386.     }
  387.     function yy_r2_6($yy_subpatterns)
  388.     {
  389.  
  390.     if ($this->debugecho '->found placement move ['.$this->value."]\n";
  391.     $this->token self::PLACEMENTMOVE;
  392.     }
  393.     function yy_r2_7($yy_subpatterns)
  394.     {
  395.  
  396.     if ($this->debugecho 'new comment ['.$this->value."]\n";
  397.     $this->yypushstate(self::INCOMMENT);
  398.     $this->token self::COMMENTOPEN;
  399.     }
  400.     function yy_r2_8($yy_subpatterns)
  401.     {
  402.  
  403.     if ($this->debugecho 'found castle move ['.$this->value."]\n";
  404.     $this->token self::CASTLE;
  405.     }
  406.     function yy_r2_9($yy_subpatterns)
  407.     {
  408.  
  409.     // cycle to next token
  410.     return false;
  411.     }
  412.     function yy_r2_10($yy_subpatterns)
  413.     {
  414.  
  415.     if ($this->debugecho 'found numeric annotation glyph ['.$this->value."]\n";
  416.     $this->token self::NAG;
  417.     }
  418.     function yy_r2_11($yy_subpatterns)
  419.     {