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);
         }
     }
 }
Ejemplo n.º 3
0
 public static function forType($type)
 {
     return CommonToken::forInput($input = null, $type);
 }
Ejemplo n.º 4
0
 /** The standard method called to automatically emit a token at the
  *  outermost lexical rule.  The token object should point into the
  *  char buffer start..stop.  If there is a text override in 'text',
  *  use that to set the token's text.  Override this method to emit
  *  custom Token objects.
  *
  *  If you are building trees, then you should also override
  *  Parser or TreeParser.getMissingSymbol().
  */
 public function emit($token = null)
 {
     if ($token == null) {
         $token = new CommonToken($this->input, $this->state->type, $this->state->channel, $this->state->tokenStartCharIndex, $this->getCharIndex() - 1);
         $token->setLine($this->state->tokenStartLine);
         $token->setText($this->state->text);
         $token->setCharPositionInLine($this->state->tokenStartCharPositionInLine);
     }
     $this->state->token = $token;
     return $token;
 }
Ejemplo n.º 5
0
     *  so that whitespace etc... can go to the parser on a "hidden" channel.
     */
    public static $DEFAULT_CHANNEL = 0;
    /** Anything on different channel than DEFAULT_CHANNEL is not parsed
     *  by parser.
     */
    public static $HIDDEN_CHANNEL = 99;
}
interface Token
{
}
TokenConst::$DEFAULT_CHANNEL = 0;
TokenConst::$INVALID_TOKEN_TYPE = 0;
TokenConst::$EOF = CharStreamConst::$EOF;
TokenConst::$EOF_TOKEN = CommonToken::forType(TokenConst::$EOF);
TokenConst::$INVALID_TOKEN_TYPE = 0;
TokenConst::$INVALID_TOKEN = CommonToken::forType(TokenConst::$INVALID_TOKEN_TYPE);
/** In an action, a lexer rule can set token to this SKIP_TOKEN and ANTLR
 *  will avoid creating a token for this symbol and try to fetch another.
 */
TokenConst::$SKIP_TOKEN = CommonToken::forType(TokenConst::$INVALID_TOKEN_TYPE);
/** All tokens go to the parser (unless skip() is called in that rule)
 *  on a particular "channel".  The parser tunes to a particular channel
 *  so that whitespace etc... can go to the parser on a "hidden" channel.
 */
TokenConst::$DEFAULT_CHANNEL = 0;
/** Anything on different channel than DEFAULT_CHANNEL is not parsed
 *  by parser.
 */
TokenConst::$HIDDEN_CHANNEL = 99;
TokenConst::$MIN_TOKEN_TYPE = TokenConst::$UP + 1;
Ejemplo n.º 6
0
 function mBLANK_NODE_LABEL()
 {
     try {
         $_type = Erfurt_Sparql_Parser_Sparql10_Sparql10_Tokenizer::$BLANK_NODE_LABEL;
         $_channel = Erfurt_Sparql_Parser_Sparql10_Sparql10_Tokenizer::$DEFAULT_TOKEN_CHANNEL;
         $t = null;
         $this->matchString("_:");
         $tStart2227 = $this->getCharIndex();
         $this->mPN_LOCAL();
         $t = new CommonToken($this->input, TokenConst::$INVALID_TOKEN_TYPE, TokenConst::$DEFAULT_CHANNEL, $tStart2227, $this->getCharIndex() - 1);
         $this->setText($t != null ? $t->getText() : null);
         $this->state->type = $_type;
         $this->state->channel = $_channel;
     } catch (Exception $e) {
         throw $e;
     }
 }