/** * @param string $src * @param array $options * @param int $line * * @throws ParserException * @throws LexerException * * @return mixed */ public function read($src, array $options = [], $line = 1) { $cursor = new Cursor($src, $line); $tokens = $this->lexer->tokenize($cursor); $stream = new Stream($tokens); $out = $this->parser->parse($stream, $options); $stream->close(); return $out; }
/** * @param Cursor $cursor * * @throws \Exception * * @return Stream */ public function tokenize(Cursor $cursor) { $stream = []; foreach (parent::tokenize($cursor) as $offset => $token) { if ($token->is(Token::TYPE_STRING | Token::TYPE_BACK_QUOTED)) { $line = $token->getLine(); $stream = array_merge($stream, $this->templateLexer->tokenize(new Cursor($token->getValue(), $line))); } else { $stream[] = $token; } } return $stream; }
/** * @When I lex the DSL: */ public function tokenize(PyStringNode $dsl) { $lexer = new Lexer($this->skipRules, $this->matchRules); $this->stream = $lexer->tokenize(new Cursor($dsl, 1)); }