LemonJS/parser_template/parser.y

94 lines
2.5 KiB
Plaintext
Raw Normal View History

2019-01-29 11:25:40 +00:00
%name Parser
%token_prefix TOKEN_
%left OR.
%left AND.
%right NOT.
%include {
// include something
}
%code {
var _result = {
error: false
};
var LemonJS = function(_input) {
_result = Object.create(null);
var parser = new Parser();
var lexer = new Lexer(_input);
var token;
var lexemes = [];
while (token = lexer.next()) {
2019-01-30 10:13:05 +00:00
switch(token.error){
case 0:
console.log("PARSE", token.lexeme);
parser.parse(parser["TOKEN_" + token.lexeme], token);
lexemes.push(token);
break;
2019-01-30 11:50:02 +00:00
case -2:
// end of search
// do nothing
break;
case -1:
// empty string or not found any lexemes
// do nothing
break;
2019-01-30 10:13:05 +00:00
case 1:
return {
success: false,
message: "Found unknown symbol on position",
error: 1,
token: token
};
case 2:
return {
success: false,
message: "Not found close quote",
error: 2,
token: token
};
case 3:
return {
success: false,
message: "Unexpected symbol in oid structure",
error: 3,
token: token
};
case 4:
return {
success: false,
message: "Not found close bracket for Oid",
error: 3,
token: token
};
2019-01-29 11:25:40 +00:00
}
2019-01-30 10:13:05 +00:00
if(_result.error) {
return {
success: false,
message: "Syntax error",
error: 0
}
2019-01-29 11:25:40 +00:00
}
}
parser.parse();
2019-01-30 10:13:05 +00:00
if (_result.root_node !== undefined) {
return {
success: true,
tree: _result.root_node,
lexemes: lexemes
};
} else {
return { success: false }
}
2019-01-29 11:25:40 +00:00
};
}
%syntax_error {
_result.error = "true";
console.log("Syntax error");
}
2019-01-30 11:50:02 +00:00
&&REPLACER{rules.y}&&