0
0

parse identifiers as command arguments

This commit is contained in:
DrMaxNix 2022-09-09 17:19:21 +02:00
parent d7dbbe4845
commit 2175363dbf
2 changed files with 19 additions and 3 deletions

View File

@ -35,7 +35,7 @@ class Juicescript {
// ARGUMENT TYPES //
static argument_type = new Juicescript_helper_enum(
"VARIABLE", "LITERAL", "OPERATOR"
"VARIABLE", "LITERAL", "OPERATOR", "IDENTIFIER"
);

View File

@ -259,7 +259,7 @@ class Juicescript_parser {
this.next();
// make sure next has valid type for an argument (also allow operators)
if(!this.is_argument(this.token, {operator: true})){
if(!this.is_argument(this.token, {operator: true, identifier: true})){
// ignore with error
this.error_token("expected argument, but got");
continue;
@ -304,6 +304,13 @@ class Juicescript_parser {
}
// IDENTIFIER? //
if(this.is_identifier(this.token)){
// return object
return {type: Juicescript.argument_type.IDENTIFIER, identifier: this.token.value};
}
// UNKNOWN //
throw "called parse_argument() on non-argument token";
}
@ -566,12 +573,14 @@ class Juicescript_parser {
is_argument(token, options = {}){
// SET DEFAULTS FOR OPTIONS //
options.operator ??= false;
options.identifier ??= false;
// CHECK //
return this.is_variable(token) ||
(options.operator && this.is_operator(token)) ||
this.is_literal(token);
this.is_literal(token) ||
(options.identifier && this.is_identifier(token));
}
/*
@ -611,6 +620,13 @@ class Juicescript_parser {
]).includes(token.type);
}
/*
HELPER: Check if TOKEN is an identifier
*/
is_identifier(token){
return (token.type === Juicescript.token_type.IDENTIFIER);
}
/*
HELPER: Add new command object with OPTIONS to current scope
*/