✨ parse identifiers as command arguments
This commit is contained in:
parent
d7dbbe4845
commit
2175363dbf
@ -35,7 +35,7 @@ class Juicescript {
|
|||||||
|
|
||||||
// ARGUMENT TYPES //
|
// ARGUMENT TYPES //
|
||||||
static argument_type = new Juicescript_helper_enum(
|
static argument_type = new Juicescript_helper_enum(
|
||||||
"VARIABLE", "LITERAL", "OPERATOR"
|
"VARIABLE", "LITERAL", "OPERATOR", "IDENTIFIER"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ class Juicescript_parser {
|
|||||||
this.next();
|
this.next();
|
||||||
|
|
||||||
// make sure next has valid type for an argument (also allow operators)
|
// 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
|
// ignore with error
|
||||||
this.error_token("expected argument, but got");
|
this.error_token("expected argument, but got");
|
||||||
continue;
|
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 //
|
// UNKNOWN //
|
||||||
throw "called parse_argument() on non-argument token";
|
throw "called parse_argument() on non-argument token";
|
||||||
}
|
}
|
||||||
@ -566,12 +573,14 @@ class Juicescript_parser {
|
|||||||
is_argument(token, options = {}){
|
is_argument(token, options = {}){
|
||||||
// SET DEFAULTS FOR OPTIONS //
|
// SET DEFAULTS FOR OPTIONS //
|
||||||
options.operator ??= false;
|
options.operator ??= false;
|
||||||
|
options.identifier ??= false;
|
||||||
|
|
||||||
|
|
||||||
// CHECK //
|
// CHECK //
|
||||||
return this.is_variable(token) ||
|
return this.is_variable(token) ||
|
||||||
(options.operator && this.is_operator(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);
|
]).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
|
HELPER: Add new command object with OPTIONS to current scope
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user