Changeset View
Changeset View
Standalone View
Standalone View
externals/jsonlint/src/Seld/JsonLint/JsonParser.php
Show First 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | public function parse($input, $flags = 0) | ||||
'loc' => $yyloc, | 'loc' => $yyloc, | ||||
'expected' => $expected, | 'expected' => $expected, | ||||
)); | )); | ||||
} | } | ||||
// just recovered from another error | // just recovered from another error | ||||
if ($recovering == 3) { | if ($recovering == 3) { | ||||
if ($symbol == $EOF) { | if ($symbol == $EOF) { | ||||
throw new JsonLintParsingException($errStr ? $errStr : 'Parsing halted.'); | throw new JsonLintParsingException($errStr ?: 'Parsing halted.'); | ||||
} | } | ||||
// discard current lookahead and grab another | // discard current lookahead and grab another | ||||
$yyleng = $this->lexer->yyleng; | $yyleng = $this->lexer->yyleng; | ||||
$yytext = $this->lexer->yytext; | $yytext = $this->lexer->yytext; | ||||
$yylineno = $this->lexer->yylineno; | $yylineno = $this->lexer->yylineno; | ||||
$yyloc = $this->lexer->yylloc; | $yyloc = $this->lexer->yylloc; | ||||
$symbol = $this->lex(); | $symbol = $this->lex(); | ||||
} | } | ||||
// try to recover from error | // try to recover from error | ||||
while (true) { | while (true) { | ||||
// check for error recovery rule in this state | // check for error recovery rule in this state | ||||
if (array_key_exists($TERROR, $this->table[$state])) { | if (array_key_exists($TERROR, $this->table[$state])) { | ||||
break; | break; | ||||
} | } | ||||
if ($state == 0) { | if ($state == 0) { | ||||
throw new JsonLintParsingException($errStr ? $errStr : 'Parsing halted.'); | throw new JsonLintParsingException($errStr ?: 'Parsing halted.'); | ||||
} | } | ||||
$this->popStack(1); | $this->popStack(1); | ||||
$state = $this->stack[count($this->stack)-1]; | $state = $this->stack[count($this->stack)-1]; | ||||
} | } | ||||
$preErrorSymbol = $symbol; // save the lookahead token | $preErrorSymbol = $symbol; // save the lookahead token | ||||
$symbol = $TERROR; // insert generic error symbol as new lookahead | $symbol = $TERROR; // insert generic error symbol as new lookahead | ||||
$state = $this->stack[count($this->stack)-1]; | $state = $this->stack[count($this->stack)-1]; | ||||
Show All 29 Lines | public function parse($input, $flags = 0) | ||||
case 2: // reduce | case 2: // reduce | ||||
$len = $this->productions_[$action[1]][1]; | $len = $this->productions_[$action[1]][1]; | ||||
// perform semantic action | // perform semantic action | ||||
$yyval->token = $this->vstack[count($this->vstack) - $len]; // default to $$ = $1 | $yyval->token = $this->vstack[count($this->vstack) - $len]; // default to $$ = $1 | ||||
// default location, uses first token for firsts, last for lasts | // default location, uses first token for firsts, last for lasts | ||||
$yyval->store = array( // _$ = store | $yyval->store = array( // _$ = store | ||||
'first_line' => $this->lstack[count($this->lstack) - ($len ? $len : 1)]['first_line'], | 'first_line' => $this->lstack[count($this->lstack) - ($len ?: 1)]['first_line'], | ||||
'last_line' => $this->lstack[count($this->lstack) - 1]['last_line'], | 'last_line' => $this->lstack[count($this->lstack) - 1]['last_line'], | ||||
'first_column' => $this->lstack[count($this->lstack) - ($len ? $len : 1)]['first_column'], | 'first_column' => $this->lstack[count($this->lstack) - ($len ?: 1)]['first_column'], | ||||
'last_column' => $this->lstack[count($this->lstack) - 1]['last_column'], | 'last_column' => $this->lstack[count($this->lstack) - 1]['last_column'], | ||||
); | ); | ||||
$r = $this->performAction($yyval, $yytext, $yyleng, $yylineno, $action[1], $this->vstack, $this->lstack); | $r = $this->performAction($yyval, $yytext, $yyleng, $yylineno, $action[1], $this->vstack, $this->lstack); | ||||
if (!$r instanceof JsonLintUndefined) { | if (!$r instanceof JsonLintUndefined) { | ||||
return $r; | return $r; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | private function failOnBOM($input) | ||||
// UTF-8 ByteOrderMark sequence | // UTF-8 ByteOrderMark sequence | ||||
$bom = "\xEF\xBB\xBF"; | $bom = "\xEF\xBB\xBF"; | ||||
if (substr($input, 0, 3) === $bom) { | if (substr($input, 0, 3) === $bom) { | ||||
$this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array()); | $this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0