X-Git-Url: http://nitlanguage.org diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index c0a9fd6..d7380c5 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -47,8 +47,8 @@ eol_helper = cr lf | cr | lf; // This takes care of different platforms // characers inside strings and super-strings (atomaton powaa) str_char - = [any - [['"' + '{'] + '\']] - | '\' any + = [any - [['"' + '{'] + '\']] + | '\' any ; str_body = str_char*; @@ -115,6 +115,7 @@ kwclass = 'class'; kwabstract = 'abstract'; kwinterface = 'interface'; kwenum = 'universal'|'enum'; +kwsubset = 'subset'; kwend = 'end'; kwmeth = 'fun'; kwtype = 'type'; @@ -159,6 +160,7 @@ kwlabel = 'label'; kwwith = 'with'; kwdebug = '__debug__'; kwyield = 'yield'; +kwcatch = 'catch'; opar = '('; cpar = ')'; @@ -202,6 +204,7 @@ ge = '>='; gg = '>>'; starship = '<=>'; bang='!'; +quest='?'; at='@'; semi=';'; @@ -216,10 +219,12 @@ start_string = id? '"' str_body '{' | id? '"' '"' '"' long_str_body lsend2; mid_string = '}' str_body '{' | '}' '}' '}' long_str_body lsend2; end_string = '}' str_body '"' id? | '}' '}' '}' long_str_body lsend1 id? ; char = id? ((''' [[any - '''] - '\'] ''') | (''' '\' any ''')) id?; -bad_string = ('"'|'}') str_body | '"' '"' '"' long_str_body | ''' ''' ''' long_sstr_body; +bad_string = ('"'|'}') str_body ; +bad_t_string = '"' '"' '"' long_str_body | ''' ''' ''' long_sstr_body; bad_char = ''' '\'? any; extern_code_segment = '`' '{' extern_code_body '`' '}'; +bad_extern = '`' '{' extern_code_body; /*****************************************************************************/ Ignored Tokens @@ -271,6 +276,7 @@ classkind | {interface} kwinterface | {enum} kwenum | {extern} kwextern kwclass + | {subset} kwsubset ; formaldefs {-> formaldef*} @@ -295,17 +301,18 @@ propdefn {-> propdef} = propdef n1 {-> propdef.propdef} ; propdef~toplevel {-> propdef} - = {meth} [doc]:nd redef visibility kwmeth qmethid signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, qmethid.methid, signature, annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)} - | {nobody} [doc]:nd redef visibility kwmeth qmethid signature annotation_withend_nonull {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, qmethid.methid, signature.signature, annotation_withend_nonull.annotations, Null, Null, Null, Null, Null)} -!toplevel| {intern_new} [doc]:nd redef visibility kwnew qmethid? signature annotation_withend_nonull {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_withend_nonull.annotations, Null, Null, Null, Null, Null)} -!toplevel| {new} [doc]:nd redef visibility kwnew qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)} - | {extern_implicit} [doc]:nd redef visibility kwmeth qmethid signature annotation_noend? extern_calls extern_code_block {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, qmethid.methid, signature.signature, annotation_noend.annotations, extern_calls, extern_code_block, Null, Null, Null)} + = {meth} [doc]:nd redef visibility kwmeth qmethid signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, Null, qmethid.methid, signature, annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)} + | {nobody} [doc]:nd redef visibility kwmeth qmethid signature annotation_withend_nonull {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, Null, qmethid.methid, signature.signature, annotation_withend_nonull.annotations, Null, Null, Null, Null, Null)} +!toplevel| {isa} [doc]:nd redef visibility kwisa annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwisa, Null, Null, New signature(Null, [], Null, Null), annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)} +!toplevel| {intern_new} [doc]:nd redef visibility kwnew qmethid? signature annotation_withend_nonull {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, Null, kwnew, qmethid.methid, signature, annotation_withend_nonull.annotations, Null, Null, Null, Null, Null)} +!toplevel| {new} [doc]:nd redef visibility kwnew qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)} + | {extern_implicit} [doc]:nd redef visibility kwmeth qmethid signature annotation_noend? extern_calls extern_code_block {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, Null, qmethid.methid, signature.signature, annotation_noend.annotations, extern_calls, extern_code_block, Null, Null, Null)} !toplevel| {var3} [doc]:nd redef visibility kwvar id typing_o annotation_withend {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, Null, Null, annotation_withend.annotations, Null, Null, Null)} !toplevel| {var4} [doc]:nd redef visibility kwvar id typing_o assign [n2]:no expr annotation_withend {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, assign, expr.expr, annotation_withend.annotations, Null, Null, Null)} !toplevel| {var5} [doc]:nd redef visibility kwvar id typing_o annotation_noend? kwdo stmtso kwend? {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, Null, Null, annotation_noend.annotations, kwdo, stmtso.expr, kwend)} -!toplevel| {init} [doc]:nd redef visibility kwinit qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, kwinit, Null, qmethid.methid, signature, annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)} +!toplevel| {init} [doc]:nd redef visibility kwinit qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, kwinit, Null, Null, qmethid.methid, signature, annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)} !toplevel| {type} [doc]:nd redef visibility kwtype qclassid typing annotation_withend {-> New propdef.type(doc.doc, redef.kwredef, visibility, kwtype, qclassid, typing.type, annotation_withend.annotations)} -!toplevel| {extern_init_implicit} [doc]:nd redef visibility kwnew qmethid? signature annotation_noend? extern_calls extern_code_block {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, extern_calls, extern_code_block, Null, Null, Null)} +!toplevel| {extern_init_implicit} [doc]:nd redef visibility kwnew qmethid? signature annotation_noend? extern_calls extern_code_block {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, extern_calls, extern_code_block, Null, Null, Null)} !toplevel| {annot} line_annotation_forclass {-> line_annotation_forclass.propdef} !toplevel| {super} superclass {-> superclass.propdef} ; @@ -360,7 +367,7 @@ signature {-> signature} | {noparnoret} no {-> New signature(Null, [], Null, Null)} ; -params {-> param*} +params {-> param*} = param params_tail* [n2]:no {-> [param, params_tail.param] } | {null} {-> []} ; @@ -408,10 +415,15 @@ extern_code_body {-> extern_code_block} = no extern_code_block {-> extern_code_b /* TYPES *********************************************************************/ type~nobra~nopar {-> type} + = {atom} [t]:type_atom~nobra~nopar {-> t.type } + | {inter} [t1]:type_atom~nobra~nopar kwand [t2]:type_atom~nobra~nopar {-> t1.type } /* TODO create real nodes */ + | {union} [t1]:type_atom~nobra~nopar kwor [t2]:type_atom~nobra~nopar {-> t1.type } + ; +type_atom~nobra~nopar {-> type} = {simple} kwnullable? qclassid annotations_o~nopar {-> New type(kwnullable, qclassid, Null, [], Null, annotations_o~nopar.annotations)} !nobra | {generic} kwnullable? qclassid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, qclassid, obra, [types.type], cbra, annotations_o~nopar.annotations)} ; -types {-> type*} +types {-> type*} = type types_tail* {-> [type, types_tail.type]}; types_tail {-> type} = comma no type {-> type}; @@ -488,8 +500,9 @@ assign_op ; do~withelse {-> expr} - = kwdo stmtso_withend label {-> New expr.do(kwdo, stmtso_withend.expr, label)} - | {nolabel} kwdo stmtso~withelse {-> New expr.do(kwdo, stmtso~withelse.expr, Null)} + = kwdo stmtso_withend label {-> New expr.do(kwdo, stmtso_withend.expr, Null, Null, label)} + | {nolabel} kwdo stmtso~withelse {-> New expr.do(kwdo, stmtso~withelse.expr, Null, Null, Null)} + | {with_catch} kwdo n stmtsn kwcatch stmtso_withend {-> New expr.do(kwdo, stmtsn.expr, kwcatch, stmtso_withend.expr, Null)} ; if~withelse {-> expr} @@ -572,7 +585,7 @@ expr_eq~nopar~nobra {-> expr} | {:gt} expr_bitor~nopar~nobra gt :no [expr2]:expr_bitor~nopar~nobra | {:ge} expr_bitor~nopar~nobra ge :no [expr2]:expr_bitor~nopar~nobra | {:starship} expr_bitor~nopar~nobra starship :no [expr2]:expr_bitor~nopar~nobra - | {:isa} expr_bitor~nopar~nobra kwisa :no type~nobra + | {:isa} expr_bitor~nopar~nobra kwisa :no type_atom~nobra ; expr_bitor~nopar~nobra {-> expr} @@ -624,7 +637,7 @@ expr_minus~nopar~nobra {-> expr} expr_new~nopar~nobra {-> expr} = expr_atom~nopar~nobra {-> expr_atom~nopar~nobra.expr} - | {new} kwnew no type~nobra_nopar args {-> New expr.new(kwnew, type~nobra_nopar.type, Null, args.exprs)} + | {new} kwnew no type_atom~nobra_nopar args {-> New expr.new(kwnew, type_atom~nobra_nopar.type, Null, args.exprs)} | {isset_attr} kwisset recv~nopar~nobra qualified_o attrid {-> New expr.isset_attr(kwisset, recv~nopar~nobra.expr, attrid)} ; @@ -635,7 +648,7 @@ expr_atom~nopar~nobra {-> expr} | {super} qualified_o kwsuper args {-> New expr.super(qualified_o.qualified, kwsuper, args.exprs)} | {init} recv~nopar~nobra kwinit args {-> New expr.init(recv~nopar~nobra.expr, kwinit, args.exprs)} !nobra | {bra} expr_atom~nopar braargs {-> New expr.bra(expr_atom~nopar.expr, braargs.exprs)} - | {new} kwnew no type~nobra_nopar dot [n2]:no qid args {-> New expr.new(kwnew, type~nobra_nopar.type, qid, args.exprs)} + | {new} kwnew no type_atom~nobra_nopar dot [n2]:no qid args {-> New expr.new(kwnew, type_atom~nobra_nopar.type, qid, args.exprs)} | {as_cast} expr_atom~nopar~nobra dot no kwas [n2]:no opar [n3]:no type [n4]:no cpar {-> New expr.as_cast(expr_atom~nopar~nobra.expr, kwas, opar, type, cpar)} | {as_notnull} expr_atom~nopar~nobra dot no kwas [n2]:no opar [n3]:no kwnot [n4]:no kwnull [n5]:no cpar {-> New expr.as_notnull(expr_atom~nopar~nobra.expr, kwas, opar, kwnot, kwnull, cpar)} | {as_notnull2}expr_atom~nopar~nobra dot no kwas [n2]:no kwnot [n4]:no kwnull {-> New expr.as_notnull(expr_atom~nopar~nobra.expr, kwas, Null, kwnot, kwnull, Null)} @@ -689,7 +702,7 @@ array_item {-> expr} | {if} kwif [n1]:no expr [n2]:no kwthen [n3]:no [then]:array_item {-> New expr.if(kwif, expr, kwthen, then.expr, Null, Null)} ; -superstring {-> expr} +superstring {-> expr} = superstring_start superstring_middle* superstring_end annotations_o {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr], annotations_o.annotations)}; superstring_start {-> expr*} = start_string_p no expr [n2]:no {-> [start_string_p.expr, expr]} @@ -780,6 +793,7 @@ atid~forclass {-> atid} recv~nopar~nobra {-> expr} = expr_atom~nopar~nobra dot no {-> expr_atom~nopar~nobra.expr} + | {safe} expr_atom~nopar~nobra quest dot no {-> New expr.safe(expr_atom~nopar~nobra.expr, quest)} | {implicit} {-> New expr.implicit_self()} ; @@ -801,7 +815,7 @@ braargs {-> exprs} = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)}; expr_list {-> expr*} = arg [n2]:no expr_tail* {-> [arg.expr, expr_tail.expr]}; -expr_tail {-> expr} +expr_tail {-> expr} = comma no arg [n2]:no {-> arg.expr}; idlist {-> id*} = opar no idlist_nopar [n2]:no cpar {-> [idlist_nopar.id]} @@ -817,10 +831,10 @@ module_name {-> module_name} | {root} quad no modquad* id {-> New module_name(quad, [modquad.id], id)} ; -qualified +qualified = {cla} modquad* classquad {-> New qualified([modquad.id], classquad.classid)} | {mod} modquad+ {-> New qualified([modquad.id], Null)} - ; + ; qualified_o {-> qualified?} = qualified {-> qualified} | {null} {-> Null} @@ -836,7 +850,7 @@ qmethid~noid {-> methid} ; modquad {-> id} = id quad no {-> id}; -classquad {-> classid} +classquad {-> classid} = classid quad no {-> classid}; kwend_o {-> kwend?} @@ -901,6 +915,7 @@ classkind | {interface} kwinterface | {enum} kwenum | {extern} kwextern kwclass? + | {subset} kwsubset ; formaldef = [id]:classid type? annotations?; @@ -908,7 +923,7 @@ formaldef = [id]:classid type? annotations?; propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? assign? expr? annotations? kwdo? [block]:expr? kwend? | {main_meth} kwredef? [block]:expr? | {type} doc? kwredef? visibility kwtype [qid]:qclassid type annotations? - | {meth} doc? kwredef? visibility kwmeth? kwinit? kwnew? methid? signature annotations? extern_calls? extern_code_block? kwdo? [block]:expr? kwend? + | {meth} doc? kwredef? visibility kwmeth? kwinit? kwisa? kwnew? methid? signature annotations? extern_calls? extern_code_block? kwdo? [block]:expr? kwend? | {super} doc? kwredef? visibility kwsuper type annotations? | {annot} doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations? ; @@ -956,14 +971,14 @@ type = kwnullable? [qid]:qclassid obra? [types]:type* cbra? annotations?; label = kwlabel id?; -expr = {block} expr* kwend? +expr = {block} expr* kwend? | {vardecl} kwvar? id type? assign? expr? annotations? | {return} kwreturn? expr? | {yield} kwyield expr | {break} kwbreak label? | {abort} kwabort | {continue} kwcontinue? label? - | {do} kwdo [block]:expr? label? + | {do} kwdo [block]:expr? kwcatch? [catch]:expr? label? | {if} kwif expr kwthen [then]:expr? kwelse? [else]:expr? | {ifexpr} kwif expr kwthen [then]:expr kwelse [else]:expr | {while} kwwhile expr kwdo [block]:expr? label? @@ -971,9 +986,9 @@ expr = {block} expr* kwend? | {for} kwfor [groups]:for_group* kwdo [block]:expr? label? | {with} kwwith expr kwdo [block]:expr? label? | {assert} kwassert id? expr kwelse? [else]:expr? - | {once} kwonce expr - | {send} expr - | {binop} expr [expr2]:expr + | {once} kwonce expr + | {send} expr + | {binop} expr [expr2]:expr | {or} expr [op]:kwor [expr2]:expr | {and} expr [op]:kwand [expr2]:expr | {or_else} expr [op]:kwor kwelse [expr2]:expr @@ -1002,26 +1017,26 @@ expr = {block} expr* kwend? | {uplus} [op]:plus expr | {utilde} [op]:tilde expr | {new} kwnew type qid? [args]:exprs - | {attr} expr [id]:attrid - | {attr_assign} expr [id]:attrid assign [value]:expr - | {attr_reassign} expr [id]:attrid assign_op [value]:expr + | {attr} expr [id]:attrid + | {attr_assign} expr [id]:attrid assign [value]:expr + | {attr_reassign} expr [id]:attrid assign_op [value]:expr | {call} expr qid [args]:exprs | {call_assign} expr qid [args]:exprs assign [value]:expr | {call_reassign} expr qid [args]:exprs assign_op [value]:expr | {super} qualified? kwsuper [args]:exprs - | {init} expr kwinit [args]:exprs + | {init} expr kwinit [args]:exprs | {bra} expr [args]:exprs - | {bra_assign} expr [args]:exprs assign [value]:expr - | {bra_reassign} expr [args]:exprs assign_op [value]:expr + | {bra_assign} expr [args]:exprs assign [value]:expr + | {bra_reassign} expr [args]:exprs assign_op [value]:expr | {var} id - | {var_assign} id assign [value]:expr - | {var_reassign} id assign_op [value]:expr + | {var_assign} id assign [value]:expr + | {var_reassign} id assign_op [value]:expr | {range} expr [expr2]:expr annotations? | {crange} obra expr dotdot [expr2]:expr cbra annotations? | {orange} obra expr dotdot [expr2]:expr [cbra]:obra annotations? | {array} obra [exprs]:expr* type? cbra annotations? | {self} kwself annotations? - | {implicit_self} + | {implicit_self} | {true} kwtrue annotations? | {false} kwfalse annotations? | {null} kwnull annotations? @@ -1029,9 +1044,9 @@ expr = {block} expr* kwend? | {float} float annotations? | {char} char annotations? | {string} string annotations? - | {start_string} [string]:start_string - | {mid_string} [string]:mid_string - | {end_string} [string]:end_string + | {start_string} [string]:start_string + | {mid_string} [string]:mid_string + | {end_string} [string]:end_string | {superstring} [exprs]:expr* annotations? | {par} opar expr cpar annotations? | {as_cast} expr kwas opar? type cpar? @@ -1040,6 +1055,7 @@ expr = {block} expr* kwend? | {debug_type} kwdebug kwtype expr type | {vararg} expr dotdotdot | {namedarg} id assign expr + | {safe} expr quest | {type} type | {methid} expr [id]:methid | {at} annotations