So I have generated a parser using 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>[-a-zA-Z0-9@\.]+ {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;
}
Is there any way I can do validations on command, i.e. If command does not satisfy any of above rules then throw a error, .i.e. having a default option.
Something like this at end of parser:
| return "command is invalid";
Thanks in Advance