aboutsummaryrefslogtreecommitdiffstats
path: root/Llk
diff options
context:
space:
mode:
authorMetalaka <matthieu.de.laubrie@gmail.com>2014-08-25 17:09:56 +0200
committerMetalaka <matthieu.de.laubrie@gmail.com>2015-08-13 16:30:40 +0200
commit9f50ab2e155e4a3e3072aa39c516daa32e293fb8 (patch)
tree0a014f8105bf087f0f502d503bec5a9aa93a3d56 /Llk
parent287851eef84b064f6213e9197b07f0e573c5da1a (diff)
downloadCompiler-9f50ab2e155e4a3e3072aa39c516daa32e293fb8.zip
Compiler-9f50ab2e155e4a3e3072aa39c516daa32e293fb8.tar.gz
Compiler-9f50ab2e155e4a3e3072aa39c516daa32e293fb8.tar.bz2
Add skipToken generation.
Skip token of the grammar should be used between token values instead of an hard-coded space. If present we use the skip token from the current namespace and then we generate a value according to his PCRE expression.
Diffstat (limited to 'Llk')
-rw-r--r--Llk/Sampler/Sampler.php41
1 files changed, 38 insertions, 3 deletions
diff --git a/Llk/Sampler/Sampler.php b/Llk/Sampler/Sampler.php
index c5e5cf2..d1aa6f0 100644
--- a/Llk/Sampler/Sampler.php
+++ b/Llk/Sampler/Sampler.php
@@ -92,6 +92,12 @@ abstract class Sampler
*/
protected $_currentNamespace = 'default';
+ /**
+ * Skip tokens AST.
+ *
+ * @var array
+ */
+ protected $_skipTokenAST = [];
/**
@@ -125,6 +131,31 @@ abstract class Sampler
}
/**
+ * Get the AST of the current namespace skip token.
+ *
+ * @return \Hoa\Compiler\Llk\TreeNode
+ */
+ protected function getSkipTokenAST()
+ {
+ if (!isset($this->_skipTokenAST[$this->_currentNamespace])) {
+ $token = new Compiler\Llk\Rule\Token(
+ -1,
+ 'skip',
+ null,
+ -1
+ );
+
+ $token->setRepresentation(
+ $this->_tokens[$this->_currentNamespace]['skip']
+ );
+
+ $this->_skipTokenAST[$this->_currentNamespace] = $token->getAST();
+ }
+
+ return $this->_skipTokenAST[$this->_currentNamespace];
+ }
+
+ /**
* Complete a token (namespace and representation).
* It returns the next namespace.
*
@@ -190,9 +221,13 @@ abstract class Sampler
$toNamespace = $this->completeToken($token);
$this->setCurrentNamespace($toNamespace);
- return $this->_tokenSampler->visit(
- $token->getAST()
- ) . ' '; // use skip token @TODO
+ $out = $this->_tokenSampler->visit($token->getAST());
+
+ if (isset($this->_tokens[$this->_currentNamespace]['skip'])) {
+ $out .= $this->_tokenSampler->visit($this->getSkipTokenAST());
+ }
+
+ return $out;
}
}