Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit f9ac3b9

Browse files
committed
Add offset support
1 parent c86ccfb commit f9ac3b9

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

Llk/Parser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,11 @@ protected function _parse(Rule $zeRule, $next)
325325
}
326326

327327
$namespace = $this->_tokenSequence->current()['namespace'];
328+
$offset = $this->_tokenSequence->current()['offset'];
329+
328330
$zzeRule = clone $zeRule;
329331
$zzeRule->setValue($value);
332+
$zzeRule->setOffset($offset);
330333
$zzeRule->setNamespace($namespace);
331334

332335
if (isset($this->_tokens[$namespace][$name])) {
@@ -595,7 +598,9 @@ protected function _buildTree($i = 0, &$children = [])
595598
'token' => $trace->getTokenName(),
596599
'value' => $trace->getValue(),
597600
'namespace' => $trace->getNamespace(),
601+
'offset' => $trace->getOffset()
598602
]);
603+
599604
$children[] = $child;
600605
++$i;
601606
}

Llk/Rule/Token.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ class Token extends Rule
105105
*/
106106
protected $_unification = -1;
107107

108-
108+
/**
109+
* Token offset.
110+
*
111+
* @var int
112+
*/
113+
protected $_offset = 0;
109114

110115
/**
111116
* Constructor.
@@ -237,6 +242,27 @@ public function getValue()
237242
return $this->_value;
238243
}
239244

245+
/**
246+
* Set token offset.
247+
*
248+
* @param int $offset
249+
* @return void
250+
*/
251+
public function setOffset($offset)
252+
{
253+
$this->_offset = $offset;
254+
}
255+
256+
/**
257+
* Get token offset.
258+
*
259+
* @return int
260+
*/
261+
public function getOffset()
262+
{
263+
return $this->_offset;
264+
}
265+
240266
/**
241267
* Set whether the token is kept or not in the AST.
242268
*

Llk/TreeNode.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ public function getValueToken()
175175
: null;
176176
}
177177

178+
/**
179+
* Get token offset.
180+
*
181+
* @return int
182+
*/
183+
public function getOffset()
184+
{
185+
return
186+
isset($this->_value['offset'])
187+
? $this->_value['offset']
188+
: 0;
189+
}
190+
178191
/**
179192
* Get value value.
180193
*

0 commit comments

Comments
 (0)