summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoritchyny <itchyny@cybozu.co.jp>2023-06-28 17:59:46 +0900
committerGitHub <noreply@github.com>2023-06-28 17:59:46 +0900
commit6d694a4a581a2d3a6014711c691a23b6dce9badc (patch)
tree992a44062c607e09834e9c0f288ac4e489aeb01d
parent5dacc6b3a1d40cd9e86cc0059c990fc7c70a5831 (diff)
Validate module metadata to be an object (#2357)
-rw-r--r--src/compile.c1
-rw-r--r--src/lexer.c35
-rw-r--r--src/lexer.h11
-rw-r--r--src/parser.c2907
-rw-r--r--src/parser.h127
-rw-r--r--src/parser.y4
-rw-r--r--tests/jq.test4
7 files changed, 1701 insertions, 1388 deletions
diff --git a/src/compile.c b/src/compile.c
index 559bfd0b..b713bc37 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -514,6 +514,7 @@ jv block_list_funcs(block body, int omit_underscores) {
}
block gen_module(block metadata) {
+ assert(block_is_const(metadata) && block_const_kind(metadata) == JV_KIND_OBJECT);
inst* i = inst_new(MODULEMETA);
i->imm.constant = block_const(metadata);
if (jv_get_kind(i->imm.constant) != JV_KIND_OBJECT)
diff --git a/src/lexer.c b/src/lexer.c
index 3745819a..764bc73d 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -1,6 +1,6 @@
-#line 2 "src/lexer.c"
+#line 1 "src/lexer.c"
-#line 4 "src/lexer.c"
+#line 3 "src/lexer.c"
#define YY_INT_ALIGNED short int
@@ -281,6 +281,7 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
+typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
@@ -445,7 +446,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
- int yy_n_chars;
+ yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
@@ -522,7 +523,7 @@ static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
-YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner );
void *yyalloc ( yy_size_t , yyscan_t yyscanner );
void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
@@ -569,7 +570,7 @@ static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
*/
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
- yyleng = (int) (yy_cp - yy_bp); \
+ yyleng = (yy_size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
@@ -842,8 +843,8 @@ struct yyguts_t
size_t yy_buffer_stack_max; /**< capacity of stack. */
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
char yy_hold_char;
- int yy_n_chars;
- int yyleng_r;
+ yy_size_t yy_n_chars;
+ yy_size_t yyleng_r;
char *yy_c_buf_p;
int yy_init;
int yy_start;
@@ -900,7 +901,7 @@ FILE *yyget_out ( yyscan_t yyscanner );
void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int yyget_leng ( yyscan_t yyscanner );
+ yy_size_t yyget_leng ( yyscan_t yyscanner );
char *yyget_text ( yyscan_t yyscanner );
@@ -985,7 +986,7 @@ static int input ( yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- int n; \
+ yy_size_t n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -1636,7 +1637,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{
- int num_to_read =
+ yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
@@ -1650,7 +1651,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( b->yy_is_our_buffer )
{
- int new_size = b->yy_buf_size * 2;
+ yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
@@ -1708,7 +1709,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
- int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
+ yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
(void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
@@ -1815,7 +1816,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{ /* need more input */
- int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
+ yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
@@ -2193,12 +2194,12 @@ YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
-YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
- int i;
+ yy_size_t i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = (yy_size_t) (_yybytes_len + 2);
@@ -2283,7 +2284,7 @@ static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
do \
{ \
/* Undo effects of setting up yytext. */ \
- int yyless_macro_arg = (n); \
+ yy_size_t yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
yytext[yyleng] = yyg->yy_hold_char; \
yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
@@ -2351,7 +2352,7 @@ FILE *yyget_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
-int yyget_leng (yyscan_t yyscanner)
+yy_size_t yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
diff --git a/src/lexer.h b/src/lexer.h
index 8ad2a44b..8446055b 100644
--- a/src/lexer.h
+++ b/src/lexer.h
@@ -2,9 +2,9 @@
#define jq_yyHEADER_H 1
#define jq_yyIN_HEADER 1
-#line 6 "src/lexer.h"
+#line 5 "src/lexer.h"
-#line 8 "src/lexer.h"
+#line 7 "src/lexer.h"
#define YY_INT_ALIGNED short int
@@ -285,6 +285,7 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
+typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
@@ -398,7 +399,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
- int yy_n_chars;
+ yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
@@ -442,7 +443,7 @@ void yypop_buffer_state ( yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
-YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner );
void *yyalloc ( yy_size_t , yyscan_t yyscanner );
void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
@@ -500,7 +501,7 @@ FILE *yyget_out ( yyscan_t yyscanner );
void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int yyget_leng ( yyscan_t yyscanner );
+ yy_size_t yyget_leng ( yyscan_t yyscanner );
char *yyget_text ( yyscan_t yyscanner );
diff --git a/src/parser.c b/src/parser.c
index 82bf21d6..28d47c50 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1,8 +1,9 @@
-/* A Bison parser, made by GNU Bison 3.0.4. */
+/* A Bison parser, made by GNU Bison 3.8.2. */
/* Bison implementation for Yacc-like parsers in C
- Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
+ Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
+ Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,7 +16,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
@@ -33,6 +34,10 @@
/* C LALR(1) parser skeleton written by Richard Stallman, by
simplifying the original so-called "semantic" parser. */
+/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
+ especially those whose name start with YY_ or yy_. They are
+ private implementation details that can be changed or removed. */
+
/* All symbols defined below should begin with yy or YY, to avoid
infringing on user name space. This should be done even for local
variables, as they might otherwise be expanded by user macros.
@@ -40,11 +45,11 @@
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
-/* Identify Bison output. */
-#define YYBISON 1
+/* Identify Bison output, and Bison version. */
+#define YYBISON 30802
-/* Bison version. */
-#define YYBISON_VERSION "3.0.4"
+/* Bison version string. */
+#define YYBISON_VERSION "3.8.2"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
@@ -61,8 +66,8 @@
-/* Copy the first part of user declarations. */
-#line 1 "src/parser.y" /* yacc.c:339 */
+/* First part of user prologue. */
+#line 1 "src/parser.y"
#include <assert.h>
#include <math.h>
@@ -73,26 +78,31 @@
#define YYMALLOC jv_mem_alloc
#define YYFREE jv_mem_free
-#line 77 "src/parser.c" /* yacc.c:339 */
+#line 82 "src/parser.c"
+# ifndef YY_CAST
+# ifdef __cplusplus
+# define YY_CAST(Type, Val) static_cast<Type> (Val)
+# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
+# else
+# define YY_CAST(Type, Val) ((Type) (Val))
+# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
+# endif
+# endif
# ifndef YY_NULLPTR
-# if defined __cplusplus && 201103L <= __cplusplus
-# define YY_NULLPTR nullptr
+# if defined __cplusplus
+# if 201103L <= __cplusplus
+# define YY_NULLPTR nullptr
+# else
+# define YY_NULLPTR 0
+# endif
# else
-# define YY_NULLPTR 0
+# define YY_NULLPTR ((void*)0)
# endif
# endif
-/* Enabling verbose error messages. */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 1
-#endif
-
-/* In a future release of Bison, this section will be replaced
- by #include "y.tab.h". */
+/* Use api.header.include to #include this header
+ instead of duplicating it here. */
#ifndef YY_YY_SRC_PARSER_H_INCLUDED
# define YY_YY_SRC_PARSER_H_INCLUDED
/* Debug traces. */
@@ -103,7 +113,7 @@
extern int yydebug;
#endif
/* "%code requires" blocks. */
-#line 11 "src/parser.y" /* yacc.c:355 */
+#line 11 "src/parser.y"
#include "locfile.h"
struct lexer_param;
@@ -120,61 +130,70 @@ struct lexer_param;
} \
} while (0)
-#line 124 "src/parser.c" /* yacc.c:355 */
+#line 134 "src/parser.c"
-/* Token type. */
+/* Token kinds. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
- INVALID_CHARACTER = 258,
- IDENT = 259,
- FIELD = 260,
- LITERAL = 261,
- FORMAT = 262,
- REC = 263,
- SETMOD = 264,
- EQ = 265,
- NEQ = 266,
- DEFINEDOR = 267,
- AS = 268,
- DEF = 269,
- MODULE = 270,
- IMPORT = 271,
- INCLUDE = 272,
- IF = 273,
- THEN = 274,
- ELSE = 275,
- ELSE_IF = 276,
- REDUCE = 277,
- FOREACH = 278,
- END = 279,
- AND = 280,
- OR = 281,
- TRY = 282,
- CATCH = 283,
- LABEL = 284,
- BREAK = 285,
- LOC = 286,
- SETPIPE = 287,
- SETPLUS = 288,
- SETMINUS = 289,
- SETMULT = 290,
- SETDIV = 291,
- SETDEFINEDOR = 292,
- LESSEQ = 293,
- GREATEREQ = 294,
- ALTERNATION = 295,
- QQSTRING_START = 296,
- QQSTRING_TEXT = 297,
- QQSTRING_INTERP_START = 298,
- QQSTRING_INTERP_END = 299,
- QQSTRING_END = 300,
- FUNCDEF = 301,
- NONOPT = 302
+ YYEMPTY = -2,
+ YYEOF = 0, /* "end of file" */
+ YYerror = 256, /* error */
+ YYUNDEF = 257, /* "invalid token" */
+ INVALID_CHARACTER = 258, /* INVALID_CHARACTER */
+ IDENT = 259, /* IDENT */
+ FIELD = 260, /* FIELD */
+ LITERAL = 261, /* LITERAL */
+ FORMAT = 262, /* FORMAT */
+ REC = 263, /* ".." */
+ SETMOD = 264, /* "%=" */
+ EQ = 265, /* "==" */
+ NEQ = 266, /* "!=" */
+ DEFINEDOR = 267, /* "//" */
+ AS = 268, /* "as" */
+ DEF = 269, /* "def" */
+ MODULE = 270, /* "module" */
+ IMPORT = 271, /* "import" */
+ INCLUDE = 272, /* "include" */
+ IF = 273, /* "if" */
+ THEN = 274, /* "then" */
+ ELSE = 275, /* "else" */
+ ELSE_IF = 276, /* "elif" */
+ REDUCE = 277, /* "reduce" */
+ FOREACH = 278, /* "foreach" */
+ END = 279, /* "end" */
+ AND = 280, /* "and" */
+ OR = 281, /* "or" */
+ TRY = 282, /* "try" */
+ CATCH = 283, /* "catch" */
+ LABEL = 284, /* "label" */
+ BREAK = 285, /* "break" */
+ LOC = 286, /* "__loc__" */
+ SETPIPE = 287, /* "|=" */
+ SETPLUS = 288, /* "+=" */
+ SETMINUS = 289, /* "-=" */
+ SETMULT = 290, /* "*=" */
+ SETDIV = 291, /* "/=" */
+ SETDEFINEDOR = 292, /* "//=" */
+ LESSEQ = 293, /* "<=" */
+ GREATEREQ = 294, /* ">=" */
+ ALTERNATION = 295, /* "?//" */
+ QQSTRING_START = 296, /* QQSTRING_START */
+ QQSTRING_TEXT = 297, /* QQSTRING_TEXT */
+ QQSTRING_INTERP_START = 298, /* QQSTRING_INTERP_START */
+ QQSTRING_INTERP_END = 299, /* QQSTRING_INTERP_END */
+ QQSTRING_END = 300, /* QQSTRING_END */
+ FUNCDEF = 301, /* FUNCDEF */
+ NONOPT = 302 /* NONOPT */
};
+ typedef enum yytokentype yytoken_kind_t;
#endif
-/* Tokens. */
+/* Token kinds. */
+#define YYEMPTY -2
+#define YYEOF 0
+#define YYerror 256
+#define YYUNDEF 257
#define INVALID_CHARACTER 258
#define IDENT 259
#define FIELD 260
@@ -223,17 +242,16 @@ struct lexer_param;
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
-
union YYSTYPE
{
-#line 31 "src/parser.y" /* yacc.c:355 */
+#line 31 "src/parser.y"
jv literal;
block blk;
-#line 235 "src/parser.c" /* yacc.c:355 */
-};
+#line 253 "src/parser.c"
+};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
@@ -255,12 +273,120 @@ struct YYLTYPE
+
int yyparse (block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr);
+
#endif /* !YY_YY_SRC_PARSER_H_INCLUDED */
+/* Symbol kind. */
+enum yysymbol_kind_t
+{
+ YYSYMBOL_YYEMPTY = -2,
+ YYSYMBOL_YYEOF = 0, /* "end of file" */
+ YYSYMBOL_YYerror = 1, /* error */
+ YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
+ YYSYMBOL_INVALID_CHARACTER = 3, /* INVALID_CHARACTER */
+ YYSYMBOL_IDENT = 4, /* IDENT */
+ YYSYMBOL_FIELD = 5, /* FIELD */
+ YYSYMBOL_LITERAL = 6, /* LITERAL */
+ YYSYMBOL_FORMAT = 7, /* FORMAT */
+ YYSYMBOL_REC = 8, /* ".." */
+ YYSYMBOL_SETMOD = 9, /* "%=" */
+ YYSYMBOL_EQ = 10, /* "==" */
+ YYSYMBOL_NEQ = 11, /* "!=" */
+ YYSYMBOL_DEFINEDOR = 12, /* "//" */
+ YYSYMBOL_AS = 13, /* "as" */
+ YYSYMBOL_DEF = 14, /* "def" */
+ YYSYMBOL_MODULE = 15, /* "module" */
+ YYSYMBOL_IMPORT = 16, /* "import" */
+ YYSYMBOL_INCLUDE = 17, /* "include" */
+ YYSYMBOL_IF = 18, /* "if" */
+ YYSYMBOL_THEN = 19, /* "then" */
+ YYSYMBOL_ELSE = 20, /* "else" */
+ YYSYMBOL_ELSE_IF = 21, /* "elif" */
+ YYSYMBOL_REDUCE = 22, /* "reduce" */
+ YYSYMBOL_FOREACH = 23, /* "foreach" */
+ YYSYMBOL_END = 24, /* "end" */
+ YYSYMBOL_AND = 25, /* "and" */
+ YYSYMBOL_OR = 26, /* "or" */
+ YYSYMBOL_TRY = 27, /* "try" */
+ YYSYMBOL_CATCH = 28, /* "catch" */
+ YYSYMBOL_LABEL = 29, /* "label" */
+ YYSYMBOL_BREAK = 30, /* "break" */
+ YYSYMBOL_LOC = 31, /* "__loc__" */
+ YYSYMBOL_SETPIPE = 32, /* "|=" */
+ YYSYMBOL_SETPLUS = 33, /* "+=" */
+ YYSYMBOL_SETMINUS = 34, /* "-=" */
+ YYSYMBOL_SETMULT = 35, /* "*=" */
+ YYSYMBOL_SETDIV = 36, /* "/=" */
+ YYSYMBOL_SETDEFINEDOR = 37, /* "//=" */
+ YYSYMBOL_LESSEQ = 38, /* "<=" */
+ YYSYMBOL_GREATEREQ = 39, /* ">=" */
+ YYSYMBOL_ALTERNATION = 40, /* "?//" */
+ YYSYMBOL_QQSTRING_START = 41, /* QQSTRING_START */
+ YYSYMBOL_QQSTRING_TEXT = 42, /* QQSTRING_TEXT */
+ YYSYMBOL_QQSTRING_INTERP_START = 43, /* QQSTRING_INTERP_START */
+ YYSYMBOL_QQSTRING_INTERP_END = 44, /* QQSTRING_INTERP_END */
+ YYSYMBOL_QQSTRING_END = 45, /* QQSTRING_END */
+ YYSYMBOL_FUNCDEF = 46, /* FUNCDEF */
+ YYSYMBOL_47_ = 47, /* '|' */
+ YYSYMBOL_48_ = 48, /* ',' */
+ YYSYMBOL_49_ = 49, /* '=' */
+ YYSYMBOL_50_ = 50, /* '<' */
+ YYSYMBOL_51_ = 51, /* '>' */
+ YYSYMBOL_52_ = 52, /* '+' */
+ YYSYMBOL_53_ = 53, /* '-' */
+ YYSYMBOL_54_ = 54, /* '*' */
+ YYSYMBOL_55_ = 55, /* '/' */
+ YYSYMBOL_56_ = 56, /* '%' */
+ YYSYMBOL_NONOPT = 57, /* NONOPT */
+ YYSYMBOL_58_ = 58, /* '?' */
+ YYSYMBOL_59_ = 59, /* ';' */
+ YYSYMBOL_60_ = 60, /* '(' */
+ YYSYMBOL_61_ = 61, /* ')' */
+ YYSYMBOL_62_ = 62, /* '$' */
+ YYSYMBOL_63_ = 63, /* ':' */
+ YYSYMBOL_64_ = 64, /* '.' */
+ YYSYMBOL_65_ = 65, /* '[' */
+ YYSYMBOL_66_ = 66, /* ']' */
+ YYSYMBOL_67_ = 67, /* '{' */
+ YYSYMBOL_68_ = 68, /* '}' */
+ YYSYMBOL_YYACCEPT = 69, /* $accept */
+ YYSYMBOL_TopLevel = 70, /* TopLevel */
+ YYSYMBOL_Module = 71, /* Module */
+ YYSYMBOL_Imports = 72, /* Imports */
+ YYSYMBOL_FuncDefs = 73, /* FuncDefs */
+ YYSYMBOL_Exp = 74, /* Exp */
+ YYSYMBOL_Import = 75, /* Import */
+ YYSYMBOL_ImportWhat = 76, /* ImportWhat */
+ YYSYMBOL_ImportFrom = 77, /* ImportFrom */
+ YYSYMBOL_FuncDef = 78, /* FuncDef */
+ YYSYMBOL_Params = 79, /* Params */
+ YYSYMBOL_Param = 80, /* Param */
+ YYSYMBOL_String = 81, /* String */
+ YYSYMBOL_82_1 = 82, /* @1 */
+ YYSYMBOL_83_2 = 83, /* @2 */
+ YYSYMBOL_QQString = 84, /* QQString */
+ YYSYMBOL_ElseBody = 85, /* ElseBody */
+ YYSYMBOL_ExpD = 86, /* ExpD */
+ YYSYMBOL_Term = 87, /* Term */
+ YYSYMBOL_Args = 88, /* Args */
+ YYSYMBOL_Arg = 89, /* Arg */
+ YYSYMBOL_RepPatterns = 90, /* RepPatterns */
+ YYSYMBOL_Patterns = 91, /* Patterns */
+ YYSYMBOL_Pattern = 92, /* Pattern */
+ YYSYMBOL_ArrayPats = 93, /* ArrayPats */
+ YYSYMBOL_ObjPats = 94, /* ObjPats */
+ YYSYMBOL_ObjPat = 95, /* ObjPat */
+ YYSYMBOL_Keyword = 96, /* Keyword */
+ YYSYMBOL_MkDict = 97, /* MkDict */
+ YYSYMBOL_MkDictPair = 98 /* MkDictPair */
+};
+typedef enum yysymbol_kind_t yysymbol_kind_t;
-/* Copy the second part of user declarations. */
-#line 124 "src/parser.y" /* yacc.c:358 */
+
+/* Second part of user prologue. */
+#line 124 "src/parser.y"
#include "lexer.h"
struct lexer_param {
@@ -440,34 +566,94 @@ static block gen_update(block object, block val, int optype) {
}
-#line 444 "src/parser.c" /* yacc.c:358 */
+#line 570 "src/parser.c"
+
#ifdef short
# undef short
#endif
-#ifdef YYTYPE_UINT8
-typedef YYTYPE_UINT8 yytype_uint8;
-#else
-typedef unsigned char yytype_uint8;
+/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
+ <limits.h> and (if available) <stdint.h> are included
+ so that the code can choose integer types of a good width. */
+
+#ifndef __PTRDIFF_MAX__
+# include <limits.h> /* INFRINGES ON USER NAME SPACE */
+# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
+# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_STDINT_H
+# endif
#endif
-#ifdef YYTYPE_INT8
-typedef YYTYPE_INT8 yytype_int8;
+/* Narrow types that promote to a signed type and that can represent a
+ signed or unsigned integer of at least N bits. In tables they can
+ save space and decrease cache pressure. Promoting to a signed type
+ helps avoid bugs in integer arithmetic. */
+
+#ifdef __INT_LEAST8_MAX__
+typedef __INT_LEAST8_TYPE__ yytype_int8;
+#elif defined YY_STDINT_H
+typedef int_least8_t yytype_int8;
#else
typedef signed char yytype_int8;
#endif
-#ifdef YYTYPE_UINT16
-typedef YYTYPE_UINT16 yytype_uint16;
+#ifdef __INT_LEAST16_MAX__
+typedef __INT_LEAST16_TYPE__ yytype_int16;
+#elif defined YY_STDINT_H
+typedef int_least16_t yytype_int16;
#else
-typedef unsigned short int yytype_uint16;
+typedef short yytype_int16;
+#endif
+
+/* Work around bug in HP-UX 11.23, which defines these macros
+ incorrectly for preprocessor constants. This workaround can likely
+ be removed in 2023, as HPE has promised support for HP-UX 11.23
+ (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
+ <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
+#ifdef __hpux
+# undef UINT_LEAST8_MAX
+# undef UINT_LEAST16_MAX
+# define UINT_LEAST8_MAX 255
+# define UINT_LEAST16_MAX 65535
#endif
-#ifdef YYTYPE_INT16
-typedef YYTYPE_INT16 yytype_int16;
+#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
+typedef __UINT_LEAST8_TYPE__ yytype_uint8;
+#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
+ && UINT_LEAST8_MAX <= INT_MAX)
+typedef uint_least8_t yytype_uint8;
+#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
+typedef unsigned char yytype_uint8;
#else
-typedef short int yytype_int16;
+typedef short yytype_uint8;
+#endif
+
+#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
+typedef __UINT_LEAST16_TYPE__ yytype_uint16;
+#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
+ && UINT_LEAST16_MAX <= INT_MAX)
+typedef uint_least16_t yytype_uint16;
+#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
+typedef unsigned short yytype_uint16;
+#else
+typedef int yytype_uint16;
+#endif
+
+#ifndef YYPTRDIFF_T
+# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
+# define YYPTRDIFF_T __PTRDIFF_TYPE__
+# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
+# elif defined PTRDIFF_MAX
+# ifndef ptrdiff_t
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# endif
+# define YYPTRDIFF_T ptrdiff_t
+# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
+# else
+# define YYPTRDIFF_T long
+# define YYPTRDIFF_MAXIMUM LONG_MAX
+# endif
#endif
#ifndef YYSIZE_T
@@ -475,15 +661,28 @@ typedef short int yytype_int16;
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
-# elif ! defined YYSIZE_T
+# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
-# define YYSIZE_T unsigned int
+# define YYSIZE_T unsigned
# endif
#endif
-#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+#define YYSIZE_MAXIMUM \
+ YY_CAST (YYPTRDIFF_T, \
+ (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
+ ? YYPTRDIFF_MAXIMUM \
+ : YY_CAST (YYSIZE_T, -1)))
+
+#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
+
+
+/* Stored state numbers (used for stacks). */
+typedef yytype_int16 yy_state_t;
+
+/* State numbers in computations. */
+typedef int yy_state_fast_t;
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
@@ -497,47 +696,43 @@ typedef short int yytype_int16;
# endif
#endif
-#ifndef YY_ATTRIBUTE
-# if (defined __GNUC__ \
- && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
- || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
-# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
-# else
-# define YY_ATTRIBUTE(Spec) /* empty */
-# endif
-#endif
#ifndef YY_ATTRIBUTE_PURE
-# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
+# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
+# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
+# else
+# define YY_ATTRIBUTE_PURE
+# endif
#endif
#ifndef YY_ATTRIBUTE_UNUSED
-# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
-#endif
-
-#if !defined _Noreturn \
- && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
-# if defined _MSC_VER && 1200 <= _MSC_VER
-# define _Noreturn __declspec (noreturn)
+# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
+# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# else
-# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
+# define YY_ATTRIBUTE_UNUSED
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
-# define YYUSE(E) ((void) (E))
+# define YY_USE(E) ((void) (E))
#else
-# define YYUSE(E) /* empty */
+# define YY_USE(E) /* empty */
#endif
-#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
- _Pragma ("GCC diagnostic push") \
- _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
+# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
+# else
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+# endif
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
@@ -550,8 +745,22 @@ typedef short int yytype_int16;
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif
+#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
+# define YY_IGNORE_USELESS_CAST_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
+# define YY_IGNORE_USELESS_CAST_END \
+ _Pragma ("GCC diagnostic pop")
+#endif
+#ifndef YY_IGNORE_USELESS_CAST_BEGIN
+# define YY_IGNORE_USELESS_CAST_BEGIN
+# define YY_IGNORE_USELESS_CAST_END
+#endif
-#if ! defined yyoverflow || YYERROR_VERBOSE
+
+#define YY_ASSERT(E) ((void) (0 && (E)))
+
+#if 1
/* The parser invokes alloca or malloc; define the necessary symbols. */
@@ -616,8 +825,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# endif
-#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
-
+#endif /* 1 */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
@@ -627,18 +835,19 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
/* A type that is properly aligned for any stack member. */
union yyalloc
{
- yytype_int16 yyss_alloc;
+ yy_state_t yyss_alloc;
YYSTYPE yyvs_alloc;
YYLTYPE yyls_alloc;
};
/* The size of the maximum gap between one aligned stack and the next. */
-# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
/* The size of an array large to enough to hold all stacks, each with
N elements. */
# define YYSTACK_BYTES(N) \
- ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
+ ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \
+ + YYSIZEOF (YYLTYPE)) \
+ 2 * YYSTACK_GAP_MAXIMUM)
# define YYCOPY_NEEDED 1
@@ -651,11 +860,11 @@ union yyalloc
# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
do \
{ \
- YYSIZE_T yynewbytes; \
+ YYPTRDIFF_T yynewbytes; \
YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
Stack = &yyptr->Stack_alloc; \
- yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
- yyptr += yynewbytes / sizeof (*yyptr); \
+ yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / YYSIZEOF (*yyptr); \
} \
while (0)
@@ -667,12 +876,12 @@ union yyalloc
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(Dst, Src, Count) \
- __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
+ __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
# else
# define YYCOPY(Dst, Src, Count) \
do \
{ \
- YYSIZE_T yyi; \
+ YYPTRDIFF_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(Dst)[yyi] = (Src)[yyi]; \
} \
@@ -695,17 +904,20 @@ union yyalloc
/* YYNSTATES -- Number of states. */
#define YYNSTATES 326
-/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
- by yylex, with out-of-bounds checking. */
-#define YYUNDEFTOK 2
+/* YYMAXUTOK -- Last valid token kind. */
#define YYMAXUTOK 302
-#define YYTRANSLATE(YYX) \
- ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex, with out-of-bounds checking. */
+#define YYTRANSLATE(YYX) \
+ (0 <= (YYX) && (YYX) <= YYMAXUTOK \
+ ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
+ : YYSYMBOL_YYUNDEF)
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
- as returned by yylex, without out-of-bounds checking. */
-static const yytype_uint8 yytranslate[] =
+ as returned by yylex. */
+static const yytype_int8 yytranslate[] =
{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@@ -741,81 +953,79 @@ static const yytype_uint8 yytranslate[] =
};
#if YYDEBUG
- /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
-static const yytype_uint16 yyrline[] =
+/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
+static const yytype_int16 yyrline[] =
{
- 0, 306, 306, 309, 314, 317, 328, 331, 336, 339,
- 344, 348, 351, 355, 359, 363, 366, 369, 374, 378,
- 382, 387, 394, 398, 402, 406, 410, 414, 418, 422,
- 426, 430, 434, 438, 442, 446, 450, 454, 458, 464,
- 470, 474, 478, 482, 486, 490, 494, 498, 502, 507,
- 510, 527, 536, 543, 551, 562, 567, 573, 576, 581,
- 585, 589, 596, 596, 600, 600, 607, 610, 613, 619,
- 622, 627, 630, 633, 639, 642, 645, 653, 657, 660,
- 663, 666, 669, 672, 675, 678, 681, 685, 691, 694,
- 697, 700, 703, 706,