Merge: Use more intern methods and add intern factories for NativeString and NativeArray
[nit.git] / src / parser / nit.sablecc3xx
index 0bc5b50..98bbcc2 100644 (file)
@@ -27,6 +27,7 @@ all = [0 .. 0xFF];
 lowercase = ['a' .. 'z'];
 uppercase = ['A' .. 'Z'];
 digit = ['0' .. '9'];
+hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
 letter = lowercase | uppercase | digit | '_';
 
 tab = 9;
@@ -183,6 +184,7 @@ id = lowercase letter*;
 attrid = '_' lowercase letter*;
 
 number = digit+;
+hex_number = ('0x' | '0X') hexdigit+;
 float = digit* '.' digit+;
 string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
 start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
@@ -240,7 +242,7 @@ classkind
        | {abstract} kwabstract kwclass
        | {interface} kwinterface
        | {enum} kwenum
-       | {extern} kwextern kwclass?
+       | {extern} kwextern kwclass
        ;
 
 formaldefs {-> formaldef*}
@@ -261,10 +263,10 @@ propdefs~toplevel {-> propdef}
        ;
 propdef~toplevel {-> propdef}
        = {meth} [doc]:no redef visibility kwmeth methid signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.concrete_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature, annotation_noend.annotations, stmtso.expr)}
-       | {assign_return} [doc]:no redef visibility kwmeth methid signature_withret assign no assign_return {-> New propdef.concrete_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature_withret.signature, Null, assign_return.expr)}
        | {nobody} [doc]:no redef visibility kwmeth methid signature annotation_withend_nonull {-> New propdef.deferred_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, annotation_withend_nonull.annotations)}
 !toplevel| {deferred} [doc]:no redef visibility kwmeth methid signature kwis kwabstract {-> New propdef.deferred_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, Null)}
-!toplevel| {intern} [doc]:no redef visibility kwmeth methid signature kwis kwintern {-> New propdef.intern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature)}
+       | {intern} [doc]:no redef visibility kwmeth methid signature kwis kwintern {-> New propdef.intern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature)}
+!toplevel| {intern_new} [doc]:no redef visibility kwnew methid? signature kwis kwintern {-> New propdef.intern_new(doc.doc, redef.kwredef, visibility, kwnew, methid, signature)}
        | {extern} [doc]:no redef visibility kwmeth methid signature kwis kwextern string_o extern_calls extern_code_block_o {-> New propdef.extern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, string_o.string, extern_calls, extern_code_block_o.extern_code_block)}
        | {extern_implicit} [doc]:no redef visibility kwmeth methid signature extern_calls extern_code_block {-> New propdef.extern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, Null, extern_calls, extern_code_block)}
 !toplevel| {var} [doc]:no readable? writable? redef visibility kwvar attrid typing_o {-> New propdef.attr(doc.doc, readable.able, writable.able, redef.kwredef, visibility, kwvar, attrid, Null, typing_o.type, Null, Null)}
@@ -320,11 +322,11 @@ methid {-> methid}
        | {braassign} obra cbra assign {-> New methid.braassign(obra, cbra, assign)}
        ;
 
-signature~withret {-> signature}
+signature {-> signature}
        = opar no params cpar typing [no2]:no {-> New signature(opar, [params.param], cpar, typing.type)}
-!withret| {noret} opar no params cpar [no2]:no {-> New signature(opar, [params.param], cpar, Null)}
+       | {noret} opar no params cpar [no2]:no {-> New signature(opar, [params.param], cpar, Null)}
        | {nopar} typing no {-> New signature(Null, [], Null, typing.type)}
-!withret| {noparnoret} no {-> New signature(Null, [], Null, Null)}
+       | {noparnoret} no {-> New signature(Null, [], Null, Null)}
        ;
 
 params {-> param*} 
@@ -338,10 +340,6 @@ param
        | id annotations? typing dotdotdot? {-> New param(id, typing.type, dotdotdot, annotations)}
        ;
 
-assign_return{-> expr}
-       = expr_final {-> New expr.return(Null, expr_final.expr)}
-       ;
-
 extern_calls {-> extern_calls?}
        = kwimport no extern_call extern_call_tail* {-> New extern_calls( kwimport, [extern_call, extern_call_tail.extern_call] )}
        | {null} {-> Null}
@@ -349,25 +347,27 @@ extern_calls {-> extern_calls?}
 extern_call_tail {-> extern_call}
        = comma no extern_call {-> extern_call};
 extern_call {-> extern_call}
-    = {prop} extern_call_prop {-> extern_call_prop.extern_call}
-    | {cast} extern_call_cast {-> extern_call_cast.extern_call}
+       = {prop} extern_call_prop {-> extern_call_prop.extern_call}
+       | {cast} extern_call_cast {-> extern_call_cast.extern_call}
        | {super} kwsuper {-> New extern_call.super( kwsuper )}
-    ;
+       ;
 extern_call_prop {-> extern_call}
-    = {local} methid {-> New extern_call.local_prop( methid )}
-       | {full} type quad methid {-> New extern_call.full_prop( type, Null, methid )}
-       | {full2} type dot methid {-> New extern_call.full_prop( type, dot, methid )}
+       = {local} methid {-> New extern_call.local_prop( methid )}
+       | {full} type dot methid {-> New extern_call.full_prop( type, dot, methid )}
        | {init} type {-> New extern_call.init_prop( type )}
        ;
 extern_call_cast {-> extern_call}
-    = {as_cast} [from_type]:type dot? kwas [n2]:no opar [n3]:no [to_type]:type [n4]:no cpar {-> New extern_call.cast_as(from_type, dot, kwas, to_type)}
-       | {as_nullable} type dot? kwas [n2]:no kwnullable {-> New extern_call.as_nullable( type, kwas, kwnullable)}
-       | {as_not_nullable} type dot? kwas [n2]:no kwnot [n3]:no kwnullable {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
+       = {as_cast} [from_type]:type dot kwas [n2]:no opar [n3]:no [to_type]:type [n4]:no cpar {-> New extern_call.cast_as(from_type, dot, kwas, to_type)}
+       | {as_cast2}[from_type]:type dot kwas [n2]:no [to_type]:type {-> New extern_call.cast_as(from_type, dot, kwas, to_type)}
+       | {as_nullable} type dot kwas [n2]:no opar [n3]:no kwnullable [n4]:no cpar {-> New extern_call.as_nullable( type, kwas, kwnullable)}
+       | {as_nullable2}type dot kwas [n2]:no kwnullable {-> New extern_call.as_nullable( type, kwas, kwnullable)}
+       | {as_not_nullable} type dot kwas [n2]:no opar [n3]:no kwnot [n4]:no kwnullable [n5]:no cpar {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
+       | {as_not_nullable2}type dot kwas [n2]:no kwnot [n3]:no kwnullable {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
        ;
 
 string_o {->string?} = string? {-> string};
 
-in_language = kwin string;
+in_language = kwin no string [n1]:no {-> New in_language(kwin, string)};
 extern_code_block = in_language? extern_code_segment;
 extern_code_block_o {-> extern_code_block?}
        = extern_code_block {-> extern_code_block}
@@ -564,7 +564,8 @@ expr_atom~nopar~nobra {-> expr}
        | {true} kwtrue annotations_o {-> New expr.true(kwtrue, annotations_o.annotations)}
        | {false} kwfalse annotations_o {-> New expr.false(kwfalse, annotations_o.annotations)}
        | {null} kwnull annotations_o {-> New expr.null(kwnull, annotations_o.annotations)}
-       | {int} number annotations_o {-> New expr.int(number, annotations_o.annotations)}
+       | {int} number annotations_o {-> New expr.dec_int(number, annotations_o.annotations)}
+       | {hex_int} hex_number annotations_o {-> New expr.hex_int(hex_number, annotations_o.annotations)}
        | {float} float annotations_o {-> New expr.float(float, annotations_o.annotations)}
        | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
        | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
@@ -769,6 +770,7 @@ propdef = {attr} doc? [readable]:able? [writable]:able? kwredef? visibility kwva
        | {meth} doc? kwredef? visibility methid signature
        | {deferred_meth} doc? kwredef? visibility kwmeth methid signature annotations?
        | {intern_meth} doc? kwredef? visibility kwmeth methid signature
+       | {intern_new} doc? kwredef? visibility kwnew methid? signature
        | {extern_meth} doc? kwredef? visibility kwmeth methid signature [extern]:string? extern_calls? extern_code_block?
        | {concrete_meth} doc? kwredef? visibility kwmeth methid signature annotations? [block]:expr?
        | {concrete_init} doc? kwredef? visibility kwinit methid? signature annotations? [block]:expr?
@@ -854,7 +856,8 @@ expr        = {block} expr* kwend?
        | {true} kwtrue annotations?
        | {false} kwfalse annotations?
        | {null} kwnull annotations?
-       | {int} number annotations?
+       | {dec_int} number annotations?
+       | {hex_int} hex_number annotations?
        | {float} float annotations?
        | {char} char annotations?
        | {string} string annotations?