Allow some of FutureReservedWords in non-strict mode
This commit is contained in:
+116
-53
@@ -145,6 +145,43 @@ current_token_equals_to_lp (lp_string str)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static token
|
||||||
|
convert_current_token_to_token (token_type tt)
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (token_start);
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < STACK_SIZE (strings); i++)
|
||||||
|
{
|
||||||
|
if (current_token_equals_to_lp (STACK_ELEMENT (strings, i)))
|
||||||
|
{
|
||||||
|
if (tt == TOK_STRING)
|
||||||
|
{
|
||||||
|
// locus must point to the first '"'
|
||||||
|
return (token)
|
||||||
|
{
|
||||||
|
.type = tt,
|
||||||
|
.loc = current_locus () - 1,
|
||||||
|
.uid = i
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return create_token (tt, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const lp_string str = (lp_string)
|
||||||
|
{
|
||||||
|
.length = (uint8_t) (buffer - token_start),
|
||||||
|
.str = (ecma_char_t *) token_start
|
||||||
|
};
|
||||||
|
|
||||||
|
STACK_PUSH (strings, str);
|
||||||
|
|
||||||
|
return create_token (tt, (idx_t) (STACK_SIZE (strings) - 1));
|
||||||
|
}
|
||||||
|
|
||||||
/* If TOKEN represents a keyword, return decoded keyword,
|
/* If TOKEN represents a keyword, return decoded keyword,
|
||||||
if TOKEN represents a Future Reserved Word, return KW_RESERVED,
|
if TOKEN represents a Future Reserved Word, return KW_RESERVED,
|
||||||
otherwise return KW_NONE. */
|
otherwise return KW_NONE. */
|
||||||
@@ -165,11 +202,11 @@ decode_keyword (void)
|
|||||||
}
|
}
|
||||||
if (current_token_equals_to ("class"))
|
if (current_token_equals_to ("class"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
PARSE_SORRY ("'class' is reseved keyword and not supported yet", current_locus ());
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("const"))
|
if (current_token_equals_to ("const"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
PARSE_SORRY ("'const' is reseved keyword and not supported yet", current_locus ());
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("continue"))
|
if (current_token_equals_to ("continue"))
|
||||||
{
|
{
|
||||||
@@ -197,15 +234,15 @@ decode_keyword (void)
|
|||||||
}
|
}
|
||||||
if (current_token_equals_to ("enum"))
|
if (current_token_equals_to ("enum"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
PARSE_SORRY ("'enum' is reseved keyword and not supported yet", current_locus ());
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("export"))
|
if (current_token_equals_to ("export"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
PARSE_SORRY ("'export' is reseved keyword and not supported yet", current_locus ());
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("extends"))
|
if (current_token_equals_to ("extends"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
PARSE_SORRY ("'extends' is reseved keyword and not supported yet", current_locus ());
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("false"))
|
if (current_token_equals_to ("false"))
|
||||||
{
|
{
|
||||||
@@ -233,7 +270,14 @@ decode_keyword (void)
|
|||||||
}
|
}
|
||||||
if (current_token_equals_to ("interface"))
|
if (current_token_equals_to ("interface"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'interface' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("in"))
|
if (current_token_equals_to ("in"))
|
||||||
{
|
{
|
||||||
@@ -241,15 +285,29 @@ decode_keyword (void)
|
|||||||
}
|
}
|
||||||
if (current_token_equals_to ("import"))
|
if (current_token_equals_to ("import"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
PARSE_SORRY ("'import' is reseved keyword and not supported yet", current_locus ());
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("implements"))
|
if (current_token_equals_to ("implements"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'implements' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("let"))
|
if (current_token_equals_to ("let"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'let' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("new"))
|
if (current_token_equals_to ("new"))
|
||||||
{
|
{
|
||||||
@@ -261,19 +319,47 @@ decode_keyword (void)
|
|||||||
}
|
}
|
||||||
if (current_token_equals_to ("package"))
|
if (current_token_equals_to ("package"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'package' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("private"))
|
if (current_token_equals_to ("private"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'private' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("protected"))
|
if (current_token_equals_to ("protected"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'protected' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("public"))
|
if (current_token_equals_to ("public"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'public' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("return"))
|
if (current_token_equals_to ("return"))
|
||||||
{
|
{
|
||||||
@@ -281,11 +367,18 @@ decode_keyword (void)
|
|||||||
}
|
}
|
||||||
if (current_token_equals_to ("static"))
|
if (current_token_equals_to ("static"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'static' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("super"))
|
if (current_token_equals_to ("super"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
PARSE_SORRY ("'super' is reseved keyword and not supported yet", current_locus ());
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("switch"))
|
if (current_token_equals_to ("switch"))
|
||||||
{
|
{
|
||||||
@@ -329,7 +422,14 @@ decode_keyword (void)
|
|||||||
}
|
}
|
||||||
if (current_token_equals_to ("yield"))
|
if (current_token_equals_to ("yield"))
|
||||||
{
|
{
|
||||||
return create_token (TOK_KEYWORD, KW_RESERVED);
|
if (parser_strict_mode ())
|
||||||
|
{
|
||||||
|
PARSE_ERROR ("'yield' is reseved keyword and not allowed in strict mode", current_locus ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convert_current_token_to_token (TOK_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_token_equals_to ("undefined"))
|
if (current_token_equals_to ("undefined"))
|
||||||
{
|
{
|
||||||
@@ -338,43 +438,6 @@ decode_keyword (void)
|
|||||||
return empty_token;
|
return empty_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
static token
|
|
||||||
convert_current_token_to_token (token_type tt)
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (token_start);
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < STACK_SIZE (strings); i++)
|
|
||||||
{
|
|
||||||
if (current_token_equals_to_lp (STACK_ELEMENT (strings, i)))
|
|
||||||
{
|
|
||||||
if (tt == TOK_STRING)
|
|
||||||
{
|
|
||||||
// locus must point to the first '"'
|
|
||||||
return (token)
|
|
||||||
{
|
|
||||||
.type = tt,
|
|
||||||
.loc = current_locus () - 1,
|
|
||||||
.uid = i
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return create_token (tt, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const lp_string str = (lp_string)
|
|
||||||
{
|
|
||||||
.length = (uint8_t) (buffer - token_start),
|
|
||||||
.str = (ecma_char_t *) token_start
|
|
||||||
};
|
|
||||||
|
|
||||||
STACK_PUSH (strings, str);
|
|
||||||
|
|
||||||
return create_token (tt, (idx_t) (STACK_SIZE (strings) - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
static token
|
static token
|
||||||
convert_seen_num_to_token (ecma_number_t num)
|
convert_seen_num_to_token (ecma_number_t num)
|
||||||
{
|
{
|
||||||
|
|||||||
+95
-93
@@ -21,118 +21,120 @@
|
|||||||
#include "lp-string.h"
|
#include "lp-string.h"
|
||||||
|
|
||||||
/* Keywords. */
|
/* Keywords. */
|
||||||
typedef uint8_t keyword;
|
typedef enum
|
||||||
|
{
|
||||||
|
/* Not a keyword. */
|
||||||
|
KW_NONE = 0,
|
||||||
|
KW_BREAK,
|
||||||
|
KW_CASE,
|
||||||
|
KW_CATCH,
|
||||||
|
KW_CONTINUE,
|
||||||
|
|
||||||
/* Not a keyword. */
|
KW_DEBUGGER,
|
||||||
#define KW_NONE 0
|
KW_DEFAULT,
|
||||||
/* Future reserved keyword. */
|
KW_DELETE,
|
||||||
#define KW_RESERVED 1
|
KW_DO,
|
||||||
#define KW_BREAK 2
|
KW_ELSE,
|
||||||
#define KW_CASE 3
|
|
||||||
#define KW_CATCH 4
|
|
||||||
|
|
||||||
#define KW_CONTINUE 5
|
KW_FINALLY,
|
||||||
#define KW_DEBUGGER 6
|
KW_FOR,
|
||||||
#define KW_DEFAULT 7
|
KW_FUNCTION,
|
||||||
#define KW_DELETE 8
|
KW_IF,
|
||||||
#define KW_DO 9
|
KW_IN,
|
||||||
|
|
||||||
#define KW_ELSE 10
|
KW_INSTANCEOF,
|
||||||
#define KW_FINALLY 11
|
KW_NEW,
|
||||||
#define KW_FOR 12
|
KW_RETURN,
|
||||||
#define KW_FUNCTION 13
|
KW_SWITCH,
|
||||||
#define KW_IF 14
|
KW_THIS,
|
||||||
|
|
||||||
#define KW_IN 15
|
KW_THROW,
|
||||||
#define KW_INSTANCEOF 16
|
KW_TRY,
|
||||||
#define KW_NEW 17
|
KW_TYPEOF,
|
||||||
#define KW_RETURN 18
|
KW_VAR,
|
||||||
#define KW_SWITCH 19
|
KW_VOID,
|
||||||
|
|
||||||
#define KW_THIS 20
|
KW_WHILE,
|
||||||
#define KW_THROW 21
|
KW_WITH,
|
||||||
#define KW_TRY 22
|
}
|
||||||
#define KW_TYPEOF 23
|
keyword;
|
||||||
#define KW_VAR 24
|
|
||||||
|
|
||||||
#define KW_VOID 25
|
|
||||||
#define KW_WHILE 26
|
|
||||||
#define KW_WITH 27
|
|
||||||
|
|
||||||
|
|
||||||
/* Type of tokens. */
|
/* Type of tokens. */
|
||||||
typedef uint8_t token_type;
|
typedef enum
|
||||||
|
{
|
||||||
|
TOK_EOF = 0, // End of file
|
||||||
|
TOK_NAME, // Identifier
|
||||||
|
TOK_KEYWORD, // Keyword
|
||||||
|
TOK_SMALL_INT,
|
||||||
|
TOK_NUMBER,
|
||||||
|
|
||||||
#define TOK_EOF 0 // End of file
|
TOK_NULL,
|
||||||
#define TOK_NAME 1 // Identifier
|
TOK_BOOL,
|
||||||
#define TOK_KEYWORD 2 // Keyword
|
TOK_NEWLINE,
|
||||||
#define TOK_SMALL_INT 3
|
TOK_STRING,
|
||||||
#define TOK_NUMBER 4
|
TOK_OPEN_BRACE, // {
|
||||||
|
|
||||||
#define TOK_NULL 5
|
TOK_CLOSE_BRACE, // }
|
||||||
#define TOK_BOOL 6
|
TOK_OPEN_PAREN, // (
|
||||||
#define TOK_NEWLINE 7
|
TOK_CLOSE_PAREN, //)
|
||||||
#define TOK_STRING 8
|
TOK_OPEN_SQUARE, // [
|
||||||
#define TOK_OPEN_BRACE 9 // {
|
TOK_CLOSE_SQUARE, // [
|
||||||
|
|
||||||
#define TOK_CLOSE_BRACE 10 // }
|
TOK_DOT, // .
|
||||||
#define TOK_OPEN_PAREN 11 // (
|
TOK_SEMICOLON, // ;
|
||||||
#define TOK_CLOSE_PAREN 12 //)
|
TOK_COMMA, // ,
|
||||||
#define TOK_OPEN_SQUARE 13 // [
|
TOK_LESS, // <
|
||||||
#define TOK_CLOSE_SQUARE 14 // [
|
TOK_GREATER, // >
|
||||||
|
|
||||||
#define TOK_DOT 15 // .
|
TOK_LESS_EQ, // <=
|
||||||
#define TOK_SEMICOLON 16 // ;
|
TOK_GREATER_EQ, // <=
|
||||||
#define TOK_COMMA 17 // ,
|
TOK_DOUBLE_EQ, // ==
|
||||||
#define TOK_LESS 18 // <
|
TOK_NOT_EQ, // !=
|
||||||
#define TOK_GREATER 19 // >
|
TOK_TRIPLE_EQ, // ===
|
||||||
|
|
||||||
#define TOK_LESS_EQ 20 // <=
|
TOK_NOT_DOUBLE_EQ, // !==
|
||||||
#define TOK_GREATER_EQ 21 // <=
|
TOK_PLUS, // +
|
||||||
#define TOK_DOUBLE_EQ 22 // ==
|
TOK_MINUS, // -
|
||||||
#define TOK_NOT_EQ 23 // !=
|
TOK_MULT, // *
|
||||||
#define TOK_TRIPLE_EQ 24 // ===
|
TOK_MOD, // %
|
||||||
|
|
||||||
#define TOK_NOT_DOUBLE_EQ 25 // !==
|
TOK_DOUBLE_PLUS, // ++
|
||||||
#define TOK_PLUS 26 // +
|
TOK_DOUBLE_MINUS, // --
|
||||||
#define TOK_MINUS 27 // -
|
TOK_LSHIFT, // <<
|
||||||
#define TOK_MULT 28 // *
|
TOK_RSHIFT, // >>
|
||||||
#define TOK_MOD 29 // %
|
TOK_RSHIFT_EX, // >>>
|
||||||
|
|
||||||
#define TOK_DOUBLE_PLUS 30 // ++
|
TOK_AND, // &
|
||||||
#define TOK_DOUBLE_MINUS 31 // --
|
TOK_OR, // |
|
||||||
#define TOK_LSHIFT 32 // <<
|
TOK_XOR, // ^
|
||||||
#define TOK_RSHIFT 33 // >>
|
TOK_NOT, // !
|
||||||
#define TOK_RSHIFT_EX 34 // >>>
|
TOK_COMPL, // ~
|
||||||
|
|
||||||
#define TOK_AND 35 // &
|
TOK_DOUBLE_AND, // &&
|
||||||
#define TOK_OR 36 // |
|
TOK_DOUBLE_OR, // ||
|
||||||
#define TOK_XOR 37 // ^
|
TOK_QUERY, // ?
|
||||||
#define TOK_NOT 38 // !
|
TOK_COLON, // :
|
||||||
#define TOK_COMPL 39 // ~
|
TOK_EQ, // =
|
||||||
|
|
||||||
#define TOK_DOUBLE_AND 40 // &&
|
TOK_PLUS_EQ, // +=
|
||||||
#define TOK_DOUBLE_OR 41 // ||
|
TOK_MINUS_EQ, // -=
|
||||||
#define TOK_QUERY 42 // ?
|
TOK_MULT_EQ, // *=
|
||||||
#define TOK_COLON 43 // :
|
TOK_MOD_EQ, // %=
|
||||||
#define TOK_EQ 44 // =
|
TOK_LSHIFT_EQ, // <<=
|
||||||
|
|
||||||
#define TOK_PLUS_EQ 45 // +=
|
TOK_RSHIFT_EQ, // >>=
|
||||||
#define TOK_MINUS_EQ 46 // -=
|
TOK_RSHIFT_EX_EQ, // >>>=
|
||||||
#define TOK_MULT_EQ 47 // *=
|
TOK_AND_EQ, // &=
|
||||||
#define TOK_MOD_EQ 48 // %=
|
TOK_OR_EQ, // |=
|
||||||
#define TOK_LSHIFT_EQ 49 // <<=
|
TOK_XOR_EQ, // ^=
|
||||||
|
|
||||||
#define TOK_RSHIFT_EQ 50 // >>=
|
TOK_DIV, // /
|
||||||
#define TOK_RSHIFT_EX_EQ 51 // >>>=
|
TOK_DIV_EQ, // /=
|
||||||
#define TOK_AND_EQ 52 // &=
|
TOK_UNDEFINED, // undefined
|
||||||
#define TOK_OR_EQ 53 // |=
|
TOK_EMPTY,
|
||||||
#define TOK_XOR_EQ 54 // ^=
|
}
|
||||||
|
token_type;
|
||||||
#define TOK_DIV 55 // /
|
|
||||||
#define TOK_DIV_EQ 56 // /=
|
|
||||||
#define TOK_UNDEFINED 57 // undefined
|
|
||||||
#define TOK_EMPTY 58
|
|
||||||
|
|
||||||
typedef size_t locus;
|
typedef size_t locus;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user