Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

Location:
EcnlProtoTool/trunk/mruby-1.3.0
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/core/parse.y

    r270 r331  
    2323#include <stdlib.h>
    2424#include <string.h>
    25 #include "mruby.h"
    26 #include "mruby/compile.h"
    27 #include "mruby/proc.h"
    28 #include "mruby/error.h"
     25#include <mruby.h>
     26#include <mruby/compile.h>
     27#include <mruby/proc.h>
     28#include <mruby/error.h>
     29#include <mruby/throw.h>
    2930#include "node.h"
    30 #include "mruby/throw.h"
    3131
    3232#define YYLEX_PARAM p
     
    4242static void yywarning(parser_state *p, const char *s);
    4343static void backref_error(parser_state *p, node *n);
     44static void void_expr_error(parser_state *p, node *n);
    4445static void tokadd(parser_state *p, int32_t c);
    4546
     
    7374#define sym(x) ((mrb_sym)(intptr_t)(x))
    7475#define nsym(x) ((node*)(intptr_t)(x))
     76#define nint(x) ((node*)(intptr_t)(x))
     77#define intn(x) ((int)(intptr_t)(x))
    7578
    7679static inline mrb_sym
     
    309312}
    310313
     314static node*
     315new_mod_rescue(parser_state *p, node *body, node *resq)
     316{
     317  return new_rescue(p, body, list1(list3(0, 0, resq)), 0);
     318}
     319
    311320/* (:ensure body ensure) */
    312321static node*
     
    348357new_if(parser_state *p, node *a, node *b, node *c)
    349358{
     359  void_expr_error(p, a);
    350360  return list4((node*)NODE_IF, a, b, c);
    351361}
     
    355365new_unless(parser_state *p, node *a, node *b, node *c)
    356366{
     367  void_expr_error(p, a);
    357368  return list4((node*)NODE_IF, a, c, b);
    358369}
     
    362373new_while(parser_state *p, node *a, node *b)
    363374{
     375  void_expr_error(p, a);
    364376  return cons((node*)NODE_WHILE, cons(a, b));
    365377}
     
    369381new_until(parser_state *p, node *a, node *b)
    370382{
     383  void_expr_error(p, a);
    371384  return cons((node*)NODE_UNTIL, cons(a, b));
    372385}
     
    376389new_for(parser_state *p, node *v, node *o, node *b)
    377390{
     391  void_expr_error(p, o);
    378392  return list4((node*)NODE_FOR, v, o, b);
    379393}
     
    386400  node *n2 = n;
    387401
     402  void_expr_error(p, a);
    388403  while (n2->cdr) {
    389404    n2 = n2->cdr;
     
    409424/* (:call a b c) */
    410425static node*
    411 new_call(parser_state *p, node *a, mrb_sym b, node *c)
    412 {
    413   node *n = list4((node*)NODE_CALL, a, nsym(b), c);
     426new_call(parser_state *p, node *a, mrb_sym b, node *c, int pass)
     427{
     428  node *n = list4(nint(pass?NODE_CALL:NODE_SCALL), a, nsym(b), c);
     429  void_expr_error(p, a);
    414430  NODE_LINENO(n, a);
    415431  return n;
     
    507523new_colon2(parser_state *p, node *b, mrb_sym c)
    508524{
     525  void_expr_error(p, b);
    509526  return cons((node*)NODE_COLON2, cons(b, nsym(c)));
    510527}
     
    614631new_class(parser_state *p, node *c, node *s, node *b)
    615632{
     633  void_expr_error(p, s);
    616634  return list4((node*)NODE_CLASS, c, s, cons(locals_node(p), b));
    617635}
     
    621639new_sclass(parser_state *p, node *o, node *b)
    622640{
     641  void_expr_error(p, o);
    623642  return list3((node*)NODE_SCLASS, o, cons(locals_node(p), b));
    624643}
     
    642661new_sdef(parser_state *p, node *o, mrb_sym m, node *a, node *b)
    643662{
     663  void_expr_error(p, o);
    644664  return list6((node*)NODE_SDEF, o, nsym(m), locals_node(p), a, b);
    645665}
     
    694714new_asgn(parser_state *p, node *a, node *b)
    695715{
     716  void_expr_error(p, b);
    696717  return cons((node*)NODE_ASGN, cons(a, b));
    697718}
     
    701722new_masgn(parser_state *p, node *a, node *b)
    702723{
     724  void_expr_error(p, b);
    703725  return cons((node*)NODE_MASGN, cons(a, b));
    704726}
     
    708730new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b)
    709731{
     732  void_expr_error(p, b);
    710733  return list4((node*)NODE_OP_ASGN, a, nsym(op), b);
    711734}
     
    715738new_int(parser_state *p, const char *s, int base)
    716739{
    717   return list3((node*)NODE_INT, (node*)strdup(s), (node*)(intptr_t)base);
     740  return list3((node*)NODE_INT, (node*)strdup(s), nint(base));
    718741}
    719742
     
    729752new_str(parser_state *p, const char *s, int len)
    730753{
    731   return cons((node*)NODE_STR, cons((node*)strndup(s, len), (node*)(intptr_t)len));
     754  return cons((node*)NODE_STR, cons((node*)strndup(s, len), nint(len)));
    732755}
    733756
     
    743766new_xstr(parser_state *p, const char *s, int len)
    744767{
    745   return cons((node*)NODE_XSTR, cons((node*)strndup(s, len), (node*)(intptr_t)len));
     768  return cons((node*)NODE_XSTR, cons((node*)strndup(s, len), nint(len)));
    746769}
    747770
     
    760783}
    761784
    762 /* (:str . (a . a)) */
     785/* (:regx . (s . (opt . enc))) */
    763786static node*
    764787new_regx(parser_state *p, const char *p1, const char* p2, const char* p3)
     
    767790}
    768791
    769 /* (:dregx . a) */
     792/* (:dregx . (a . b)) */
    770793static node*
    771794new_dregx(parser_state *p, node *a, node *b)
     
    778801new_back_ref(parser_state *p, int n)
    779802{
    780   return cons((node*)NODE_BACK_REF, (node*)(intptr_t)n);
     803  return cons((node*)NODE_BACK_REF, nint(n));
    781804}
    782805
     
    785808new_nth_ref(parser_state *p, int n)
    786809{
    787   return cons((node*)NODE_NTH_REF, (node*)(intptr_t)n);
     810  return cons((node*)NODE_NTH_REF, nint(n));
    788811}
    789812
     
    827850call_uni_op(parser_state *p, node *recv, const char *m)
    828851{
    829   return new_call(p, recv, intern_cstr(m), 0);
     852  void_expr_error(p, recv);
     853  return new_call(p, recv, intern_cstr(m), 0, 1);
    830854}
    831855
     
    834858call_bin_op(parser_state *p, node *recv, const char *m, node *arg1)
    835859{
    836   return new_call(p, recv, intern_cstr(m), list1(list1(arg1)));
     860  return new_call(p, recv, intern_cstr(m), list1(list1(arg1)), 1);
    837861}
    838862
     
    853877  node *n;
    854878
    855   if (a->car == (node*)NODE_SUPER ||
    856       a->car == (node*)NODE_ZSUPER) {
     879  switch ((enum node_type)intn(a->car)) {
     880  case NODE_SUPER:
     881  case NODE_ZSUPER:
    857882    if (!a->cdr) a->cdr = cons(0, b);
    858883    else {
    859884      args_with_block(p, a->cdr, b);
    860885    }
    861   }
    862   else {
     886    break;
     887  case NODE_CALL:
     888  case NODE_FCALL:
     889  case NODE_SCALL:
    863890    n = a->cdr->cdr->cdr;
    864891    if (!n->car) n->car = cons(0, b);
     
    866893      args_with_block(p, n->car, b);
    867894    }
     895    break;
     896  default:
     897    break;
    868898  }
    869899}
     
    895925assignable(parser_state *p, node *lhs)
    896926{
    897   if ((int)(intptr_t)lhs->car == NODE_LVAR) {
     927  if (intn(lhs->car) == NODE_LVAR) {
    898928    local_add(p, sym(lhs->cdr));
    899929  }
     
    905935  node *n;
    906936
    907   if ((int)(intptr_t)lhs->car == NODE_LVAR) {
     937  if (intn(lhs->car) == NODE_LVAR) {
    908938    if (!local_var_p(p, sym(lhs->cdr))) {
    909939      n = new_fcall(p, sym(lhs->cdr), 0);
     
    921951new_strterm(parser_state *p, string_type type, int term, int paren)
    922952{
    923   return cons((node*)(intptr_t)type, cons((node*)0, cons((node*)(intptr_t)paren, (node*)(intptr_t)term)));
     953  return cons(nint(type), cons((node*)0, cons(nint(paren), nint(term))));
    924954}
    925955
     
    10021032  else {
    10031033    /* next heredoc */
    1004     p->lex_strterm->car = (node*)(intptr_t)parsing_heredoc_inf(p)->type;
    1005   }
    1006 }
    1007 #define is_strterm_type(p,str_func) ((int)(intptr_t)((p)->lex_strterm->car) & (str_func))
     1034    p->lex_strterm->car = nint(parsing_heredoc_inf(p)->type);
     1035  }
     1036}
     1037#define is_strterm_type(p,str_func) (intn((p)->lex_strterm->car) & (str_func))
    10081038
    10091039/* xxx ----------------------------- */
     
    10771107%token <id>  tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
    10781108%token <nd>  tINTEGER tFLOAT tCHAR tXSTRING tREGEXP
    1079 %token <nd>  tSTRING tSTRING_PART tSTRING_MID
     1109%token <nd>  tSTRING tSTRING_PART tSTRING_MID tLABEL_END
    10801110%token <nd>  tNTH_REF tBACK_REF
    10811111%token <num> tREGEXP_END
     
    10851115%type <nd> top_compstmt top_stmts top_stmt
    10861116%type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
    1087 %type <nd> expr_value arg_value primary_value
     1117%type <nd> expr_value arg_rhs primary_value
    10881118%type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
    10891119%type <nd> args call_args opt_call_args
    10901120%type <nd> paren_args opt_paren_args variable
    10911121%type <nd> command_args aref_args opt_block_arg block_arg var_ref var_lhs
    1092 %type <nd> command_asgn mrhs superclass block_call block_command
     1122%type <nd> command_asgn command_rhs mrhs superclass block_call block_command
    10931123%type <nd> f_block_optarg f_block_opt
    10941124%type <nd> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
     
    11011131%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_opt_asgn
    11021132%type <nd> heredoc words symbols
     1133%type <num> call_op call_op2     /* 0:'&.', 1:'.', 2:'::' */
    11031134
    11041135%token tUPLUS             /* unary+ */
     
    11291160%token tAMPER             /* & */
    11301161%token tLAMBDA            /* -> */
     1162%token tANDDOT            /* &. */
    11311163%token tSYMBEG tREGEXP_BEG tWORDS_BEG tSYMBOLS_BEG
    11321164%token tSTRING_BEG tXSTRING_BEG tSTRING_DVAR tLAMBEG
     
    12921324                | stmt modifier_rescue stmt
    12931325                    {
    1294                       $$ = new_rescue(p, $1, list1(list3(0, 0, $3)), 0);
     1326                      $$ = new_mod_rescue(p, $1, $3);
    12951327                    }
    12961328                | keyword_END '{' compstmt '}'
    12971329                    {
    1298                       yyerror(p, "END not suported");
     1330                      yyerror(p, "END not supported");
    12991331                      $$ = new_postexe(p, $3);
    13001332                    }
     
    13041336                      $$ = new_masgn(p, $1, $3);
    13051337                    }
    1306                 | var_lhs tOP_ASGN command_call
     1338                | lhs '=' mrhs
     1339                    {
     1340                      $$ = new_asgn(p, $1, new_array(p, $3));
     1341                    }
     1342                | mlhs '=' arg
     1343                    {
     1344                      $$ = new_masgn(p, $1, $3);
     1345                    }
     1346                | mlhs '=' mrhs
     1347                    {
     1348                      $$ = new_masgn(p, $1, new_array(p, $3));
     1349                    }
     1350                | expr
     1351                ;
     1352
     1353command_asgn    : lhs '=' command_rhs
     1354                    {
     1355                      $$ = new_asgn(p, $1, $3);
     1356                    }
     1357                | var_lhs tOP_ASGN command_rhs
    13071358                    {
    13081359                      $$ = new_op_asgn(p, $1, $2, $3);
    13091360                    }
    1310                 | primary_value '[' opt_call_args rbracket tOP_ASGN command_call
    1311                     {
    1312                       $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3), $5, $6);
    1313                     }
    1314                 | primary_value '.' tIDENTIFIER tOP_ASGN command_call
    1315                     {
    1316                       $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5);
    1317                     }
    1318                 | primary_value '.' tCONSTANT tOP_ASGN command_call
    1319                     {
    1320                       $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5);
     1361                | primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs
     1362                    {
     1363                      $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6);
     1364                    }
     1365                | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
     1366                    {
     1367                      $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5);
     1368                    }
     1369                | primary_value call_op tCONSTANT tOP_ASGN command_rhs
     1370                    {
     1371                      $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5);
    13211372                    }
    13221373                | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
     
    13251376                      $$ = 0;
    13261377                    }
    1327                 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
    1328                     {
    1329                       $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5);
    1330                     }
    1331                 | backref tOP_ASGN command_call
     1378                | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
     1379                    {
     1380                      $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5);
     1381                    }
     1382                | backref tOP_ASGN command_rhs
    13321383                    {
    13331384                      backref_error(p, $1);
    13341385                      $$ = new_begin(p, 0);
    13351386                    }
    1336                 | lhs '=' mrhs
    1337                     {
    1338                       $$ = new_asgn(p, $1, new_array(p, $3));
    1339                     }
    1340                 | mlhs '=' arg_value
    1341                     {
    1342                       $$ = new_masgn(p, $1, $3);
    1343                     }
    1344                 | mlhs '=' mrhs
    1345                     {
    1346                       $$ = new_masgn(p, $1, new_array(p, $3));
    1347                     }
    1348                 | expr
    1349                 ;
    1350 
    1351 command_asgn    : lhs '=' command_call
    1352                     {
    1353                       $$ = new_asgn(p, $1, $3);
    1354                     }
    1355                 | lhs '=' command_asgn
    1356                     {
    1357                       $$ = new_asgn(p, $1, $3);
    1358                     }
     1387                ;
     1388
     1389command_rhs     : command_call   %prec tOP_ASGN
     1390                | command_call modifier_rescue stmt
     1391                    {
     1392                      $$ = new_mod_rescue(p, $1, $3);
     1393                    }
     1394                | command_asgn
    13591395                ;
    13601396
     
    13831419                    {
    13841420                      if (!$1) $$ = new_nil(p);
    1385                       else $$ = $1;
     1421                      else {
     1422                        $$ = $1;
     1423                      }
    13861424                    }
    13871425                ;
     
    13921430
    13931431block_command   : block_call
    1394                 | block_call dot_or_colon operation2 command_args
     1432                | block_call call_op2 operation2 command_args
     1433                    {
     1434                      $$ = new_call(p, $1, $3, $4, $2);
     1435                    }
    13951436                ;
    13961437
     
    14171458                      $$ = new_fcall(p, $1, $2);
    14181459                    }
    1419                 | primary_value '.' operation2 command_args     %prec tLOWEST
    1420                     {
    1421                       $$ = new_call(p, $1, $3, $4);
    1422                     }
    1423                 | primary_value '.' operation2 command_args cmd_brace_block
     1460                | primary_value call_op operation2 command_args     %prec tLOWEST
     1461                    {
     1462                      $$ = new_call(p, $1, $3, $4, $2);
     1463                    }
     1464                | primary_value call_op operation2 command_args cmd_brace_block
    14241465                    {
    14251466                      args_with_block(p, $4, $5);
    1426                       $$ = new_call(p, $1, $3, $4);
     1467                      $$ = new_call(p, $1, $3, $4, $2);
    14271468                   }
    14281469                | primary_value tCOLON2 operation2 command_args %prec tLOWEST
    14291470                    {
    1430                       $$ = new_call(p, $1, $3, $4);
     1471                      $$ = new_call(p, $1, $3, $4, tCOLON2);
    14311472                    }
    14321473                | primary_value tCOLON2 operation2 command_args cmd_brace_block
    14331474                    {
    14341475                      args_with_block(p, $4, $5);
    1435                       $$ = new_call(p, $1, $3, $4);
     1476                      $$ = new_call(p, $1, $3, $4, tCOLON2);
    14361477                    }
    14371478                | keyword_super command_args
     
    15491590                | primary_value '[' opt_call_args rbracket
    15501591                    {
    1551                       $$ = new_call(p, $1, intern("[]",2), $3);
    1552                     }
    1553                 | primary_value '.' tIDENTIFIER
    1554                     {
    1555                       $$ = new_call(p, $1, $3, 0);
     1592                      $$ = new_call(p, $1, intern("[]",2), $3, '.');
     1593                    }
     1594                | primary_value call_op tIDENTIFIER
     1595                    {
     1596                      $$ = new_call(p, $1, $3, 0, $2);
    15561597                    }
    15571598                | primary_value tCOLON2 tIDENTIFIER
    15581599                    {
    1559                       $$ = new_call(p, $1, $3, 0);
    1560                     }
    1561                 | primary_value '.' tCONSTANT
    1562                     {
    1563                       $$ = new_call(p, $1, $3, 0);
     1600                      $$ = new_call(p, $1, $3, 0, tCOLON2);
     1601                    }
     1602                | primary_value call_op tCONSTANT
     1603                    {
     1604                      $$ = new_call(p, $1, $3, 0, $2);
    15641605                    }
    15651606                | primary_value tCOLON2 tCONSTANT
     
    15881629                | primary_value '[' opt_call_args rbracket
    15891630                    {
    1590                       $$ = new_call(p, $1, intern("[]",2), $3);
    1591                     }
    1592                 | primary_value '.' tIDENTIFIER
    1593                     {
    1594                       $$ = new_call(p, $1, $3, 0);
     1631                      $$ = new_call(p, $1, intern("[]",2), $3, '.');
     1632                    }
     1633                | primary_value call_op tIDENTIFIER
     1634                    {
     1635                      $$ = new_call(p, $1, $3, 0, $2);
    15951636                    }
    15961637                | primary_value tCOLON2 tIDENTIFIER
    15971638                    {
    1598                       $$ = new_call(p, $1, $3, 0);
    1599                     }
    1600                 | primary_value '.' tCONSTANT
    1601                     {
    1602                       $$ = new_call(p, $1, $3, 0);
     1639                      $$ = new_call(p, $1, $3, 0, tCOLON2);
     1640                    }
     1641                | primary_value call_op tCONSTANT
     1642                    {
     1643                      $$ = new_call(p, $1, $3, 0, $2);
    16031644                    }
    16041645                | primary_value tCOLON2 tCONSTANT
     
    16381679                | primary_value tCOLON2 cname
    16391680                    {
     1681                      void_expr_error(p, $1);
    16401682                      $$ = cons($1, nsym($3));
    16411683                    }
     
    17161758                ;
    17171759
    1718 arg             : lhs '=' arg
     1760arg             : lhs '=' arg_rhs
    17191761                    {
    17201762                      $$ = new_asgn(p, $1, $3);
    17211763                    }
    1722                 | lhs '=' arg modifier_rescue arg
    1723                     {
    1724                       $$ = new_asgn(p, $1, new_rescue(p, $3, list1(list3(0, 0, $5)), 0));
    1725                     }
    1726                 | var_lhs tOP_ASGN arg
     1764                | var_lhs tOP_ASGN arg_rhs
    17271765                    {
    17281766                      $$ = new_op_asgn(p, $1, $2, $3);
    17291767                    }
    1730                 | var_lhs tOP_ASGN arg modifier_rescue arg
    1731                     {
    1732                       $$ = new_op_asgn(p, $1, $2, new_rescue(p, $3, list1(list3(0, 0, $5)), 0));
    1733                     }
    1734                 | primary_value '[' opt_call_args rbracket tOP_ASGN arg
    1735                     {
    1736                       $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3), $5, $6);
    1737                     }
    1738                 | primary_value '.' tIDENTIFIER tOP_ASGN arg
    1739                     {
    1740                       $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5);
    1741                     }
    1742                 | primary_value '.' tCONSTANT tOP_ASGN arg
    1743                     {
    1744                       $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5);
    1745                     }
    1746                 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
    1747                     {
    1748                       $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5);
    1749                     }
    1750                 | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
     1768                | primary_value '[' opt_call_args rbracket tOP_ASGN arg_rhs
     1769                    {
     1770                      $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6);
     1771                    }
     1772                | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
     1773                    {
     1774                      $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5);
     1775                    }
     1776                | primary_value call_op tCONSTANT tOP_ASGN arg_rhs
     1777                    {
     1778                      $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5);
     1779                    }
     1780                | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
     1781                    {
     1782                      $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5);
     1783                    }
     1784                | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
    17511785                    {
    17521786                      yyerror(p, "constant re-assignment");
    17531787                      $$ = new_begin(p, 0);
    17541788                    }
    1755                 | tCOLON3 tCONSTANT tOP_ASGN arg
     1789                | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
    17561790                    {
    17571791                      yyerror(p, "constant re-assignment");
    17581792                      $$ = new_begin(p, 0);
    17591793                    }
    1760                 | backref tOP_ASGN arg
     1794                | backref tOP_ASGN arg_rhs
    17611795                    {
    17621796                      backref_error(p, $1);
     
    18971931                ;
    18981932
    1899 arg_value       : arg
    1900                     {
    1901                       $$ = $1;
    1902                       if (!$$) $$ = new_nil(p);
    1903                     }
    1904                 ;
    1905 
    19061933aref_args       : none
    19071934                | args trailer
     
    19101937                      NODE_LINENO($$, $1);
    19111938                    }
    1912                 | args ',' assocs trailer
     1939                | args comma assocs trailer
    19131940                    {
    19141941                      $$ = push($1, new_hash(p, $3));
     
    19181945                      $$ = cons(new_hash(p, $1), 0);
    19191946                      NODE_LINENO($$, $1);
     1947                    }
     1948                ;
     1949
     1950arg_rhs         : arg %prec tOP_ASGN
     1951                    {
     1952                      $$ = $1;
     1953                    }
     1954                | arg modifier_rescue arg
     1955                    {
     1956                      void_expr_error(p, $1);
     1957                      void_expr_error(p, $3);
     1958                      $$ = new_mod_rescue(p, $1, $3);
    19201959                    }
    19211960                ;
     
    19381977                      NODE_LINENO($$, $1);
    19391978                    }
    1940                 | args ',' assocs ','
     1979                | args comma assocs ','
    19411980                    {
    19421981                      $$ = cons(push($1, new_hash(p, $3)), 0);
     
    19521991call_args       : command
    19531992                    {
     1993                      void_expr_error(p, $1);
    19541994                      $$ = cons(list1($1), 0);
    19551995                      NODE_LINENO($$, $1);
     
    19652005                      NODE_LINENO($$, $1);
    19662006                    }
    1967                 | args ',' assocs opt_block_arg
     2007                | args comma assocs opt_block_arg
    19682008                    {
    19692009                      $$ = cons(push($1, new_hash(p, $3)), $4);
     
    19882028                ;
    19892029
    1990 block_arg       : tAMPER arg_value
     2030block_arg       : tAMPER arg
    19912031                    {
    19922032                      $$ = new_block_arg(p, $2);
     
    19942034                ;
    19952035
    1996 opt_block_arg   : ',' block_arg
     2036opt_block_arg   : comma block_arg
    19972037                    {
    19982038                      $$ = $2;
     
    20042044                ;
    20052045
    2006 args            : arg_value
    2007                     {
     2046comma           : ','
     2047                | ','  heredoc_bodies
     2048                ;
     2049
     2050args            : arg
     2051                    {
     2052                      void_expr_error(p, $1);
    20082053                      $$ = cons($1, 0);
    20092054                      NODE_LINENO($$, $1);
    20102055                    }
    2011                 | tSTAR arg_value
    2012                     {
     2056                | tSTAR arg
     2057                    {
     2058                      void_expr_error(p, $2);
    20132059                      $$ = cons(new_splat(p, $2), 0);
    20142060                      NODE_LINENO($$, $2);
    20152061                    }
    2016                 | args ',' arg_value
    2017                     {
     2062                | args comma arg
     2063                    {
     2064                      void_expr_error(p, $3);
    20182065                      $$ = push($1, $3);
    20192066                    }
    2020                 | args ',' tSTAR arg_value
    2021                     {
     2067                | args comma tSTAR arg
     2068                    {
     2069                      void_expr_error(p, $4);
    20222070                      $$ = push($1, new_splat(p, $4));
    20232071                    }
    2024                 | args ',' heredoc_bodies arg_value
    2025                     {
    2026                       $$ = push($1, $4);
    2027                     }
    2028                 | args ',' heredoc_bodies tSTAR arg_value
    2029                     {
    2030                       $$ = push($1, new_splat(p, $5));
    2031                     }
    2032                 ;
    2033 
    2034 mrhs            : args ',' arg_value
    2035                     {
     2072                ;
     2073
     2074mrhs            : args comma arg
     2075                    {
     2076                      void_expr_error(p, $3);
    20362077                      $$ = push($1, $3);
    20372078                    }
    2038                 | args ',' tSTAR arg_value
    2039                     {
     2079                | args comma tSTAR arg
     2080                    {
     2081                      void_expr_error(p, $4);
    20402082                      $$ = push($1, new_splat(p, $4));
    20412083                    }
    2042                 | tSTAR arg_value
    2043                     {
     2084                | tSTAR arg
     2085                    {
     2086                      void_expr_error(p, $2);
    20442087                      $$ = list1(new_splat(p, $2));
    20452088                    }
     
    20732116                      p->cmdarg_stack = 0;
    20742117                    }
    2075                   expr {p->lstate = EXPR_ENDARG;} rparen
     2118                  stmt {p->lstate = EXPR_ENDARG;} rparen
    20762119                    {
    20772120                      p->cmdarg_stack = $<stack>2;
     
    20802123                | tLPAREN_ARG {p->lstate = EXPR_ENDARG;} rparen
    20812124                    {
    2082                       $$ = 0;
     2125                      $$ = new_nil(p);
    20832126                    }
    20842127                | tLPAREN compstmt ')'
     
    21082151                      $$ = new_return(p, 0);
    21092152                    }
    2110                 | keyword_yield '(' call_args rparen
    2111                     {
    2112                       $$ = new_yield(p, $3);
    2113                     }
    2114                 | keyword_yield '(' rparen
    2115                     {
    2116                       $$ = new_yield(p, 0);
    2117                     }
    2118                 | keyword_yield
    2119                     {
    2120                       $$ = new_yield(p, 0);
     2153                | keyword_yield opt_paren_args
     2154                    {
     2155                      $$ = new_yield(p, $2);
    21212156                    }
    21222157                | keyword_not '(' expr rparen
     
    22292264                  term
    22302265                    {
    2231                       $<nd>$ = cons(local_switch(p), (node*)(intptr_t)p->in_single);
     2266                      $<nd>$ = cons(local_switch(p), nint(p->in_single));
    22322267                      p->in_single = 0;
    22332268                    }
     
    22392274                      local_resume(p, $<nd>6->car);
    22402275                      p->in_def = $<num>4;
    2241                       p->in_single = (int)(intptr_t)$<nd>6->cdr;
     2276                      p->in_single = intn($<nd>6->cdr);
    22422277                    }
    22432278                | keyword_module
     
    24332468                | f_arg ','
    24342469                    {
    2435                       $$ = new_args(p, $1, 0, 1, 0, 0);
     2470                      $$ = new_args(p, $1, 0, 0, 0, 0);
    24362471                    }
    24372472                | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg
     
    25612596                      $$ = $1;
    25622597                    }
    2563                 | block_call dot_or_colon operation2 opt_paren_args
    2564                     {
    2565                       $$ = new_call(p, $1, $3, $4);
    2566                     }
    2567                 | block_call dot_or_colon operation2 opt_paren_args brace_block
    2568                     {
    2569                       $$ = new_call(p, $1, $3, $4);
     2598                | block_call call_op2 operation2 opt_paren_args
     2599                    {
     2600                      $$ = new_call(p, $1, $3, $4, $2);
     2601                    }
     2602                | block_call call_op2 operation2 opt_paren_args brace_block
     2603                    {
     2604                      $$ = new_call(p, $1, $3, $4, $2);
    25702605                      call_with_block(p, $$, $5);
    25712606                    }
    2572                 | block_call dot_or_colon operation2 command_args do_block
    2573                     {
    2574                       $$ = new_call(p, $1, $3, $4);
     2607                | block_call call_op2 operation2 command_args do_block
     2608                    {
     2609                      $$ = new_call(p, $1, $3, $4, $2);
    25752610                      call_with_block(p, $$, $5);
    25762611                    }
     
    25812616                      $$ = new_fcall(p, $1, $2);
    25822617                    }
    2583                 | primary_value '.' operation2 opt_paren_args
    2584                     {
    2585                       $$ = new_call(p, $1, $3, $4);
     2618                | primary_value call_op operation2 opt_paren_args
     2619                    {
     2620                      $$ = new_call(p, $1, $3, $4, $2);
    25862621                    }
    25872622                | primary_value tCOLON2 operation2 paren_args
    25882623                    {
    2589                       $$ = new_call(p, $1, $3, $4);
     2624                      $$ = new_call(p, $1, $3, $4, tCOLON2);
    25902625                    }
    25912626                | primary_value tCOLON2 operation3
    25922627                    {
    2593                       $$ = new_call(p, $1, $3, 0);
    2594                     }
    2595                 | primary_value '.' paren_args
    2596                     {
    2597                       $$ = new_call(p, $1, intern("call",4), $3);
     2628                      $$ = new_call(p, $1, $3, 0, tCOLON2);
     2629                    }
     2630                | primary_value call_op paren_args
     2631                    {
     2632                      $$ = new_call(p, $1, intern("call",4), $3, $2);
    25982633                    }
    25992634                | primary_value tCOLON2 paren_args
    26002635                    {
    2601                       $$ = new_call(p, $1, intern("call",4), $3);
     2636                      $$ = new_call(p, $1, intern("call",4), $3, tCOLON2);
    26022637                    }
    26032638                | keyword_super paren_args
     
    26112646                | primary_value '[' opt_call_args rbracket
    26122647                    {
    2613                       $$ = new_call(p, $1, intern("[]",2), $3);
     2648                      $$ = new_call(p, $1, intern("[]",2), $3, '.');
    26142649                    }
    26152650                ;
     
    26712706                ;
    26722707
    2673 exc_list        : arg_value
     2708exc_list        : arg
    26742709                    {
    26752710                        $$ = list1($1);
     
    27662801                ;
    27672802
    2768 opt_heredoc_bodies : /* none */
    2769                    | heredoc_bodies
    2770                    ;
    2771 
    27722803heredoc_bodies  : heredoc_body
    27732804                | heredoc_bodies heredoc_body
     
    28252856                      $$ = new_sym(p, $1);
    28262857                    }
    2827                 | tSYMBEG tSTRING_BEG string_interp tSTRING
     2858                | tSYMBEG tSTRING_BEG string_rep tSTRING
    28282859                    {
    28292860                      p->lstate = EXPR_END;
     
    29252956                | keyword__FILE__
    29262957                    {
    2927                       if (!p->filename) {
    2928                         p->filename = "(null)";
     2958                      const char *fn = p->filename;
     2959                      if (!fn) {
     2960                        fn = "(null)";
    29292961                      }
    2930                       $$ = new_str(p, p->filename, strlen(p->filename));
     2962                      $$ = new_str(p, fn, strlen(fn));
    29312963                    }
    29322964                | keyword__LINE__
     
    29552987                    {
    29562988                      $$ = $3;
    2957                     } /* 
     2989                    } /*
    29582990                | error term
    29592991                    {
     
    30983130                ;
    30993131
    3100 f_opt           : f_opt_asgn arg_value
    3101                     {
     3132f_opt           : f_opt_asgn arg
     3133                    {
     3134                      void_expr_error(p, $2);
    31023135                      $$ = cons(nsym($1), $2);
    31033136                    }
     
    31063139f_block_opt     : f_opt_asgn primary_value
    31073140                    {
     3141                      void_expr_error(p, $2);
    31083142                      $$ = cons(nsym($1), $2);
    31093143                    }
     
    31793213                      }
    31803214                      else {
    3181                         switch ((enum node_type)(int)(intptr_t)$3->car) {
     3215                        switch ((enum node_type)intn($3->car)) {
    31823216                        case NODE_STR:
    31833217                        case NODE_DSTR:
     
    32163250                ;
    32173251
    3218 assoc           : arg_value tASSOC arg_value
    3219                     {
     3252assoc           : arg tASSOC arg
     3253                    {
     3254                      void_expr_error(p, $1);
     3255                      void_expr_error(p, $3);
    32203256                      $$ = cons($1, $3);
    32213257                    }
    3222                 | tLABEL arg_value
    3223                     {
     3258                | tLABEL arg
     3259                    {
     3260                      void_expr_error(p, $2);
    32243261                      $$ = cons(new_sym(p, $1), $2);
     3262                    }
     3263                | tLABEL_END arg
     3264                    {
     3265                      void_expr_error(p, $2);
     3266                      $$ = cons(new_sym(p, new_strsym(p, $1)), $2);
     3267                    }
     3268                | tSTRING_BEG tLABEL_END arg
     3269                    {
     3270                      void_expr_error(p, $3);
     3271                      $$ = cons(new_sym(p, new_strsym(p, $2)), $3);
     3272                    }
     3273                | tSTRING_BEG string_rep tLABEL_END arg
     3274                    {
     3275                      void_expr_error(p, $4);
     3276                      $$ = cons(new_dsym(p, push($2, $3)), $4);
    32253277                    }
    32263278                ;
     
    32463298                ;
    32473299
     3300call_op         : '.'
     3301                    {
     3302                      $$ = '.';
     3303                    }
     3304                | tANDDOT
     3305                    {
     3306                      $$ = 0;
     3307                    }
     3308                ;
     3309
     3310call_op2        : call_op
     3311                | tCOLON2
     3312                    {
     3313                      $$ = tCOLON2;
     3314                    }
     3315                ;
     3316
    32483317opt_terms       : /* none */
    32493318                | terms
     
    32623331trailer         : /* none */
    32633332                | nl
    3264                 | ','
     3333                | comma
    32653334                ;
    32663335
    32673336term            : ';' {yyerrok;}
    32683337                | nl
     3338                | heredoc_body
    32693339                ;
    32703340
     
    32743344                      p->column = 0;
    32753345                    }
    3276                   opt_heredoc_bodies
     3346                ;
    32773347
    32783348terms           : term
    3279                 | terms ';' {yyerrok;}
     3349                | terms term
    32803350                ;
    32813351
     
    32863356                ;
    32873357%%
    3288 #define yylval  (*((YYSTYPE*)(p->ylval)))
     3358#define pylval  (*((YYSTYPE*)(p->ylval)))
    32893359
    32903360static void
     
    33743444
    33753445  if (c == NODE_NTH_REF) {
    3376     yyerror_i(p, "can't set variable $%d", (int)(intptr_t)n->cdr);
     3446    yyerror_i(p, "can't set variable $%" MRB_PRId, (mrb_int)(intptr_t)n->cdr);
    33773447  }
    33783448  else if (c == NODE_BACK_REF) {
     
    33813451  else {
    33823452    mrb_bug(p->mrb, "Internal error in backref_error() : n=>car == %S", mrb_fixnum_value(c));
     3453  }
     3454}
     3455
     3456static void
     3457void_expr_error(parser_state *p, node *n)
     3458{
     3459  int c;
     3460
     3461  if (n == NULL) return;
     3462  c = (int)(intptr_t)n->car;
     3463  switch (c) {
     3464  case NODE_BREAK:
     3465  case NODE_RETURN:
     3466  case NODE_NEXT:
     3467  case NODE_REDO:
     3468  case NODE_RETRY:
     3469    yyerror(p, "void value expression");
     3470    break;
     3471  case NODE_AND:
     3472  case NODE_OR:
     3473    void_expr_error(p, n->cdr->car);
     3474    void_expr_error(p, n->cdr->cdr);
     3475    break;
     3476  case NODE_BEGIN:
     3477    if (n->cdr) {
     3478      while (n->cdr) {
     3479        n = n->cdr;
     3480      }
     3481      void_expr_error(p, n->car);
     3482    }
     3483    break;
     3484  default:
     3485    break;
    33833486  }
    33843487}
     
    34693572    c0 = nextc(p);
    34703573    if (c0 == -1) return c0;    /* do not skip partial EOF */
     3574    if (c0 >= 0) --p->column;
    34713575    list = push(list, (node*)(intptr_t)c0);
    34723576  } while(n--);
     
    35173621    for (;;) {
    35183622      c = nextc(p);
    3519       if (c < 0) return c;
     3623      if (c < 0) return FALSE;
    35203624      if (c == '\n') {
    35213625        p->lineno++;
     
    35473651newtok(parser_state *p)
    35483652{
    3549   p->bidx = 0;
     3653  if (p->tokbuf != p->buf) {
     3654    mrb_free(p->mrb, p->tokbuf);
     3655    p->tokbuf = p->buf;
     3656    p->tsiz = MRB_PARSER_TOKBUF_SIZE;
     3657  }
     3658  p->tidx = 0;
    35503659  return p->column - 1;
    35513660}
     
    35553664{
    35563665  char utf8[4];
    3557   unsigned len;
     3666  int i, len;
    35583667
    35593668  /* mrb_assert(-0x10FFFF <= c && c <= 0xFF); */
     
    35893698    }
    35903699  }
    3591   if (p->bidx+len <= MRB_PARSER_BUF_SIZE) {
    3592     unsigned i;
    3593     for (i = 0; i < len; i++) {
    3594       p->buf[p->bidx++] = utf8[i];
    3595     }
     3700  if (p->tidx+len >= p->tsiz) {
     3701    if (p->tsiz >= MRB_PARSER_TOKBUF_MAX) {
     3702      p->tidx += len;
     3703      return;
     3704    }
     3705    p->tsiz *= 2;
     3706    if (p->tokbuf == p->buf) {
     3707      p->tokbuf = (char*)mrb_malloc(p->mrb, p->tsiz);
     3708      memcpy(p->tokbuf, p->buf, MRB_PARSER_TOKBUF_SIZE);
     3709    }
     3710    else {
     3711      p->tokbuf = (char*)mrb_realloc(p->mrb, p->tokbuf, p->tsiz);
     3712    }
     3713  }
     3714  for (i = 0; i < len; i++) {
     3715    p->tokbuf[p->tidx++] = utf8[i];
    35963716  }
    35973717}
     
    36003720toklast(parser_state *p)
    36013721{
    3602   return p->buf[p->bidx-1];
     3722  return p->tokbuf[p->tidx-1];
    36033723}
    36043724
     
    36063726tokfix(parser_state *p)
    36073727{
    3608   int i = p->bidx, imax = MRB_PARSER_BUF_SIZE - 1;
    3609 
    3610   if (i > imax) {
    3611     i = imax;
     3728  if (p->tidx >= MRB_PARSER_TOKBUF_MAX) {
     3729    p->tidx = MRB_PARSER_TOKBUF_MAX-1;
    36123730    yyerror(p, "string too long (truncated)");
    36133731  }
    3614   p->buf[i] = '\0';
     3732  p->tokbuf[p->tidx] = '\0';
    36153733}
    36163734
     
    36183736tok(parser_state *p)
    36193737{
    3620   return p->buf;
     3738  return p->tokbuf;
    36213739}
    36223740
     
    36243742toklen(parser_state *p)
    36253743{
    3626   return p->bidx;
     3744  return p->tidx;
    36273745}
    36283746
     
    36673785
    36683786  return retval;
     3787}
     3788
     3789static int32_t
     3790read_escape_unicode(parser_state *p, int limit)
     3791{
     3792  int32_t c;
     3793  int buf[9];
     3794  int i;
     3795
     3796  /* Look for opening brace */
     3797  i = 0;
     3798  buf[0] = nextc(p);
     3799  if (buf[0] < 0) goto eof;
     3800  if (ISXDIGIT(buf[0])) {
     3801    /* \uxxxx form */
     3802    for (i=1; i<limit; i++) {
     3803      buf[i] = nextc(p);
     3804      if (buf[i] < 0) goto eof;
     3805      if (!ISXDIGIT(buf[i])) {
     3806        pushback(p, buf[i]);
     3807        break;
     3808      }
     3809    }
     3810  }
     3811  else {
     3812    pushback(p, buf[0]);
     3813  }
     3814  c = scan_hex(buf, i, &i);
     3815  if (i == 0) {
     3816  eof:
     3817    yyerror(p, "Invalid escape character syntax");
     3818    return -1;
     3819  }
     3820  if (c < 0 || c > 0x10FFFF || (c & 0xFFFFF800) == 0xD800) {
     3821    yyerror(p, "Invalid Unicode code point");
     3822    return -1;
     3823  }
     3824  return c;
    36693825}
    36703826
     
    37413897
    37423898  case 'u':     /* Unicode */
    3743   {
    3744     int buf[9];
    3745     int i;
    3746 
    3747     /* Look for opening brace */
    3748     i = 0;
    3749     buf[0] = nextc(p);
    3750     if (buf[0] < 0) goto eof;
    3751     if (buf[0] == '{') {
     3899    if (peek(p, '{')) {
    37523900      /* \u{xxxxxxxx} form */
    3753       for (i=0; i<9; i++) {
    3754         buf[i] = nextc(p);
    3755         if (buf[i] < 0) goto eof;
    3756         if (buf[i] == '}') {
    3757           break;
    3758         }
    3759         else if (!ISXDIGIT(buf[i])) {
    3760           yyerror(p, "Invalid escape character syntax");
    3761           pushback(p, buf[i]);
    3762           return 0;
    3763         }
    3764       }
    3765     }
    3766     else if (ISXDIGIT(buf[0])) {
    3767       /* \uxxxx form */
    3768       for (i=1; i<4; i++) {
    3769         buf[i] = nextc(p);
    3770         if (buf[i] < 0) goto eof;
    3771         if (!ISXDIGIT(buf[i])) {
    3772           pushback(p, buf[i]);
    3773           break;
    3774         }
    3775       }
     3901      nextc(p);
     3902      c = read_escape_unicode(p, 8);
     3903      if (c < 0) return 0;
     3904      if (nextc(p) != '}') goto eof;
    37763905    }
    37773906    else {
    3778       pushback(p, buf[0]);
    3779     }
    3780     c = scan_hex(buf, i, &i);
    3781     if (i == 0) {
    3782       yyerror(p, "Invalid escape character syntax");
    3783       return 0;
    3784     }
    3785     if (c < 0 || c > 0x10FFFF || (c & 0xFFFFF800) == 0xD800) {
    3786       yyerror(p, "Invalid Unicode code point");
    3787       return 0;
    3788     }
    3789   }
     3907      c = read_escape_unicode(p, 4);
     3908      if (c < 0) return 0;
     3909    }
    37903910  return -c;
    37913911
     
    38453965  int end = (intptr_t)p->lex_strterm->cdr->cdr->cdr;
    38463966  parser_heredoc_info *hinf = (type & STR_FUNC_HEREDOC) ? parsing_heredoc_inf(p) : NULL;
    3847 
     3967  int cmd_state = p->cmd_start;
     3968
     3969  if (beg == 0) beg = -3;       /* should never happen */
     3970  if (end == 0) end = -3;
    38483971  newtok(p);
    38493972  while ((c = nextc(p)) != end || nest_level != 0) {
     
    38673990        }
    38683991        if ((len-1 == hinf->term_len) && (strncmp(s, hinf->term, len-1) == 0)) {
    3869           return tHEREDOC_END;
     3992          if (c < 0) {
     3993            p->parsing_heredoc = NULL;
     3994          }
     3995          else {
     3996            return tHEREDOC_END;
     3997          }
    38703998        }
    38713999      }
     
    38764004        return 0;
    38774005      }
    3878       yylval.nd = new_str(p, tok(p), toklen(p));
     4006      pylval.nd = new_str(p, tok(p), toklen(p));
    38794007      return tHD_STRING_MID;
    38804008    }
     
    39084036          tokadd(p, c);
    39094037        }
     4038        else if (c == 'u' && peek(p, '{')) {
     4039          /* \u{xxxx xxxx xxxx} form */
     4040          nextc(p);
     4041          while (1) {
     4042            do c = nextc(p); while (ISSPACE(c));
     4043            if (c == '}') break;
     4044            pushback(p, c);
     4045            c = read_escape_unicode(p, 8);
     4046            if (c < 0) break;
     4047            tokadd(p, -c);
     4048          }
     4049          if (hinf)
     4050            hinf->line_head = FALSE;
     4051        }
    39104052        else {
    39114053          pushback(p, c);
     
    39354077        p->lstate = EXPR_BEG;
    39364078        p->cmd_start = TRUE;
    3937         yylval.nd = new_str(p, tok(p), toklen(p));
     4079        pylval.nd = new_str(p, tok(p), toklen(p));
    39384080        if (hinf) {
    39394081          hinf->line_head = FALSE;
     
    39654107        pushback(p, c);
    39664108        tokfix(p);
    3967         yylval.nd = new_str(p, tok(p), toklen(p));
     4109        pylval.nd = new_str(p, tok(p), toklen(p));
    39684110        return tSTRING_MID;
    39694111      }
     4112    }
     4113    if (c == '\n') {
     4114      p->lineno++;
     4115      p->column = 0;
    39704116    }
    39714117    tokadd(p, c);
     
    39774123
    39784124  if (type & STR_FUNC_XQUOTE) {
    3979     yylval.nd = new_xstr(p, tok(p), toklen(p));
     4125    pylval.nd = new_xstr(p, tok(p), toklen(p));
    39804126    return tXSTRING;
    39814127  }
     
    40194165    if (flag > flags) {
    40204166      dup = strndup(flags, (size_t)(flag - flags));
    4021     } else {
     4167    }
     4168    else {
    40224169      dup = NULL;
    40234170    }
    40244171    if (enc) {
    40254172      encp = strndup(&enc, 1);
    4026     } else {
     4173    }
     4174    else {
    40274175      encp = NULL;
    40284176    }
    4029     yylval.nd = new_regx(p, s, dup, encp);
     4177    pylval.nd = new_regx(p, s, dup, encp);
    40304178
    40314179    return tREGEXP;
    40324180  }
    4033 
    4034   yylval.nd = new_str(p, tok(p), toklen(p));
     4181  pylval.nd = new_str(p, tok(p), toklen(p));
     4182  if (IS_LABEL_POSSIBLE()) {
     4183    if (IS_LABEL_SUFFIX(0)) {
     4184      p->lstate = EXPR_BEG;
     4185      nextc(p);
     4186      return tLABEL_END;
     4187    }
     4188  }
     4189
    40354190  return tSTRING;
    40364191}
     
    41024257  p->lstate = EXPR_END;
    41034258
    4104   yylval.nd = newnode;
     4259  pylval.nd = newnode;
    41054260  return tHEREDOC_BEG;
    41064261}
     
    42064361    if ((c = nextc(p)) == '*') {
    42074362      if ((c = nextc(p)) == '=') {
    4208         yylval.id = intern("**",2);
     4363        pylval.id = intern("**",2);
    42094364        p->lstate = EXPR_BEG;
    42104365        return tOP_ASGN;
     
    42154370    else {
    42164371      if (c == '=') {
    4217         yylval.id = intern_c('*');
     4372        pylval.id = intern_c('*');
    42184373        p->lstate = EXPR_BEG;
    42194374        return tOP_ASGN;
     
    43314486    if (c == '<') {
    43324487      if ((c = nextc(p)) == '=') {
    4333         yylval.id = intern("<<",2);
     4488        pylval.id = intern("<<",2);
    43344489        p->lstate = EXPR_BEG;
    43354490        return tOP_ASGN;
     
    43534508    if (c == '>') {
    43544509      if ((c = nextc(p)) == '=') {
    4355         yylval.id = intern(">>",2);
     4510        pylval.id = intern(">>",2);
    43564511        p->lstate = EXPR_BEG;
    43574512        return tOP_ASGN;
     
    44504605    }
    44514606    tokfix(p);
    4452     yylval.nd = new_str(p, tok(p), toklen(p));
     4607    pylval.nd = new_str(p, tok(p), toklen(p));
    44534608    p->lstate = EXPR_END;
    44544609    return tCHAR;
     
    44584613      p->lstate = EXPR_BEG;
    44594614      if ((c = nextc(p)) == '=') {
    4460         yylval.id = intern("&&",2);
     4615        pylval.id = intern("&&",2);
    44614616        p->lstate = EXPR_BEG;
    44624617        return tOP_ASGN;
     
    44654620      return tANDOP;
    44664621    }
     4622    else if (c == '.') {
     4623      p->lstate = EXPR_DOT;
     4624      return tANDDOT;
     4625    }
    44674626    else if (c == '=') {
    4468       yylval.id = intern_c('&');
     4627      pylval.id = intern_c('&');
    44694628      p->lstate = EXPR_BEG;
    44704629      return tOP_ASGN;
     
    44934652      p->lstate = EXPR_BEG;
    44944653      if ((c = nextc(p)) == '=') {
    4495         yylval.id = intern("||",2);
     4654        pylval.id = intern("||",2);
    44964655        p->lstate = EXPR_BEG;
    44974656        return tOP_ASGN;
     
    45014660    }
    45024661    if (c == '=') {
    4503       yylval.id = intern_c('|');
     4662      pylval.id = intern_c('|');
    45044663      p->lstate = EXPR_BEG;
    45054664      return tOP_ASGN;
     
    45254684    }
    45264685    if (c == '=') {
    4527       yylval.id = intern_c('+');
     4686      pylval.id = intern_c('+');
    45284687      p->lstate = EXPR_BEG;
    45294688      return tOP_ASGN;
     
    45534712    }
    45544713    if (c == '=') {
    4555       yylval.id = intern_c('-');
     4714      pylval.id = intern_c('-');
    45564715      p->lstate = EXPR_BEG;
    45574716      return tOP_ASGN;
     
    46274786        }
    46284787        else if (nondigit) goto trailing_uc;
    4629         yylval.nd = new_int(p, tok(p), 16);
     4788        pylval.nd = new_int(p, tok(p), 16);
    46304789        return tINTEGER;
    46314790      }
     
    46514810        }
    46524811        else if (nondigit) goto trailing_uc;
    4653         yylval.nd = new_int(p, tok(p), 2);
     4812        pylval.nd = new_int(p, tok(p), 2);
    46544813        return tINTEGER;
    46554814      }
     
    46754834        }
    46764835        else if (nondigit) goto trailing_uc;
    4677         yylval.nd = new_int(p, tok(p), 10);
     4836        pylval.nd = new_int(p, tok(p), 10);
    46784837        return tINTEGER;
    46794838      }
     
    47084867          tokfix(p);
    47094868          if (nondigit) goto trailing_uc;
    4710           yylval.nd = new_int(p, tok(p), 8);
     4869          pylval.nd = new_int(p, tok(p), 8);
    47114870          return tINTEGER;
    47124871        }
     
    47254884      else {
    47264885        pushback(p, c);
    4727         yylval.nd = new_int(p, "0", 10);
     4886        pylval.nd = new_int(p, "0", 10);
    47284887        return tINTEGER;
    47294888      }
     
    48014960
    48024961      errno = 0;
    4803       d = strtod(tok(p), &endp);
     4962      d = mrb_float_read(tok(p), &endp);
    48044963      if (d == 0 && endp == tok(p)) {
    48054964        yywarning_s(p, "corrupted float value %s", tok(p));
     
    48094968        errno = 0;
    48104969      }
    4811       yylval.nd = new_float(p, tok(p));
     4970      pylval.nd = new_float(p, tok(p));
    48124971      return tFLOAT;
    48134972    }
    4814     yylval.nd = new_int(p, tok(p), 10);
     4973    pylval.nd = new_int(p, tok(p), 10);
    48154974    return tINTEGER;
    48164975  }
     
    48545013    }
    48555014    if ((c = nextc(p)) == '=') {
    4856       yylval.id = intern_c('/');
     5015      pylval.id = intern_c('/');
    48575016      p->lstate = EXPR_BEG;
    48585017      return tOP_ASGN;
     
    48735032  case '^':
    48745033    if ((c = nextc(p)) == '=') {
    4875       yylval.id = intern_c('^');
     5034      pylval.id = intern_c('^');
    48765035      p->lstate = EXPR_BEG;
    48775036      return tOP_ASGN;
     
    50475206    }
    50485207    if ((c = nextc(p)) == '=') {
    5049       yylval.id = intern_c('%');
     5208      pylval.id = intern_c('%');
    50505209      p->lstate = EXPR_BEG;
    50515210      return tOP_ASGN;
     
    51015260      tokadd(p, c);
    51025261      tokfix(p);
    5103       yylval.id = intern_cstr(tok(p));
     5262      pylval.id = intern_cstr(tok(p));
    51045263      return tGVAR;
    51055264
     
    51115270      gvar:
    51125271      tokfix(p);
    5113       yylval.id = intern_cstr(tok(p));
     5272      pylval.id = intern_cstr(tok(p));
    51145273      return tGVAR;
    51155274
     
    51235282        goto gvar;
    51245283      }
    5125       yylval.nd = new_back_ref(p, c);
     5284      pylval.nd = new_back_ref(p, c);
    51265285      return tBACK_REF;
    51275286
     
    51425301          return 0;
    51435302        }
    5144         yylval.nd = new_nth_ref(p, (int)n);
     5303        pylval.nd = new_nth_ref(p, (int)n);
    51455304      }
    51465305      return tNTH_REF;
     
    51665325      }
    51675326      if (c < 0) {
    5168         if (p->bidx == 1) {
     5327        if (p->tidx == 1) {
    51695328          yyerror(p, "incomplete instance variable syntax");
    51705329        }
     
    51755334      }
    51765335      else if (isdigit(c)) {
    5177         if (p->bidx == 1) {
     5336        if (p->tidx == 1) {
    51785337          yyerror_i(p, "'@%c' is not allowed as an instance variable name", c);
    51795338        }
     
    52705429          nextc(p);
    52715430          tokfix(p);
    5272           yylval.id = intern_cstr(tok(p));
     5431          pylval.id = intern_cstr(tok(p));
    52735432          return tLABEL;
    52745433        }
     
    52815440        if (kw) {
    52825441          enum mrb_lex_state_enum state = p->lstate;
    5283           yylval.num = p->lineno;
     5442          pylval.num = p->lineno;
    52845443          p->lstate = kw->state;
    52855444          if (state == EXPR_FNAME) {
    5286             yylval.id = intern_cstr(kw->name);
     5445            pylval.id = intern_cstr(kw->name);
    52875446            return kw->id[0];
    52885447          }
     
    53315490      mrb_sym ident = intern_cstr(tok(p));
    53325491
    5333       yylval.id = ident;
     5492      pylval.id = ident;
    53345493#if 0
    53355494      if (last_state != EXPR_DOT && islower(tok(p)[0]) && lvar_defined(ident)) {
     
    53965555mrb_parser_parse(parser_state *p, mrbc_context *c)
    53975556{
    5398   struct mrb_jmpbuf buf;
    5399   p->jmp = &buf;
     5557  struct mrb_jmpbuf buf1;
     5558  p->jmp = &buf1;
    54005559
    54015560  MRB_TRY(p->jmp) {
     5561    int n;
    54025562
    54035563    p->cmd_start = TRUE;
     
    54075567
    54085568    parser_init_cxt(p, c);
    5409     yyparse(p);
     5569
     5570    if (p->mrb->jmp) {
     5571      n = yyparse(p);
     5572    }
     5573    else {
     5574      struct mrb_jmpbuf buf2;
     5575
     5576      p->mrb->jmp = &buf2;
     5577      MRB_TRY(p->mrb->jmp) {
     5578        n = yyparse(p);
     5579      }
     5580      MRB_CATCH(p->mrb->jmp) {
     5581        p->nerr++;
     5582      }
     5583      MRB_END_EXC(p->mrb->jmp);
     5584      p->mrb->jmp = 0;
     5585    }
     5586    if (n != 0 || p->nerr > 0) {
     5587      p->tree = 0;
     5588      return;
     5589    }
    54105590    if (!p->tree) {
    54115591      p->tree = new_nil(p);
     
    54155595      mrb_parser_dump(p->mrb, p->tree, 0);
    54165596    }
    5417 
    54185597  }
    54195598  MRB_CATCH(p->jmp) {
     
    54435622
    54445623  p->s = p->send = NULL;
    5445 #ifndef MRB_DISBLE_STDIO
     5624#ifndef MRB_DISABLE_STDIO
    54465625  p->f = NULL;
    54475626#endif
     
    54565635  yydebug = 1;
    54575636#endif
     5637  p->tsiz = MRB_PARSER_TOKBUF_SIZE;
     5638  p->tokbuf = p->buf;
    54585639
    54595640  p->lex_strterm = NULL;
     
    54705651MRB_API void
    54715652mrb_parser_free(parser_state *p) {
     5653  if (p->tokbuf != p->buf) {
     5654    mrb_free(p->mrb, p->tokbuf);
     5655  }
    54725656  mrb_pool_close(p->pool);
    54735657}
     
    54825666mrbc_context_free(mrb_state *mrb, mrbc_context *cxt)
    54835667{
     5668  mrb_free(mrb, cxt->filename);
    54845669  mrb_free(mrb, cxt->syms);
    54855670  mrb_free(mrb, cxt);
     
    54915676  if (s) {
    54925677    int len = strlen(s);
    5493     char *p = (char *)mrb_alloca(mrb, len + 1);
     5678    char *p = (char *)mrb_malloc(mrb, len + 1);
    54945679
    54955680    memcpy(p, s, len + 1);
     5681    if (c->filename) {
     5682      mrb_free(mrb, c->filename);
     5683    }
    54965684    c->filename = p;
    54975685  }
     
    55785766}
    55795767
    5580 static mrb_value
    5581 load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c)
     5768MRB_API mrb_value
     5769mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
    55825770{
    55835771  struct RClass *target = mrb->object_class;
     
    56015789    }
    56025790    else {
    5603       mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error"));
     5791      if (mrb->exc == NULL) {
     5792        mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error"));
     5793      }
    56045794      mrb_parser_free(p);
    56055795      return mrb_undef_value();
     
    56095799  mrb_parser_free(p);
    56105800  if (proc == NULL) {
    5611     mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error"));
     5801    if (mrb->exc == NULL) {
     5802      mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error"));
     5803    }
    56125804    return mrb_undef_value();
    56135805  }
     
    56295821    mrb->c->ci->target_class = target;
    56305822  }
    5631   v = mrb_toplevel_run_keep(mrb, proc, keep);
     5823  v = mrb_top_run(mrb, proc, mrb_top_self(mrb), keep);
    56325824  if (mrb->exc) return mrb_nil_value();
    56335825  return v;
     
    56385830mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c)
    56395831{
    5640   return load_exec(mrb, mrb_parse_file(mrb, f, c), c);
     5832  return mrb_load_exec(mrb, mrb_parse_file(mrb, f, c), c);
    56415833}
    56425834
     
    56515843mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *c)
    56525844{
    5653   return load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c);
     5845  return mrb_load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c);
    56545846}
    56555847
     
    58055997        dump_recur(mrb, n->car, offset+2);
    58065998      }
    5807       n = n->cdr;
    5808       if (n) {
     5999      if (n->cdr) {
    58096000        dump_prefix(n, offset+1);
    5810         printf("blk=&%s\n", mrb_sym2name(mrb, sym(n)));
     6001        printf("blk=&%s\n", mrb_sym2name(mrb, sym(n->cdr)));
    58116002      }
    58126003    }
     
    59466137  case NODE_FCALL:
    59476138  case NODE_CALL:
    5948     printf("NODE_CALL:\n");
     6139  case NODE_SCALL:
     6140    switch (nodetype) {
     6141    case NODE_FCALL:
     6142      printf("NODE_FCALL:\n"); break;
     6143    case NODE_CALL:
     6144      printf("NODE_CALL(.):\n"); break;
     6145    case NODE_SCALL:
     6146      printf("NODE_SCALL(&.):\n"); break;
     6147    default:
     6148      break;
     6149    }
    59496150    mrb_parser_dump(mrb, tree->car, offset+1);
    59506151    dump_prefix(tree, offset+1);
     
    61546355
    61556356  case NODE_NTH_REF:
    6156     printf("NODE_NTH_REF: $%d\n", (int)(intptr_t)tree);
     6357    printf("NODE_NTH_REF: $%" MRB_PRId "\n", (mrb_int)(intptr_t)tree);
    61576358    break;
    61586359
     
    62066407    dump_prefix(tree, offset);
    62076408    printf("tail: %s\n", (char*)tree->cdr->cdr->car);
    6208     dump_prefix(tree, offset);
    6209     printf("opt: %s\n", (char*)tree->cdr->cdr->cdr);
     6409    if (tree->cdr->cdr->cdr->car) {
     6410      dump_prefix(tree, offset);
     6411      printf("opt: %s\n", (char*)tree->cdr->cdr->cdr->car);
     6412    }
     6413    if (tree->cdr->cdr->cdr->cdr) {
     6414      dump_prefix(tree, offset);
     6415      printf("enc: %s\n", (char*)tree->cdr->cdr->cdr->cdr);
     6416    }
    62106417    break;
    62116418
    62126419  case NODE_SYM:
    6213     printf("NODE_SYM :%s\n", mrb_sym2name(mrb, sym(tree)));
     6420    printf("NODE_SYM :%s (%d)\n", mrb_sym2name(mrb, sym(tree)),
     6421           (int)(intptr_t)tree);
    62146422    break;
    62156423
     
    64256633
    64266634  case NODE_HEREDOC:
    6427     printf("NODE_HEREDOC:\n");
    6428     mrb_parser_dump(mrb, ((parser_heredoc_info*)tree)->doc, offset+1);
     6635    printf("NODE_HEREDOC (<<%s):\n", ((parser_heredoc_info*)tree)->term);
     6636    dump_recur(mrb, ((parser_heredoc_info*)tree)->doc, offset+1);
    64296637    break;
    64306638
Note: See TracChangeset for help on using the changeset viewer.