我已生成使用JISON
解析器:錯誤JISON
%lex
%x TEXT
%%
("Project"|"project") {return 'PROJECTCOMMAND';}
"-au" {return 'ADDUSER';}
"-n" {this.begin('TEXT'); return 'NAMEOPTION';}
"-k" {return 'KEYOPTION';}
"-desc" {return 'DESCRIPTION';}
("--add"|"-a") {return 'ADDOPTION';}
<TEXT>[[email protected]\.]+ {this.popState(); return 'TEXT';}
<INITIAL,TEXT>\s+ // Ignore white space...
/lex
%%
line :
PROJECTCOMMAND ADDUSER
{
//Project Command of add user
var res = new Object();
res.value = "addUser Project";
return res;
}
| PROJECTCOMMAND ADDOPTION
{
//Project Command with no arguments
var res = new Object();
res.value = "addProject";
return res;
}
| PROJECTCOMMAND ADDOPTION NAMEOPTION TEXT
{
//Project command with project name as argument
var res = new Object();
res.value = "addProject name";
res.name = $4;
return res;
}
以上工作正常,如果我給喜歡命令:
project -a
project -au
project -a -n abc
...
但是如果我在這樣的命令類型給出了錯誤:
project -a abcd
它引發錯誤。
同樣的方式,如果我給一個命令
project -a -n
錯誤:解決這個問題是寫所有可能的錯誤情況,但會被永遠不會結束,因爲作爲命令增加可能
Expecting 'TEXT' got `1'
的一種方式錯誤的情況也增加,反正我可以告訴解析器,如果它不滿足任何上述命令然後拋出一個常見錯誤?
由於提前