@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | public function __construct($input, $state = null) { |
| 38 | 38 | parent::__construct($state); // share the state object with another parser |
| 39 | 39 | $this->setTokenStream($input); |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | public function reset() { |
| 43 | 43 | parent::reset(); // reset all recognizer state variables |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $this->input = $input; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function getTokenStream() { |
|
| 80 | + public function getTokenStream() { |
|
| 81 | 81 | return $this->input; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | public function reset() { |
| 43 | 43 | parent::reset(); // reset all recognizer state variables |
| 44 | - if ( $this->input!=null ) { |
|
| 44 | + if ($this->input != null) { |
|
| 45 | 45 | $this->input->seek(0); // rewind the input |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -53,15 +53,15 @@ discard block |
||
| 53 | 53 | protected function getMissingSymbol($input, $e, $expectedTokenType, $follow) |
| 54 | 54 | { |
| 55 | 55 | $tokenText = null; |
| 56 | - if ( $expectedTokenType==TokenConst::$EOF ){ |
|
| 56 | + if ($expectedTokenType == TokenConst::$EOF) { |
|
| 57 | 57 | $tokenText = "<missing EOF>"; |
| 58 | 58 | } else { |
| 59 | 59 | $tokenNames = $this->getTokenNames(); |
| 60 | - $tokenText = "<missing ".$tokenNames[$expectedTokenType].">"; |
|
| 60 | + $tokenText = "<missing " . $tokenNames[$expectedTokenType] . ">"; |
|
| 61 | 61 | } |
| 62 | 62 | $t = CommonToken::forTypeAndText($expectedTokenType, $tokenText); |
| 63 | 63 | $current = $input->LT(1); |
| 64 | - if ( $current->getType() == TokenConst::$EOF ) { |
|
| 64 | + if ($current->getType() == TokenConst::$EOF) { |
|
| 65 | 65 | $current = $this->input->LT(-1); |
| 66 | 66 | } |
| 67 | 67 | $t->line = $current->getLine(); |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | return $this->input->getSourceName(); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - public function traceIn($ruleName, $ruleIndex, $inputSymbol=null) { |
|
| 88 | + public function traceIn($ruleName, $ruleIndex, $inputSymbol = null) { |
|
| 89 | 89 | parent::traceIn($ruleName, $ruleIndex, $this->input->LT(1)); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function traceOut($ruleName, $ruleIndex, $inputSymbol=null) { |
|
| 92 | + public function traceOut($ruleName, $ruleIndex, $inputSymbol = null) { |
|
| 93 | 93 | parent::traceOut($ruleName, $ruleIndex, $this->input->LT(1)); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | |
| 11 | 11 | public static $MIN_TOKEN_TYPE;// = UP+1; |
| 12 | 12 | |
| 13 | - public static $EOF;// = CharStream.EOF; |
|
| 13 | + public static $EOF;// = CharStream.EOF; |
|
| 14 | 14 | public static $EOF_TOKEN;// = new CommonToken(EOF); |
| 15 | 15 | |
| 16 | 16 | public static $INVALID_TOKEN_TYPE = 0; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - class TokenConst{ |
|
| 3 | + class TokenConst { |
|
| 4 | 4 | public static $EOR_TOKEN_TYPE = 1; |
| 5 | 5 | |
| 6 | 6 | /** imaginary tree navigation type; traverse "get child" link */ |
@@ -8,18 +8,18 @@ discard block |
||
| 8 | 8 | /** imaginary tree navigation type; finish with a child list */ |
| 9 | 9 | public static $UP = 3; |
| 10 | 10 | |
| 11 | - public static $MIN_TOKEN_TYPE;// = UP+1; |
|
| 11 | + public static $MIN_TOKEN_TYPE; // = UP+1; |
|
| 12 | 12 | |
| 13 | - public static $EOF;// = CharStream.EOF; |
|
| 14 | - public static $EOF_TOKEN;// = new CommonToken(EOF); |
|
| 13 | + public static $EOF; // = CharStream.EOF; |
|
| 14 | + public static $EOF_TOKEN; // = new CommonToken(EOF); |
|
| 15 | 15 | |
| 16 | 16 | public static $INVALID_TOKEN_TYPE = 0; |
| 17 | - public static $INVALID_TOKEN;// = new CommonToken(INVALID_TOKEN_TYPE); |
|
| 17 | + public static $INVALID_TOKEN; // = new CommonToken(INVALID_TOKEN_TYPE); |
|
| 18 | 18 | |
| 19 | 19 | /** In an action, a lexer rule can set token to this SKIP_TOKEN and ANTLR |
| 20 | 20 | * will avoid creating a token for this symbol and try to fetch another. |
| 21 | 21 | */ |
| 22 | - public static $SKIP_TOKEN;// = new CommonToken(INVALID_TOKEN_TYPE); |
|
| 22 | + public static $SKIP_TOKEN; // = new CommonToken(INVALID_TOKEN_TYPE); |
|
| 23 | 23 | |
| 24 | 24 | /** All tokens go to the parser (unless skip() is called in that rule) |
| 25 | 25 | * on a particular "channel". The parser tunes to a particular channel |
@@ -34,20 +34,20 @@ discard block |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - interface Token{ |
|
| 37 | + interface Token { |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | class CommonToken implements Token { |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - public function __construct(){ |
|
| 44 | + public function __construct() { |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public static function forInput($input=null, $type, $channel=0, $start=0, $stop=0) { |
|
| 48 | + public static function forInput($input = null, $type, $channel = 0, $start = 0, $stop = 0) { |
|
| 49 | 49 | $ct = new CommonToken(); |
| 50 | - $ct->charPositionInLine=-1; |
|
| 50 | + $ct->charPositionInLine = -1; |
|
| 51 | 51 | $ct->input = $input; |
| 52 | 52 | $ct->type = $type; |
| 53 | 53 | $ct->channel = $channel; |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | return $ct; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public static function forType($type){ |
|
| 60 | - return CommonToken::forInput($input=null, $type); |
|
| 59 | + public static function forType($type) { |
|
| 60 | + return CommonToken::forInput($input = null, $type); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public static function forTypeAndText($type, $text) { |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | public function getText() { |
| 93 | - if ( $this->text!=null ) { |
|
| 93 | + if ($this->text != null) { |
|
| 94 | 94 | return $this->text; |
| 95 | 95 | } |
| 96 | - if ( $this->input==null ) { |
|
| 96 | + if ($this->input == null) { |
|
| 97 | 97 | return null; |
| 98 | 98 | } |
| 99 | - $this->text = $this->input->substring($this->start,$this->stop); |
|
| 99 | + $this->text = $this->input->substring($this->start, $this->stop); |
|
| 100 | 100 | return $this->text; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -167,28 +167,28 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | public function toString() { |
| 169 | 169 | $channelStr = ""; |
| 170 | - if ( $this->channel>0 ) { |
|
| 171 | - $channelStr=",channel=".$this->channel; |
|
| 170 | + if ($this->channel > 0) { |
|
| 171 | + $channelStr = ",channel=" . $this->channel; |
|
| 172 | 172 | } |
| 173 | 173 | $txt = $this->getText(); |
| 174 | - if ( $txt!=null ) { |
|
| 175 | - $txt = str_replace("\n",'\n', $txt); |
|
| 176 | - $txt = str_replace("\r",'\r', $txt); |
|
| 177 | - $txt = str_replace("\t",'\t', $txt); |
|
| 174 | + if ($txt != null) { |
|
| 175 | + $txt = str_replace("\n", '\n', $txt); |
|
| 176 | + $txt = str_replace("\r", '\r', $txt); |
|
| 177 | + $txt = str_replace("\t", '\t', $txt); |
|
| 178 | 178 | } |
| 179 | 179 | else { |
| 180 | 180 | $txt = "<no text>"; |
| 181 | 181 | } |
| 182 | - return "[@".$this->getTokenIndex().",".$this->start.":".$this->stop."='".$txt."',<".$this->type.">".$channelStr.",".$this->line.":".$this->getCharPositionInLine()."]"; |
|
| 182 | + return "[@" . $this->getTokenIndex() . "," . $this->start . ":" . $this->stop . "='" . $txt . "',<" . $this->type . ">" . $channelStr . "," . $this->line . ":" . $this->getCharPositionInLine() . "]"; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - public function __toString(){ |
|
| 185 | + public function __toString() { |
|
| 186 | 186 | return $this->toString(); |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - TokenConst::$DEFAULT_CHANNEL=0; |
|
| 191 | - TokenConst::$INVALID_TOKEN_TYPE=0; |
|
| 190 | + TokenConst::$DEFAULT_CHANNEL = 0; |
|
| 191 | + TokenConst::$INVALID_TOKEN_TYPE = 0; |
|
| 192 | 192 | |
| 193 | 193 | TokenConst::$EOF = CharStreamConst::$EOF; |
| 194 | 194 | TokenConst::$EOF_TOKEN = CommonToken::forType(TokenConst::$EOF); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | |
| 215 | 215 | |
| 216 | - TokenConst::$MIN_TOKEN_TYPE = TokenConst::$UP+1; |
|
| 216 | + TokenConst::$MIN_TOKEN_TYPE = TokenConst::$UP + 1; |
|
| 217 | 217 | |
| 218 | 218 | |
| 219 | 219 | |
@@ -175,8 +175,7 @@ |
||
| 175 | 175 | $txt = str_replace("\n",'\n', $txt); |
| 176 | 176 | $txt = str_replace("\r",'\r', $txt); |
| 177 | 177 | $txt = str_replace("\t",'\t', $txt); |
| 178 | - } |
|
| 179 | - else { |
|
| 178 | + } else { |
|
| 180 | 179 | $txt = "<no text>"; |
| 181 | 180 | } |
| 182 | 181 | return "[@".$this->getTokenIndex().",".$this->start.":".$this->stop."='".$txt."',<".$this->type.">".$channelStr.",".$this->line.":".$this->getCharPositionInLine()."]"; |
@@ -41,18 +41,18 @@ |
||
| 41 | 41 | public function LA($i); |
| 42 | 42 | |
| 43 | 43 | /** Tell the stream to start buffering if it hasn't already. Return |
| 44 | - * current input position, index(), or some other marker so that |
|
| 44 | + * current input position, index(), or some other marker so that |
|
| 45 | 45 | * when passed to rewind() you get back to the same spot. |
| 46 | 46 | * rewind(mark()) should not affect the input cursor. The Lexer |
| 47 | 47 | * track line/col info as well as input index so its markers are |
| 48 | 48 | * not pure input indexes. Same for tree node streams. |
| 49 | - */ |
|
| 49 | + */ |
|
| 50 | 50 | public function mark(); |
| 51 | 51 | |
| 52 | 52 | /** Return the current input symbol index 0..n where n indicates the |
| 53 | - * last symbol has been read. The index is the symbol about to be |
|
| 53 | + * last symbol has been read. The index is the symbol about to be |
|
| 54 | 54 | * read not the most recently read symbol. |
| 55 | - */ |
|
| 55 | + */ |
|
| 56 | 56 | public function index(); |
| 57 | 57 | |
| 58 | 58 | /** Reset the stream so that next call to index would return marker. |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | * like a stack. Assume the state the stream was in when this marker |
| 64 | 64 | * was created. |
| 65 | 65 | */ |
| 66 | - public function rewind($marker=null); |
|
| 66 | + public function rewind($marker = null); |
|
| 67 | 67 | |
| 68 | 68 | /** You may want to commit to a backtrack but don't want to force the |
| 69 | 69 | * stream to keep bookkeeping objects around for a marker that is |
@@ -29,13 +29,13 @@ |
||
| 29 | 29 | |
| 30 | 30 | /** A stream of tokens accessing tokens from a TokenSource */ |
| 31 | 31 | interface TokenStream extends IntStream { |
| 32 | - /** Get Token at current input pointer + i ahead where i=1 is next Token. |
|
| 32 | + /** Get Token at current input pointer + i ahead where i=1 is next Token. |
|
| 33 | 33 | * i<0 indicates tokens in the past. So -1 is previous token and -2 is |
| 34 | 34 | * two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken. |
| 35 | 35 | * Return null for LT(0) and any index that results in an absolute address |
| 36 | 36 | * that is negative. |
| 37 | 37 | */ |
| 38 | - public function LT($k); |
|
| 38 | + public function LT($k); |
|
| 39 | 39 | |
| 40 | 40 | /** Get a token at an absolute index i; 0..n-1. This is really only |
| 41 | 41 | * needed for profiling and debugging and token stream rewriting. |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | * something nonnull so that the auto token emit mechanism will not |
| 56 | 56 | * emit another token. |
| 57 | 57 | */ |
| 58 | - $this->token = null; |
|
| 58 | + $this->token = null; |
|
| 59 | 59 | |
| 60 | 60 | /** What character index in the stream did the current token start at? |
| 61 | 61 | * Needed, for example, to get the text for current token. Set at |
| 62 | 62 | * the start of nextToken. |
| 63 | - */ |
|
| 63 | + */ |
|
| 64 | 64 | $this->tokenStartCharIndex = -1; |
| 65 | 65 | |
| 66 | 66 | /** The line on which the first character of the token resides */ |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | /** You can set the text for the current token to override what is in |
| 79 | 79 | * the input char buffer. Use setText() or can set this instance var. |
| 80 | - */ |
|
| 80 | + */ |
|
| 81 | 81 | $this->text=null; |
| 82 | 82 | |
| 83 | 83 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class RecognizerSharedState { |
| 3 | - public function __construct(){ |
|
| 3 | + public function __construct() { |
|
| 4 | 4 | /** Track the set of token types that can follow any rule invocation. |
| 5 | 5 | * Stack grows upwards. When it hits the max, it grows 2x in size |
| 6 | 6 | * and keeps going. |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | /** In lieu of a return value, this indicates that a rule or token |
| 25 | 25 | * has failed to match. Reset to false upon valid token match. |
| 26 | 26 | */ |
| 27 | - $this->failed=false; |
|
| 27 | + $this->failed = false; |
|
| 28 | 28 | /** Did the recognizer encounter a syntax error? Track how many. */ |
| 29 | - $this->syntaxErrors=0; |
|
| 29 | + $this->syntaxErrors = 0; |
|
| 30 | 30 | |
| 31 | 31 | /** If 0, no backtracking is going on. Safe to exec actions etc... |
| 32 | 32 | * If >0 then it's the level of backtracking. |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | /** You can set the text for the current token to override what is in |
| 79 | 79 | * the input char buffer. Use setText() or can set this instance var. |
| 80 | 80 | */ |
| 81 | - $this->text=null; |
|
| 81 | + $this->text = null; |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | |
@@ -2,12 +2,12 @@ discard block |
||
| 2 | 2 | /** |
| 3 | 3 | * Base class for lexers |
| 4 | 4 | */ |
| 5 | -abstract class AntlrLexer extends BaseRecognizer{ |
|
| 5 | +abstract class AntlrLexer extends BaseRecognizer { |
|
| 6 | 6 | public static $DEFAULT_TOKEN_CHANNEL = 0; |
| 7 | 7 | protected $input; |
| 8 | 8 | |
| 9 | - public function __construct($input, &$state=null) { |
|
| 10 | - if($state==null){ |
|
| 9 | + public function __construct($input, &$state = null) { |
|
| 10 | + if ($state == null) { |
|
| 11 | 11 | $state = new RecognizerSharedState(); |
| 12 | 12 | } |
| 13 | 13 | $this->state = $state; |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | public function reset() { |
| 18 | 18 | parent::reset(); // reset all recognizer state variables |
| 19 | 19 | // wack Lexer state variables |
| 20 | - if ( $this->input!=null ) { |
|
| 20 | + if ($this->input != null) { |
|
| 21 | 21 | $this->input->seek(0); // rewind the input |
| 22 | 22 | } |
| 23 | - if ( $this->state==null ) { |
|
| 23 | + if ($this->state == null) { |
|
| 24 | 24 | return; // no shared state work to do |
| 25 | 25 | } |
| 26 | 26 | $this->state->token = null; |
@@ -39,20 +39,20 @@ discard block |
||
| 39 | 39 | public function nextToken() { |
| 40 | 40 | while (true) { |
| 41 | 41 | $this->state->token = null; |
| 42 | - $this->state->channel = 0;//Token::DEFAULT_CHANNEL; |
|
| 42 | + $this->state->channel = 0; //Token::DEFAULT_CHANNEL; |
|
| 43 | 43 | $this->state->tokenStartCharIndex = $this->input->index(); |
| 44 | 44 | $this->state->tokenStartCharPositionInLine = $this->input->getCharPositionInLine(); |
| 45 | 45 | $this->state->tokenStartLine = $this->input->getLine(); |
| 46 | 46 | $this->state->text = null; |
| 47 | - if ( $this->input->LA(1)==CharStreamConst::$EOF ) { |
|
| 47 | + if ($this->input->LA(1) == CharStreamConst::$EOF) { |
|
| 48 | 48 | return TokenConst::$EOF_TOKEN; |
| 49 | 49 | } |
| 50 | 50 | try { |
| 51 | 51 | $this->mTokens(); |
| 52 | - if ( $this->state->token==null ) { |
|
| 52 | + if ($this->state->token == null) { |
|
| 53 | 53 | $this->emit(); |
| 54 | 54 | } |
| 55 | - else if ( $this->state->token==Token::$SKIP_TOKEN ) { |
|
| 55 | + else if ($this->state->token == Token::$SKIP_TOKEN) { |
|
| 56 | 56 | continue; |
| 57 | 57 | } |
| 58 | 58 | return $this->state->token; |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | * If you are building trees, then you should also override |
| 111 | 111 | * Parser or TreeParser.getMissingSymbol(). |
| 112 | 112 | */ |
| 113 | - public function emit($token=null) { |
|
| 114 | - if($token==null){ |
|
| 113 | + public function emit($token = null) { |
|
| 114 | + if ($token == null) { |
|
| 115 | 115 | $token = CommonToken::forInput($this->input, $this->state->type, $this->state->channel, |
| 116 | - $this->state->tokenStartCharIndex, $this->getCharIndex()-1); |
|
| 116 | + $this->state->tokenStartCharIndex, $this->getCharIndex() - 1); |
|
| 117 | 117 | $token->setLine($this->state->tokenStartLine); |
| 118 | 118 | $token->setText($this->state->text); |
| 119 | 119 | $token->setCharPositionInLine($this->state->tokenStartCharPositionInLine); |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | return $token; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function matchString($s){ |
|
| 125 | + public function matchString($s) { |
|
| 126 | 126 | $i = 0; |
| 127 | - while ( $i<strlen($s)) { |
|
| 128 | - if ( $this->input->LA(1)!=charAt($s, $i) ) { |
|
| 129 | - if ( $this->state->backtracking>0 ) { |
|
| 127 | + while ($i < strlen($s)) { |
|
| 128 | + if ($this->input->LA(1) != charAt($s, $i)) { |
|
| 129 | + if ($this->state->backtracking > 0) { |
|
| 130 | 130 | $this->state->failed = true; |
| 131 | 131 | return; |
| 132 | 132 | } |
@@ -140,18 +140,18 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - public function matchAny($x=null) { |
|
| 143 | + public function matchAny($x = null) { |
|
| 144 | 144 | $this->input->consume(); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | public function matchChar($c) { |
| 148 | - if ($this->input->LA(1)!=$c ) { |
|
| 149 | - if ( $this->state->backtracking>0 ) { |
|
| 148 | + if ($this->input->LA(1) != $c) { |
|
| 149 | + if ($this->state->backtracking > 0) { |
|
| 150 | 150 | $this->state->failed = true; |
| 151 | 151 | return; |
| 152 | 152 | } |
| 153 | 153 | $mte = new MismatchedTokenException($c, $this->input); |
| 154 | - $this->recover($mte); // don't really recover; just consume in lexer |
|
| 154 | + $this->recover($mte); // don't really recover; just consume in lexer |
|
| 155 | 155 | throw $mte; |
| 156 | 156 | } |
| 157 | 157 | $this->input->consume(); |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | public function matchRange($a, $b) { |
| 162 | - if ( $this->input->LA(1)<$a || $this->input->LA(1)>$b ) { |
|
| 163 | - if ( $this->state->backtracking>0 ) { |
|
| 162 | + if ($this->input->LA(1) < $a || $this->input->LA(1) > $b) { |
|
| 163 | + if ($this->state->backtracking > 0) { |
|
| 164 | 164 | $this->state->failed = true; |
| 165 | 165 | return; |
| 166 | 166 | } |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | * text override. |
| 191 | 191 | */ |
| 192 | 192 | public function getText() { |
| 193 | - if ( $this->state->text!=null ) { |
|
| 193 | + if ($this->state->text != null) { |
|
| 194 | 194 | return $this->state->text; |
| 195 | 195 | } |
| 196 | - return $this->input->substring($this->state->tokenStartCharIndex,$this->getCharIndex()-1); |
|
| 196 | + return $this->input->substring($this->state->tokenStartCharIndex, $this->getCharIndex() - 1); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** Set the complete text of this token; it wipes any previous |
@@ -220,35 +220,35 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | public function getErrorMessage($e, $tokenNames) { |
| 222 | 222 | $msg = null; |
| 223 | - if ( $e instanceof MismatchedTokenException ) { |
|
| 223 | + if ($e instanceof MismatchedTokenException) { |
|
| 224 | 224 | $mte = $e; |
| 225 | - $msg = "mismatched character ".$this->getCharErrorDisplay($e->c). |
|
| 226 | - " expecting ".$this->getCharErrorDisplay($mte->expecting); |
|
| 225 | + $msg = "mismatched character " . $this->getCharErrorDisplay($e->c) . |
|
| 226 | + " expecting " . $this->getCharErrorDisplay($mte->expecting); |
|
| 227 | 227 | } |
| 228 | - else if ( $e instanceof NoViableAltException ) { |
|
| 228 | + else if ($e instanceof NoViableAltException) { |
|
| 229 | 229 | $nvae = $e; |
| 230 | 230 | // for development, can add "decision=<<"+nvae.grammarDecisionDescription+">>" |
| 231 | 231 | // and "(decision="+nvae.decisionNumber+") and |
| 232 | 232 | // "state "+nvae.stateNumber |
| 233 | - $msg = "no viable alternative at character ".$this->getCharErrorDisplay($e->c); |
|
| 233 | + $msg = "no viable alternative at character " . $this->getCharErrorDisplay($e->c); |
|
| 234 | 234 | } |
| 235 | - else if ( $e instanceof EarlyExitException ) { |
|
| 235 | + else if ($e instanceof EarlyExitException) { |
|
| 236 | 236 | $eee = $e; |
| 237 | 237 | // for development, can add "(decision="+eee.decisionNumber+")" |
| 238 | - $msg = "required (...)+ loop did not match anything at character ".$this->getCharErrorDisplay($e->c); |
|
| 238 | + $msg = "required (...)+ loop did not match anything at character " . $this->getCharErrorDisplay($e->c); |
|
| 239 | 239 | } |
| 240 | - else if ( $e instanceof MismatchedNotSetException ) { |
|
| 240 | + else if ($e instanceof MismatchedNotSetException) { |
|
| 241 | 241 | $mse = $e; |
| 242 | - $msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ".$mse->expecting; |
|
| 242 | + $msg = "mismatched character " . $this->getCharErrorDisplay($e->c) . " expecting set " . $mse->expecting; |
|
| 243 | 243 | } |
| 244 | - else if ( $e instanceof MismatchedSetException ) { |
|
| 244 | + else if ($e instanceof MismatchedSetException) { |
|
| 245 | 245 | $mse = $e; |
| 246 | - $msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ".$mse->expecting; |
|
| 246 | + $msg = "mismatched character " . $this->getCharErrorDisplay($e->c) . " expecting set " . $mse->expecting; |
|
| 247 | 247 | } |
| 248 | - else if ( $e instanceof MismatchedRangeException ) { |
|
| 248 | + else if ($e instanceof MismatchedRangeException) { |
|
| 249 | 249 | $mre = $e; |
| 250 | - $msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ". |
|
| 251 | - $this->getCharErrorDisplay($mre->a)."..".$this->getCharErrorDisplay($mre->b); |
|
| 250 | + $msg = "mismatched character " . $this->getCharErrorDisplay($e->c) . " expecting set " . |
|
| 251 | + $this->getCharErrorDisplay($mre->a) . ".." . $this->getCharErrorDisplay($mre->b); |
|
| 252 | 252 | } |
| 253 | 253 | else { |
| 254 | 254 | $msg = parent::getErrorMessage($e, $tokenNames); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | public function getCharErrorDisplay($c) { |
| 260 | 260 | $s = chr($c); |
| 261 | - switch ( $s ) { |
|
| 261 | + switch ($s) { |
|
| 262 | 262 | case '\n' : |
| 263 | 263 | $s = "\\n"; |
| 264 | 264 | break; |
@@ -269,10 +269,10 @@ discard block |
||
| 269 | 269 | $s = "\\r"; |
| 270 | 270 | break; |
| 271 | 271 | } |
| 272 | - if ($c==TokenConst::$EOF){ |
|
| 272 | + if ($c == TokenConst::$EOF) { |
|
| 273 | 273 | $s = "<EOF>"; |
| 274 | 274 | } |
| 275 | - return "'".$s."'"; |
|
| 275 | + return "'" . $s . "'"; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** Lexers can normally match any char in it's vocabulary after matching |
@@ -280,18 +280,18 @@ discard block |
||
| 280 | 280 | * it all works out. You can instead use the rule invocation stack |
| 281 | 281 | * to do sophisticated error recovery if you are in a fragment rule. |
| 282 | 282 | */ |
| 283 | - public function recover($re, $input=null) { |
|
| 283 | + public function recover($re, $input = null) { |
|
| 284 | 284 | $this->input->consume(); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
| 288 | - public function traceIn($ruleName, $ruleIndex, $inputSymbol=null) { |
|
| 289 | - $inputSymbol = $this->input->LT(1)." line=".$this->getLine().":".$this->getCharPositionInLine(); |
|
| 288 | + public function traceIn($ruleName, $ruleIndex, $inputSymbol = null) { |
|
| 289 | + $inputSymbol = $this->input->LT(1) . " line=" . $this->getLine() . ":" . $this->getCharPositionInLine(); |
|
| 290 | 290 | parent::traceIn($ruleName, $ruleIndex, $inputSymbol); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - public function traceOut($ruleName, $ruleIndex, $inputSymbol=null) { |
|
| 294 | - $inputSymbol = $this->input->LT(1)." line=".$this->getLine().":".$this->getCharPositionInLine(); |
|
| 293 | + public function traceOut($ruleName, $ruleIndex, $inputSymbol = null) { |
|
| 294 | + $inputSymbol = $this->input->LT(1) . " line=" . $this->getLine() . ":" . $this->getCharPositionInLine(); |
|
| 295 | 295 | parent::traceOut($ruleName, $ruleIndex, $inputSymbol); |
| 296 | 296 | } |
| 297 | 297 | } |
@@ -51,17 +51,14 @@ discard block |
||
| 51 | 51 | $this->mTokens(); |
| 52 | 52 | if ( $this->state->token==null ) { |
| 53 | 53 | $this->emit(); |
| 54 | - } |
|
| 55 | - else if ( $this->state->token==Token::$SKIP_TOKEN ) { |
|
| 54 | + } else if ( $this->state->token==Token::$SKIP_TOKEN ) { |
|
| 56 | 55 | continue; |
| 57 | 56 | } |
| 58 | 57 | return $this->state->token; |
| 59 | - } |
|
| 60 | - catch (NoViableAltException $nva) { |
|
| 58 | + } catch (NoViableAltException $nva) { |
|
| 61 | 59 | $this->reportError($nva); |
| 62 | 60 | $this->recover($nva); // throw out current char and try again |
| 63 | - } |
|
| 64 | - catch (RecognitionException $re) { |
|
| 61 | + } catch (RecognitionException $re) { |
|
| 65 | 62 | $this->reportError($re); |
| 66 | 63 | // match() routine has already called recover() |
| 67 | 64 | } |
@@ -224,33 +221,27 @@ discard block |
||
| 224 | 221 | $mte = $e; |
| 225 | 222 | $msg = "mismatched character ".$this->getCharErrorDisplay($e->c). |
| 226 | 223 | " expecting ".$this->getCharErrorDisplay($mte->expecting); |
| 227 | - } |
|
| 228 | - else if ( $e instanceof NoViableAltException ) { |
|
| 224 | + } else if ( $e instanceof NoViableAltException ) { |
|
| 229 | 225 | $nvae = $e; |
| 230 | 226 | // for development, can add "decision=<<"+nvae.grammarDecisionDescription+">>" |
| 231 | 227 | // and "(decision="+nvae.decisionNumber+") and |
| 232 | 228 | // "state "+nvae.stateNumber |
| 233 | 229 | $msg = "no viable alternative at character ".$this->getCharErrorDisplay($e->c); |
| 234 | - } |
|
| 235 | - else if ( $e instanceof EarlyExitException ) { |
|
| 230 | + } else if ( $e instanceof EarlyExitException ) { |
|
| 236 | 231 | $eee = $e; |
| 237 | 232 | // for development, can add "(decision="+eee.decisionNumber+")" |
| 238 | 233 | $msg = "required (...)+ loop did not match anything at character ".$this->getCharErrorDisplay($e->c); |
| 239 | - } |
|
| 240 | - else if ( $e instanceof MismatchedNotSetException ) { |
|
| 234 | + } else if ( $e instanceof MismatchedNotSetException ) { |
|
| 241 | 235 | $mse = $e; |
| 242 | 236 | $msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ".$mse->expecting; |
| 243 | - } |
|
| 244 | - else if ( $e instanceof MismatchedSetException ) { |
|
| 237 | + } else if ( $e instanceof MismatchedSetException ) { |
|
| 245 | 238 | $mse = $e; |
| 246 | 239 | $msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ".$mse->expecting; |
| 247 | - } |
|
| 248 | - else if ( $e instanceof MismatchedRangeException ) { |
|
| 240 | + } else if ( $e instanceof MismatchedRangeException ) { |
|
| 249 | 241 | $mre = $e; |
| 250 | 242 | $msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ". |
| 251 | 243 | $this->getCharErrorDisplay($mre->a)."..".$this->getCharErrorDisplay($mre->b); |
| 252 | - } |
|
| 253 | - else { |
|
| 244 | + } else { |
|
| 254 | 245 | $msg = parent::getErrorMessage($e, $tokenNames); |
| 255 | 246 | } |
| 256 | 247 | return $msg; |
@@ -30,13 +30,13 @@ |
||
| 30 | 30 | /** A mismatched char or Token or tree node */ |
| 31 | 31 | class MismatchedTokenException extends RecognitionException { |
| 32 | 32 | |
| 33 | - public function __construct($expecting=0, $input=null) { |
|
| 33 | + public function __construct($expecting = 0, $input = null) { |
|
| 34 | 34 | parent::__construct($input); |
| 35 | 35 | $this->expecting = $expecting; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function __toString() { |
| 39 | - return "MismatchedTokenException(".$this->getUnexpectedType()."!=".$this->expecting.")"; |
|
| 39 | + return "MismatchedTokenException(" . $this->getUnexpectedType() . "!=" . $this->expecting . ")"; |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | ?> |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | |
| 31 | -class CharStreamConst{ |
|
| 31 | +class CharStreamConst { |
|
| 32 | 32 | public static $EOF = -1; |
| 33 | 33 | } |
| 34 | 34 | $CharStream_EOF = -1; |
@@ -41,11 +41,11 @@ |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function toString() { |
| 44 | - if ( $this->inserted!=null && $this->token!=null ) { |
|
| 45 | - return "MissingTokenException(inserted ".$this->inserted." at ".$this->token->getText()+")"; |
|
| 44 | + if ($this->inserted != null && $this->token != null) { |
|
| 45 | + return "MissingTokenException(inserted " . $this->inserted . " at " . $this->token->getText() + ")"; |
|
| 46 | 46 | } |
| 47 | - if ( $this->token!=null ) { |
|
| 48 | - return "MissingTokenException(at ".$token->getText().")"; |
|
| 47 | + if ($this->token != null) { |
|
| 48 | + return "MissingTokenException(at " . $token->getText() . ")"; |
|
| 49 | 49 | } |
| 50 | 50 | return "MissingTokenException"; |
| 51 | 51 | } |