diff --git a/src/main.js b/src/main.js index 3508be3..ea0af12 100644 --- a/src/main.js +++ b/src/main.js @@ -35,7 +35,7 @@ class Juicescript { // ARGUMENT TYPES // static argument_type = new Juicescript_helper_enum( - "VARIABLE", "LITERAL", "OPERATOR" + "VARIABLE", "LITERAL", "OPERATOR", "IDENTIFIER" ); diff --git a/src/parser.js b/src/parser.js index 9c81b8f..a0cc783 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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 */