aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerafim <nesk@xakep.ru>2017-10-25 02:46:57 +0300
committerSerafim <nesk@xakep.ru>2017-10-25 02:46:57 +0300
commitf9ac3b9e2e6a5621ccba2063a545eef4958cd661 (patch)
tree444aa29ae6930300bac0787f48d584aae9110ae8
parentc86ccfbce9b9cad17cf84ffdf5c505c695d83d7a (diff)
downloadCompiler-f9ac3b9e2e6a5621ccba2063a545eef4958cd661.zip
Compiler-f9ac3b9e2e6a5621ccba2063a545eef4958cd661.tar.gz
Compiler-f9ac3b9e2e6a5621ccba2063a545eef4958cd661.tar.bz2
Add offset support
-rw-r--r--Llk/Parser.php5
-rw-r--r--Llk/Rule/Token.php28
-rw-r--r--Llk/TreeNode.php13
3 files changed, 45 insertions, 1 deletions
diff --git a/Llk/Parser.php b/Llk/Parser.php
index e8a4dfe..d827cbf 100644
--- a/Llk/Parser.php
+++ b/Llk/Parser.php
@@ -325,8 +325,11 @@ class Parser
}
$namespace = $this->_tokenSequence->current()['namespace'];
+ $offset = $this->_tokenSequence->current()['offset'];
+
$zzeRule = clone $zeRule;
$zzeRule->setValue($value);
+ $zzeRule->setOffset($offset);
$zzeRule->setNamespace($namespace);
if (isset($this->_tokens[$namespace][$name])) {
@@ -595,7 +598,9 @@ class Parser
'token' => $trace->getTokenName(),
'value' => $trace->getValue(),
'namespace' => $trace->getNamespace(),
+ 'offset' => $trace->getOffset()
]);
+
$children[] = $child;
++$i;
}
diff --git a/Llk/Rule/Token.php b/Llk/Rule/Token.php
index a0a23b4..8b7ae6f 100644
--- a/Llk/Rule/Token.php
+++ b/Llk/Rule/Token.php
@@ -105,7 +105,12 @@ class Token extends Rule
*/
protected $_unification = -1;
-
+ /**
+ * Token offset.
+ *
+ * @var int
+ */
+ protected $_offset = 0;
/**
* Constructor.
@@ -238,6 +243,27 @@ class Token extends Rule
}
/**
+ * Set token offset.
+ *
+ * @param int $offset
+ * @return void
+ */
+ public function setOffset($offset)
+ {
+ $this->_offset = $offset;
+ }
+
+ /**
+ * Get token offset.
+ *
+ * @return int
+ */
+ public function getOffset()
+ {
+ return $this->_offset;
+ }
+
+ /**
* Set whether the token is kept or not in the AST.
*
* @param bool $kept Kept.
diff --git a/Llk/TreeNode.php b/Llk/TreeNode.php
index 1cfb7fa..cd29f2e 100644
--- a/Llk/TreeNode.php
+++ b/Llk/TreeNode.php
@@ -176,6 +176,19 @@ class TreeNode implements Visitor\Element
}
/**
+ * Get token offset.
+ *
+ * @return int
+ */
+ public function getOffset()
+ {
+ return
+ isset($this->_value['offset'])
+ ? $this->_value['offset']
+ : 0;
+ }
+
+ /**
* Get value value.
*
* @return string