1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci#ifndef JS_PARSER_H
17425bb815Sopenharmony_ci#define JS_PARSER_H
18425bb815Sopenharmony_ci
19425bb815Sopenharmony_ci#include "ecma-globals.h"
20425bb815Sopenharmony_ci
21425bb815Sopenharmony_ci/** \addtogroup parser Parser
22425bb815Sopenharmony_ci * @{
23425bb815Sopenharmony_ci *
24425bb815Sopenharmony_ci * \addtogroup jsparser JavaScript
25425bb815Sopenharmony_ci * @{
26425bb815Sopenharmony_ci *
27425bb815Sopenharmony_ci * \addtogroup jsparser_parser Parser
28425bb815Sopenharmony_ci * @{
29425bb815Sopenharmony_ci */
30425bb815Sopenharmony_ci
31425bb815Sopenharmony_ci/**
32425bb815Sopenharmony_ci * Error codes.
33425bb815Sopenharmony_ci */
34425bb815Sopenharmony_citypedef enum
35425bb815Sopenharmony_ci{
36425bb815Sopenharmony_ci  PARSER_ERR_NO_ERROR,                                /**< no error */
37425bb815Sopenharmony_ci
38425bb815Sopenharmony_ci  PARSER_ERR_OUT_OF_MEMORY,                           /**< out of memory */
39425bb815Sopenharmony_ci  PARSER_ERR_LITERAL_LIMIT_REACHED,                   /**< maximum number of literals reached */
40425bb815Sopenharmony_ci  PARSER_ERR_SCOPE_STACK_LIMIT_REACHED,               /**< maximum depth of scope stack reached */
41425bb815Sopenharmony_ci  PARSER_ERR_ARGUMENT_LIMIT_REACHED,                  /**< maximum number of function arguments reached */
42425bb815Sopenharmony_ci  PARSER_ERR_STACK_LIMIT_REACHED,                     /**< maximum function stack size reached */
43425bb815Sopenharmony_ci  PARSER_ERR_JERRY_STACK_LIMIT_REACHED,               /**< maximum jerry context stack limit reached */
44425bb815Sopenharmony_ci
45425bb815Sopenharmony_ci  PARSER_ERR_INVALID_CHARACTER,                       /**< unexpected character */
46425bb815Sopenharmony_ci  PARSER_ERR_INVALID_OCTAL_DIGIT,                     /**< invalid octal digit */
47425bb815Sopenharmony_ci  PARSER_ERR_INVALID_HEX_DIGIT,                       /**< invalid hexadecimal digit */
48425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
49425bb815Sopenharmony_ci  PARSER_ERR_INVALID_BIN_DIGIT,                       /**< invalid binary digit */
50425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
51425bb815Sopenharmony_ci  PARSER_ERR_INVALID_ESCAPE_SEQUENCE,                 /**< invalid escape sequence */
52425bb815Sopenharmony_ci  PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE,         /**< invalid unicode escape sequence */
53425bb815Sopenharmony_ci  PARSER_ERR_INVALID_IDENTIFIER_START,                /**< character cannot be start of an identifier */
54425bb815Sopenharmony_ci  PARSER_ERR_INVALID_IDENTIFIER_PART,                 /**< character cannot be part of an identifier */
55425bb815Sopenharmony_ci  PARSER_ERR_INVALID_KEYWORD,                         /**< escape sequences are not allowed in keywords */
56425bb815Sopenharmony_ci
57425bb815Sopenharmony_ci  PARSER_ERR_INVALID_NUMBER,                          /**< invalid number literal */
58425bb815Sopenharmony_ci  PARSER_ERR_MISSING_EXPONENT,                        /**< missing exponent */
59425bb815Sopenharmony_ci  PARSER_ERR_IDENTIFIER_AFTER_NUMBER,                 /**< identifier start after number */
60425bb815Sopenharmony_ci
61425bb815Sopenharmony_ci  PARSER_ERR_INVALID_REGEXP,                          /**< invalid regular expression */
62425bb815Sopenharmony_ci  PARSER_ERR_UNKNOWN_REGEXP_FLAG,                     /**< unknown regexp flag */
63425bb815Sopenharmony_ci  PARSER_ERR_DUPLICATED_REGEXP_FLAG,                  /**< duplicated regexp flag */
64425bb815Sopenharmony_ci  PARSER_ERR_UNSUPPORTED_REGEXP,                      /**< regular expression is not supported */
65425bb815Sopenharmony_ci
66425bb815Sopenharmony_ci  PARSER_ERR_IDENTIFIER_TOO_LONG,                     /**< too long identifier */
67425bb815Sopenharmony_ci  PARSER_ERR_STRING_TOO_LONG,                         /**< too long string literal */
68425bb815Sopenharmony_ci  PARSER_ERR_NUMBER_TOO_LONG,                         /**< too long number literal */
69425bb815Sopenharmony_ci  PARSER_ERR_REGEXP_TOO_LONG,                         /**< too long regexp literal */
70425bb815Sopenharmony_ci
71425bb815Sopenharmony_ci  PARSER_ERR_UNTERMINATED_MULTILINE_COMMENT,          /**< unterminated multiline comment */
72425bb815Sopenharmony_ci  PARSER_ERR_UNTERMINATED_STRING,                     /**< unterminated string literal */
73425bb815Sopenharmony_ci  PARSER_ERR_UNTERMINATED_REGEXP,                     /**< unterminated regexp literal */
74425bb815Sopenharmony_ci
75425bb815Sopenharmony_ci  PARSER_ERR_NEWLINE_NOT_ALLOWED,                     /**< newline is not allowed */
76425bb815Sopenharmony_ci  PARSER_ERR_OCTAL_NUMBER_NOT_ALLOWED,                /**< octal numbers are not allowed in strict mode */
77425bb815Sopenharmony_ci  PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED,                /**< octal escape sequences are not allowed in strict mode */
78425bb815Sopenharmony_ci  PARSER_ERR_STRICT_IDENT_NOT_ALLOWED,                /**< identifier name is reserved in strict mode */
79425bb815Sopenharmony_ci  PARSER_ERR_EVAL_NOT_ALLOWED,                        /**< eval is not allowed here in strict mode */
80425bb815Sopenharmony_ci  PARSER_ERR_ARGUMENTS_NOT_ALLOWED,                   /**< arguments is not allowed here in strict mode */
81425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
82425bb815Sopenharmony_ci  PARSER_ERR_USE_STRICT_NOT_ALLOWED,                  /**< use strict directive is not allowed */
83425bb815Sopenharmony_ci  PARSER_ERR_YIELD_NOT_ALLOWED,                       /**< yield expression is not allowed */
84425bb815Sopenharmony_ci  PARSER_ERR_AWAIT_NOT_ALLOWED,                       /**< await expression is not allowed */
85425bb815Sopenharmony_ci  PARSER_ERR_FOR_IN_OF_DECLARATION,                   /**< variable declaration in for-in or for-of loop */
86425bb815Sopenharmony_ci  PARSER_ERR_DUPLICATED_PROTO,                        /**< duplicated __proto__ fields are not allowed */
87425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
88425bb815Sopenharmony_ci  PARSER_ERR_DELETE_IDENT_NOT_ALLOWED,                /**< identifier delete is not allowed in strict mode */
89425bb815Sopenharmony_ci  PARSER_ERR_EVAL_CANNOT_ASSIGNED,                    /**< eval cannot be assigned in strict mode */
90425bb815Sopenharmony_ci  PARSER_ERR_ARGUMENTS_CANNOT_ASSIGNED,               /**< arguments cannot be assigned in strict mode */
91425bb815Sopenharmony_ci  PARSER_ERR_WITH_NOT_ALLOWED,                        /**< with statement is not allowed in strict mode */
92425bb815Sopenharmony_ci  PARSER_ERR_MULTIPLE_DEFAULTS_NOT_ALLOWED,           /**< multiple default cases are not allowed */
93425bb815Sopenharmony_ci  PARSER_ERR_DEFAULT_NOT_IN_SWITCH,                   /**< default statement is not in switch block */
94425bb815Sopenharmony_ci  PARSER_ERR_CASE_NOT_IN_SWITCH,                      /**< case statement is not in switch block */
95425bb815Sopenharmony_ci
96425bb815Sopenharmony_ci  PARSER_ERR_LEFT_PAREN_EXPECTED,                     /**< left paren expected */
97425bb815Sopenharmony_ci  PARSER_ERR_LEFT_BRACE_EXPECTED,                     /**< left brace expected */
98425bb815Sopenharmony_ci  PARSER_ERR_RIGHT_PAREN_EXPECTED,                    /**< right paren expected */
99425bb815Sopenharmony_ci  PARSER_ERR_RIGHT_SQUARE_EXPECTED,                   /**< right square expected */
100425bb815Sopenharmony_ci
101425bb815Sopenharmony_ci  PARSER_ERR_COLON_EXPECTED,                          /**< colon expected */
102425bb815Sopenharmony_ci  PARSER_ERR_COLON_FOR_CONDITIONAL_EXPECTED,          /**< colon expected for conditional expression */
103425bb815Sopenharmony_ci  PARSER_ERR_SEMICOLON_EXPECTED,                      /**< semicolon expected */
104425bb815Sopenharmony_ci  PARSER_ERR_IN_EXPECTED,                             /**< in keyword expected */
105425bb815Sopenharmony_ci  PARSER_ERR_WHILE_EXPECTED,                          /**< while expected for do-while loop */
106425bb815Sopenharmony_ci  PARSER_ERR_CATCH_FINALLY_EXPECTED,                  /**< catch or finally expected */
107425bb815Sopenharmony_ci  PARSER_ERR_ARRAY_ITEM_SEPARATOR_EXPECTED,           /**< array item separator expected */
108425bb815Sopenharmony_ci  PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED,          /**< object item separator expected */
109425bb815Sopenharmony_ci  PARSER_ERR_IDENTIFIER_EXPECTED,                     /**< identifier expected */
110425bb815Sopenharmony_ci  PARSER_ERR_EXPRESSION_EXPECTED,                     /**< expression expected */
111425bb815Sopenharmony_ci  PARSER_ERR_PRIMARY_EXP_EXPECTED,                    /**< primary expression expected */
112425bb815Sopenharmony_ci  PARSER_ERR_LEFT_HAND_SIDE_EXP_EXPECTED,             /**< left-hand-side expression expected */
113425bb815Sopenharmony_ci  PARSER_ERR_STATEMENT_EXPECTED,                      /**< statement expected */
114425bb815Sopenharmony_ci  PARSER_ERR_PROPERTY_IDENTIFIER_EXPECTED,            /**< property identifier expected */
115425bb815Sopenharmony_ci  PARSER_ERR_ARGUMENT_LIST_EXPECTED,                  /**< argument list expected */
116425bb815Sopenharmony_ci  PARSER_ERR_NO_ARGUMENTS_EXPECTED,                   /**< property getters must have no arguments */
117425bb815Sopenharmony_ci  PARSER_ERR_ONE_ARGUMENT_EXPECTED,                   /**< property setters must have one argument */
118425bb815Sopenharmony_ci
119425bb815Sopenharmony_ci  PARSER_ERR_INVALID_EXPRESSION,                      /**< invalid expression */
120425bb815Sopenharmony_ci  PARSER_ERR_INVALID_SWITCH,                          /**< invalid switch body */
121425bb815Sopenharmony_ci  PARSER_ERR_INVALID_BREAK,                           /**< break must be inside a loop or switch */
122425bb815Sopenharmony_ci  PARSER_ERR_INVALID_BREAK_LABEL,                     /**< break target not found */
123425bb815Sopenharmony_ci  PARSER_ERR_INVALID_CONTINUE,                        /**< continue must be inside a loop */
124425bb815Sopenharmony_ci  PARSER_ERR_INVALID_CONTINUE_LABEL,                  /**< continue target not found */
125425bb815Sopenharmony_ci  PARSER_ERR_INVALID_RETURN,                          /**< return must be inside a function */
126425bb815Sopenharmony_ci  PARSER_ERR_INVALID_RIGHT_SQUARE,                    /**< right square must terminate a block */
127425bb815Sopenharmony_ci  PARSER_ERR_DUPLICATED_LABEL,                        /**< duplicated label */
128425bb815Sopenharmony_ci  PARSER_ERR_OBJECT_PROPERTY_REDEFINED,               /**< property of object literal redefined */
129425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
130425bb815Sopenharmony_ci  PARSER_ERR_VARIABLE_REDECLARED,                     /**< a variable redeclared */
131425bb815Sopenharmony_ci  PARSER_ERR_LEXICAL_SINGLE_STATEMENT,                /**< lexical declaration in single statement context */
132425bb815Sopenharmony_ci  PARSER_ERR_LABELLED_FUNC_NOT_IN_BLOCK,              /**< labelled functions are only allowed inside blocks */
133425bb815Sopenharmony_ci  PARSER_ERR_LEXICAL_LET_BINDING,                     /**< let binding cannot be declared in let/const */
134425bb815Sopenharmony_ci  PARSER_ERR_MISSING_ASSIGN_AFTER_CONST,              /**< an assignment is required after a const declaration */
135425bb815Sopenharmony_ci
136425bb815Sopenharmony_ci  PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS,             /**< multiple class constructor */
137425bb815Sopenharmony_ci  PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR,           /**< class constructor cannot be an accessor */
138425bb815Sopenharmony_ci  PARSER_ERR_CLASS_CONSTRUCTOR_AS_GENERATOR,          /**< class constructor cannot be a generator */
139425bb815Sopenharmony_ci  PARSER_ERR_CLASS_STATIC_PROTOTYPE,                  /**< static method name 'prototype' is not allowed */
140425bb815Sopenharmony_ci  PARSER_ERR_UNEXPECTED_SUPER_KEYWORD,                /**< unexpected super keyword */
141425bb815Sopenharmony_ci
142425bb815Sopenharmony_ci  PARSER_ERR_RIGHT_BRACE_EXPECTED,                    /**< right brace expected */
143425bb815Sopenharmony_ci  PARSER_ERR_OF_EXPECTED,                             /**< of keyword expected */
144425bb815Sopenharmony_ci
145425bb815Sopenharmony_ci  PARSER_ERR_ASSIGNMENT_EXPECTED,                     /**< assignment expression expected */
146425bb815Sopenharmony_ci  PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER,       /**< formal parameter after rest parameter */
147425bb815Sopenharmony_ci  PARSER_ERR_SETTER_REST_PARAMETER,                   /**< setter rest parameter */
148425bb815Sopenharmony_ci  PARSER_ERR_REST_PARAMETER_DEFAULT_INITIALIZER,      /**< rest parameter default initializer */
149425bb815Sopenharmony_ci  PARSER_ERR_DUPLICATED_ARGUMENT_NAMES,               /**< duplicated argument names */
150425bb815Sopenharmony_ci  PARSER_ERR_INVALID_DESTRUCTURING_PATTERN,           /**< invalid destructuring pattern */
151425bb815Sopenharmony_ci  PARSER_ERR_ILLEGAL_PROPERTY_IN_DECLARATION,         /**< illegal property in declaration context */
152425bb815Sopenharmony_ci  PARSER_ERR_INVALID_EXPONENTIATION,                  /**< left operand of ** operator cannot be unary expression */
153425bb815Sopenharmony_ci  PARSER_ERR_NEW_TARGET_EXPECTED,                     /**< expected new.target expression */
154425bb815Sopenharmony_ci  PARSER_ERR_NEW_TARGET_NOT_ALLOWED,                  /**< new.target is not allowed in the given context */
155425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
156425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
157425bb815Sopenharmony_ci  PARSER_ERR_FILE_NOT_FOUND,                          /**< file not found*/
158425bb815Sopenharmony_ci  PARSER_ERR_FROM_EXPECTED,                           /**< from expected */
159425bb815Sopenharmony_ci  PARSER_ERR_FROM_COMMA_EXPECTED,                     /**< from or comma expected */
160425bb815Sopenharmony_ci  PARSER_ERR_AS_EXPECTED,                             /**< as expected */
161425bb815Sopenharmony_ci  PARSER_ERR_STRING_EXPECTED,                         /**< string literal expected */
162425bb815Sopenharmony_ci  PARSER_ERR_MODULE_UNEXPECTED,                       /**< unexpected import or export statement */
163425bb815Sopenharmony_ci  PARSER_ERR_LEFT_BRACE_MULTIPLY_LITERAL_EXPECTED,    /**< left brace or multiply or literal expected */
164425bb815Sopenharmony_ci  PARSER_ERR_LEFT_BRACE_MULTIPLY_EXPECTED,            /**< left brace or multiply expected */
165425bb815Sopenharmony_ci  PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED,              /**< right brace or comma expected */
166425bb815Sopenharmony_ci  PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER,            /**< duplicated export identifier name */
167425bb815Sopenharmony_ci  PARSER_ERR_DUPLICATED_IMPORT_BINDING,               /**< duplicated import binding name */
168425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
169425bb815Sopenharmony_ci
170425bb815Sopenharmony_ci  PARSER_ERR_NON_STRICT_ARG_DEFINITION                /**< non-strict argument definition */
171425bb815Sopenharmony_ci} parser_error_t;
172425bb815Sopenharmony_ci
173425bb815Sopenharmony_ci/**
174425bb815Sopenharmony_ci * Source code line counter type.
175425bb815Sopenharmony_ci */
176425bb815Sopenharmony_citypedef uint32_t parser_line_counter_t;
177425bb815Sopenharmony_ci
178425bb815Sopenharmony_ci/**
179425bb815Sopenharmony_ci * Error code location.
180425bb815Sopenharmony_ci */
181425bb815Sopenharmony_citypedef struct
182425bb815Sopenharmony_ci{
183425bb815Sopenharmony_ci  parser_error_t error;                               /**< error code */
184425bb815Sopenharmony_ci  parser_line_counter_t line;                         /**< line where the error occured */
185425bb815Sopenharmony_ci  parser_line_counter_t column;                       /**< column where the error occured */
186425bb815Sopenharmony_ci} parser_error_location_t;
187425bb815Sopenharmony_ci
188425bb815Sopenharmony_ci/* Note: source must be a valid UTF-8 string */
189425bb815Sopenharmony_ciecma_value_t parser_parse_script (const uint8_t *arg_list_p, size_t arg_list_size,
190425bb815Sopenharmony_ci                                  const uint8_t *source_p, size_t source_size,
191425bb815Sopenharmony_ci                                  uint32_t parse_opts, ecma_compiled_code_t **bytecode_data_p);
192425bb815Sopenharmony_ci
193425bb815Sopenharmony_ci#if ENABLED (JERRY_ERROR_MESSAGES)
194425bb815Sopenharmony_ciconst char *parser_error_to_string (parser_error_t);
195425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ERROR_MESSAGES) */
196425bb815Sopenharmony_ci
197425bb815Sopenharmony_ci/**
198425bb815Sopenharmony_ci * @}
199425bb815Sopenharmony_ci * @}
200425bb815Sopenharmony_ci * @}
201425bb815Sopenharmony_ci */
202425bb815Sopenharmony_ci
203425bb815Sopenharmony_ci#endif /* !JS_PARSER_H */
204