Ejemplo n.º 1
0
 protected function getMissingSymbol($input, $e, $expectedTokenType, $follow)
 {
     $tokenText = null;
     if ($expectedTokenType == TokenConst::$EOF) {
         $tokenText = "<missing EOF>";
     } else {
         $tokenNames = $this->getTokenNames();
         $tokenText = "<missing " . $tokenNames[$expectedTokenType] . ">";
     }
     $t = CommonToken::forTypeAndText($expectedTokenType, $tokenText);
     $current = $input->LT(1);
     if ($current->getType() == TokenConst::$EOF) {
         $current = $this->input->LT(-1);
     }
     $t->line = $current->getLine();
     $t->charPositionInLine = $current->getCharPositionInLine();
     $t->channel = $DEFAULT_TOKEN_CHANNEL;
     return $t;
 }
Ejemplo n.º 2
0
 protected function extractInformationFromTreeNodeStream($input)
 {
     $nodes = $input;
     $this->node = $nodes->LT(1);
     $adaptor = $nodes->getTreeAdaptor();
     $payload = $adaptor->getToken($this->node);
     if ($payload != null) {
         $this->token = $payload;
         if ($payload->getLine() <= 0) {
             // imaginary node; no line/pos info; scan backwards
             $i = -1;
             $priorNode = $nodes->LT($i);
             while ($priorNode != null) {
                 $priorPayload = $adaptor->getToken($priorNode);
                 if ($priorPayload != null && $priorPayload->getLine() > 0) {
                     // we found the most recent real line / pos info
                     $this->line = $priorPayload->getLine();
                     $this->charPositionInLine = $priorPayload->getCharPositionInLine();
                     $this->approximateLineInfo = true;
                     break;
                 }
                 --$i;
                 $priorNode = $nodes->LT($i);
             }
         } else {
             // node created from real token
             $this->line = $payload->getLine();
             $this->charPositionInLine = $payload->getCharPositionInLine();
         }
     } else {
         if ($this->node instanceof Tree) {
             $this->line = $this->node->getLine();
             $this->charPositionInLine = $this->node->getCharPositionInLine();
             if ($this->node instanceof CommonTree) {
                 $this->token = $this->node->token;
             }
         } else {
             $type = $adaptor->getType($this->node);
             $text = $adaptor->getText($this->node);
             $this->token = CommonToken::forTypeAndText($type, $text);
         }
     }
 }