From: Jean Privat Date: Tue, 24 Feb 2015 15:59:48 +0000 (+0700) Subject: grammar: introduce ASuperPropdef for super-classes X-Git-Tag: v0.7.2~6^2~8 X-Git-Url: http://nitlanguage.org grammar: introduce ASuperPropdef for super-classes The suffix `Prodef` is unfortunate, but sablecc3 is the law. I would have preferred `ASuperDef` or something. Signed-off-by: Jean Privat --- diff --git a/src/metrics/detect_covariance.nit b/src/metrics/detect_covariance.nit index c7c118d..dd7c36d 100644 --- a/src/metrics/detect_covariance.nit +++ b/src/metrics/detect_covariance.nit @@ -230,7 +230,7 @@ private class DetectCovariancePhase else node.debug("6.downcast {sup} to {sub}") end - else if n isa ASuperclass then + else if n isa ASuperPropdef then cpt_pattern.inc("8.subclass") else if n isa AArrayExpr then cpt_pattern.inc("9.array element") diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index 7c74a99..8d67fe8 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -253,12 +253,13 @@ formaldefs_tail {-> formaldef} formaldef = classid annotations? typing_o {-> New formaldef(classid, typing_o.type, annotations)}; -superclass {-> superclass} - = {super} no kwsuper [n2]:no type annotation_withend {-> New superclass(kwsuper, type, annotation_withend.annotations)} +superclass {-> propdef} + = {super} [doc]:no redef visibility kwsuper [n2]:no type annotation_withend {-> New propdef.super(doc.doc, redef.kwredef, visibility, kwsuper, type, annotation_withend.annotations)} ; propdefs {-> propdef*} = propdefn+ no {-> [propdefn.propdef]} + | {super} superclass {-> [superclass.propdef]} | {empty} no {-> []} ; propdefn {-> propdef} @@ -276,6 +277,7 @@ propdef~toplevel {-> propdef} !toplevel| {init} [doc]:no 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, stmtso.expr)} !toplevel| {type} [doc]:no redef visibility kwtype classid typing annotation_withend {-> New propdef.type(doc.doc, redef.kwredef, visibility, kwtype, classid, typing.type, annotation_withend.annotations)} !toplevel| {extern_init_implicit} [doc]:no 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)} +!toplevel| {super} superclass {-> superclass.propdef} ; annotation_withend~nonull {-> annotations?} = {oneliner} kwis many_annotations {-> many_annotations.annotations} @@ -811,13 +813,13 @@ classkind | {extern} kwextern kwclass? ; formaldef = [id]:classid type? annotations?; -superclass = kwsuper type annotations?; propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? expr? annotations? [block]:expr? | {main_meth} kwredef? [block]:expr? | {type} doc? kwredef? visibility kwtype [id]:classid type annotations? | {meth} doc? kwredef? visibility kwmeth? kwinit? kwnew? methid? signature annotations? extern_calls? extern_code_block? [block]:expr? + | {super} doc? kwredef? visibility kwsuper type annotations? ; methid = {id} id | {plus} plus | {minus} minus | {star} star | {starstar} starstar | {slash} slash | {percent} percent | {eq} eq | {ne} ne | {le} le | {ge} ge | {lt} lt | {gt} gt | {ll} ll | {gg} gg | {bra} obra cbra | {starship} starship | {assign} id assign | {braassign} obra cbra assign; diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index 289ad53..93a26e2 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -1030,12 +1030,13 @@ class AStdClassdef # The extern block code var n_extern_code_block: nullable AExternCodeBlock = null is writable - # The list of super-classes - var n_superclasses = new ANodes[ASuperclass](self) - # The `end` keyword var n_kwend: TKwend is writable, noinit + fun n_superclasses: Array[ASuperPropdef] do + return [for d in n_propdefs do if d isa ASuperPropdef then d] + end + redef fun hot_location do return n_id.location end @@ -1111,17 +1112,6 @@ class AFormaldef var n_type: nullable AType = null is writable end -# A super-class. eg `super X` -class ASuperclass - super Prod - - # The super keyword - var n_kwsuper: TKwsuper is writable, noinit - - # The super-class (indicated as a type) - var n_type: AType is writable, noinit -end - # The definition of a property abstract class APropdef super ADefinition @@ -1200,6 +1190,18 @@ class AMainMethPropdef super AMethPropdef end +# A super-class. eg `super X` +class ASuperPropdef + super APropdef + + # The super keyword + var n_kwsuper: TKwsuper is writable, noinit + + # The super-class (indicated as a type) + var n_type: AType is writable, noinit +end + + # Declaration of callbacks for extern methods class AExternCalls super Prod