Skip to content

Loading…

Updating php port to latest #113

Merged
merged 1 commit into from

3 participants

@robertleeplummerjr

Getting better and better. Thanks for the insight Zach.

robertleeplummerjr Fixed unset and input methods, added a few options as well, fixed opt…
…ions transfer from jison.js wrapper
ab02e2a
@travisbot

This pull request passes (merged ab02e2a into bdc9422).

@zaach zaach merged commit 746a829 into zaach:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2012
  1. Fixed unset and input methods, added a few options as well, fixed opt…

    robertleeplummerjr committed
    …ions transfer from jison.js wrapper
Showing with 68 additions and 18 deletions.
  1. +3 −0 ports/php/jison.js
  2. +65 −18 ports/php/template.php
View
3 ports/php/jison.js
@@ -37,6 +37,7 @@ exec("jison " + process.argv[2], function(error) {
rules = rules.substring(1, rules.length - 1);
var conditions = Parser.parser.lexer.conditions;
+ var options = JSON.stringify(Parser.parser.lexer.options);
var parserPerformAction = Parser.parser.performAction.toString();
var lexerPerformAction = Parser.parser.lexer.performAction.toString();
@@ -126,6 +127,8 @@ exec("jison " + process.argv[2], function(error) {
.replace('"<@@RULES@@>"', 'array(' + rules + ')')
.replace('"<@@CONDITIONS@@>"', "json_decode('" + JSON.stringify(conditions) + "', true)")
+ .replace('"<@@OPTIONS@@>"', "json_decode('" + (options) + "', true)")
+
.replace('"<@@PARSER_PERFORM_ACTION@@>";', jsPerformActionToPhp(parserPerformAction))
.replace('"<@@LEXER_PERFORM_ACTION@@>";', jsPerformActionToPhp(lexerPerformAction));
View
83 ports/php/template.php
@@ -8,7 +8,7 @@ class Parser
var $productions_ = array();
var $table = array();
var $defaultActions = array();
- var $version = '0.3.6';
+ var $version = '0.3.12';
var $debug = false;
function __construct()
@@ -267,7 +267,12 @@ function parse($input)
var $yytext = "";
var $match = "";
var $matched = "";
- var $yyloc = array();
+ var $yyloc = array(
+ "first_line"=> 1,
+ "first_column"=> 0,
+ "last_line"=> 1,
+ "last_column"=> 0
+ );
var $conditionsStack = array();
var $conditionStackCount = 0;
var $rules = array();
@@ -277,6 +282,7 @@ function parse($input)
var $more;
var $_input;
var $options;
+ var $offset;
function setInput($input)
{
@@ -285,12 +291,15 @@ function setInput($input)
$this->yylineno = $this->yyleng = 0;
$this->yytext = $this->matched = $this->match = '';
$this->conditionStack = array('INITIAL');
- $this->yyloc = array(
- "first_line"=> 1,
- "first_column"=> 0,
- "last_line"=> 1,
- "last_column"=> 0
- );
+ $this->yyloc["first_line"] = 1;
+ $this->yyloc["first_column"] = 0;
+ $this->yyloc["last_line"] = 1;
+ $this->yyloc["last_column"] = 0;
+ if ($this->options->ranges) {
+ $this->yyloc['range'] = array(0,0);
+ }
+ $this->offset = 0;
+ return $this;
}
function input()
@@ -298,17 +307,52 @@ function input()
$ch = $this->_input[0];
$this->yytext .= $ch;
$this->yyleng++;
+ $this->offset++;
$this->match .= $ch;
$this->matched .= $ch;
- $lines = preg_match("/\n/", $ch);
- if (count($lines) > 0) $this->yylineno++;
- array_slice($this->_input, 1);
+ $lines = preg_match("/(?:\r\n?|\n).*/", $ch);
+ if (count($lines) > 0) {
+ $this->yylineno++;
+ $this->yyloc['last_line']++;
+ } else {
+ $this->yyloc['last_column']++;
+ }
+ if ($this->options->ranges) $this->yyloc['range'][1]++;
+
+ $this->_input = array_slice($this->_input, 1);
return $ch;
}
function unput($ch)
{
+ $len = strlen($ch);
+ $lines = explode("/(?:\r\n?|\n)/", $ch);
+ $linesCount = count($lines);
+
$this->_input = $ch . $this->_input;
+ $this->yytext = substr($this->yytext, 0, $len - 1);
+ //$this->yylen -= $len;
+ $this->offset -= $len;
+ $oldLines = explode("/(?:\r\n?|\n)/", $this->match);
+ $oldLinesCount = count($oldLines);
+ $this->match = substr($this->match, 0, strlen($this->match) - 1);
+ $this->matched = substr($this->matched, 0, strlen($this->matched) - 1);
+
+ if (($linesCount - 1) > 0) $this->yylineno -= $linesCount - 1;
+ $r = $this->yyloc['range'];
+ $oldLinesLength = (isset($oldLines[$oldLinesCount - $linesCount]) ? strlen($oldLines[$oldLinesCount - $linesCount]) : 0);
+
+ $this->yyloc["first_line"] = $this->yyloc["first_line"];
+ $this->yyloc["last_line"] = $this->yylineno + 1;
+ $this->yyloc["first_column"] = $this->yyloc['first_column'];
+ $this->yyloc["last_column"] = (empty($lines) ?
+ ($linesCount == $oldLinesCount ? $this->yyloc['first_column'] : 0) + $oldLinesLength :
+ $this->yyloc['first_column'] - $len);
+
+ if (isset($this->options->ranges)) {
+ $this->yyloc['range'] = array($r[0], $r[0] + $this->yyleng - $len);
+ }
+
return $this;
}
@@ -369,16 +413,19 @@ function next()
$matchCount = strlen($match[0]);
$lineCount = preg_match("/\n.*/", $match[0], $lines);
- if ($lineCount > 1) $this->yylineno += $lineCount;
- $this->yyloc = array(
- "first_line"=> $this->yyloc['last_line'],
- "last_line"=> $this->yylineno + 1,
- "first_column"=> $this->yyloc['last_column'],
- "last_column"=> $lines ? count($lines[$lineCount - 1]) - 1 : $this->yyloc['last_column'] + $matchCount
- );
+ $this->yylineno += $lineCount;
+ $this->yyloc["first_line"] = $this->yyloc['last_line'];
+ $this->yyloc["last_line"] = $this->yylineno + 1;
+ $this->yyloc["first_column"] = $this->yyloc['last_column'];
+ $this->yyloc["last_column"] = $lines ? count($lines[$lineCount - 1]) - 1 : $this->yyloc['last_column'] + $matchCount;
+
$this->yytext .= $match[0];
$this->match .= $match[0];
+ $this->matches = $match;
$this->yyleng = strlen($this->yytext);
+ if ($this->options.ranges) {
+ $this->yyloc['range'] = array($this->offset, $this->offset += $this->yyleng);
+ }
$this->more = false;
$this->_input = substr($this->_input, $matchCount, strlen($this->_input));
$this->matched .= $match[0];
Something went wrong with that request. Please try again.