我正在尝试使用 Jison。
这是我的语法:
var grammar = {
lex:{
rules:[
["\\s+", ""],
["then", "return 'newline';"],
["goto", "return 'goto';"],
["http[^\\s]*", "return 'url';"],
["search", "return 'search';"],
["should_exist", "return 'exist';"],
//["#(.)*", "return 'elementById';"],
//["$", "return 'EOF';"]
]
},
bnf:{
lines:[
['lines line', "console.log('big expression is ',$3); return ['l2',$1, $2];"],
['line', "console.log('expression is ',$1); return ['l1',$1]"],
],
line:[
["line newline", "console.log('line newline', $1); $$ = $1"],
["goto url", "console.log('goto', $2); $$ = {cmd:'goto', url: $2 } "],
["elementById exist", "$$ = {cmd:'assert', elId: $1} "]
]
}
};
当我尝试解析时,goto http://www.google.com then goto http://www.bing.com
我只会被[ 'l1', { cmd: 'goto', url: 'http://www.google.com' } ]
返回。
我期望同时返回两个 goto 命令。
对我弄清楚我的语法有什么帮助吗?