Javascript 可以在JS代码中以编程方式设置Jison解析器的状态吗?

Javascript 可以在JS代码中以编程方式设置Jison解析器的状态吗?,javascript,node.js,parsing,state,jison,Javascript,Node.js,Parsing,State,Jison,我正在用JS编写一个脚本,它使用Jison()作为解析器生成器;我在它的文档中找不到如下内容: // index.js - the script using the jison parser let myParser = require('/path/to/parser').parser; // some logic here to determine what the state should be myParser.setState('someState'); myParser.

我正在用JS编写一个脚本,它使用Jison()作为解析器生成器;我在它的文档中找不到如下内容:

// index.js - the script using the jison parser 

let myParser = require('/path/to/parser').parser; 

// some logic here to determine what the state should be 

myParser.setState('someState');
myParser.parser('someInput'); 
myParser.popState(); 

// etc.
我有一些逻辑来清理来自服务器的响应,并在将输出发送到解析器之前确定有关该输出的一些信息。是否可以在
.jison
文件本身之外设置解析器的状态

谢谢


编辑:在下面添加更多信息:

我注意到在Jison生成的代码中,导出的解析器函数/对象有一个
lexer
字段。lexer有方法
pushState()
popState()
。我试着调用它,但我得到以下错误:

例如:

let myParser = require('/path/to/parser').parser; 

myParser.lexer.pushState('someState');
myParser.parse('someInput');
myParser.lexer.popState();
输出:

node index.js
C:\path\to\my\script\TheParser.js:608
        this.conditionStack.push(condition);
                            ^

TypeError: Cannot read property 'push' of undefined

在lexer初始化之前,不能使用
begin
/
pushState
,这是在调用其
setInput
方法时发生的。我想您可以自己调用该方法,尽管解析器无论如何都会再次调用它。

这很有意义-谢谢您的帮助。我想出了一种方法来解析我需要的东西,而不需要提前设置状态;下次我尝试这样的解决方案时,我会记住这一点!