Signed-off-by: Jean Privat <jean@pryen.org>
# Get `self` as a `String`.
# Return null if not a string.
fun as_string: nullable String
do
# Get `self` as a `String`.
# Return null if not a string.
fun as_string: nullable String
do
- if not self isa AExprAtArg then return null
- var nexpr = n_expr
- if not nexpr isa AStringFormExpr then return null
- return nexpr.value.as(not null)
+ if not self isa AStringFormExpr then return null
+ return self.value.as(not null)
end
# Get `self` as an `Int`.
# Return null if not an integer.
fun as_int: nullable Int
do
end
# Get `self` as an `Int`.
# Return null if not an integer.
fun as_int: nullable Int
do
- if not self isa AExprAtArg then return null
- var nexpr = n_expr
- if not nexpr isa AIntExpr then return null
- return nexpr.value.as(not null)
+ if not self isa AIntExpr then return null
+ return self.value.as(not null)
end
# Get `self` as a single identifier.
# Return null if not a single identifier.
fun as_id: nullable String
do
end
# Get `self` as a single identifier.
# Return null if not a single identifier.
fun as_id: nullable String
do
- if not self isa AExprAtArg then return null
- var nexpr = n_expr
- if not nexpr isa ACallExpr then return null
- if not nexpr.n_expr isa AImplicitSelfExpr then return null
- if not nexpr.n_args.n_exprs.is_empty then return null
- return nexpr.n_id.text
+ if not self isa ACallExpr then return null
+ if not self.n_expr isa AImplicitSelfExpr then return null
+ if not self.n_args.n_exprs.is_empty then return null
+ return self.n_id.text
end
var options = new Array[CCompilerOption]
end
var options = new Array[CCompilerOption]
- for arg in args do
- if not arg isa AExprAtArg then
- modelbuilder.error(nat, "Syntax error: \"{annotation_name}\" expects its arguments to be the name of the package as String literals or a call to `exex(\"local_program\")`.")
- return
- end
-
- var expr = arg.n_expr
if expr isa AStringFormExpr then
var text = expr.collect_text
text = text.substring(1, text.length-2)
if expr isa AStringFormExpr then
var text = expr.collect_text
text = text.substring(1, text.length-2)
redef fun accept_pretty_printer(v) do v.visit n_type
end
redef fun accept_pretty_printer(v) do v.visit n_type
end
-redef class AExprAtArg
- redef fun accept_pretty_printer(v) do v.visit n_expr
-end
-
# Modules
redef class AModule
# Modules
redef class AModule
| {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
| {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
| {superstring} superstring {-> superstring.expr}
| {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
| {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
| {superstring} superstring {-> superstring.expr}
-!nopar | {par} opar no expr [n2]:no cpar annotations_o {-> New expr.par(opar, expr, cpar, annotations_o.annotations)}
+!nopar | {par} opar no any_expr [n2]:no cpar annotations_o {-> New expr.par(opar, any_expr.expr, cpar, annotations_o.annotations)}
// !nopar to unambiguise 'foo[5].bar' between '(foo[5]).bar' and 'foo([5].bar),
!nobra!nopar | {range} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no cbra annotations_o {-> New expr.crange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
!nobra!nopar | {orange} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no [cbra]:obra annotations_o {-> New expr.orange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
// !nopar to unambiguise 'foo[5].bar' between '(foo[5]).bar' and 'foo([5].bar),
!nobra!nopar | {range} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no cbra annotations_o {-> New expr.crange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
!nobra!nopar | {orange} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no [cbra]:obra annotations_o {-> New expr.orange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
one_annotation~nopar {-> annotation}
= {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
// !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
one_annotation~nopar {-> annotation}
= {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
// !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
-!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.at_arg], cpar, annotations_o~nopar.annotations)}
+!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.expr], cpar, annotations_o~nopar.annotations)}
;
many_annotations {-> annotations}
;
many_annotations {-> annotations}
one_annotation_list~nopar {-> annotation}
= {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
// !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
one_annotation_list~nopar {-> annotation}
= {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
// !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
-!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.at_arg], cpar, annotations_o~nopar.annotations)}
-!nopar | {nopar} redef visibility atid at_arg_single {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [at_arg_single.at_arg], Null, Null)}
+!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.expr], cpar, annotations_o~nopar.annotations)}
+!nopar | {nopar} redef visibility atid at_arg_single {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [at_arg_single.expr], Null, Null)}
-at_arg_single {-> at_arg}
// FIXME: why expr_single but not expr_atom is not clear :(
// FIXME: why expr_single but not expr_atom is not clear :(
- = {expr} [expr]:expr_single_nopar {-> New at_arg.expr(expr.expr)}
+ = {expr} [expr]:expr_single_nopar {-> expr.expr}
;
annotations_tail {-> annotation}
;
annotations_tail {-> annotation}
;
line_annotation {-> annotation}
= [doc]:no redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)}
;
line_annotation {-> annotation}
= [doc]:no redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)}
- | {args} [doc]:no redef visibility atid opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, opar, [at_args.at_arg], cpar, annotations)}
- | {nopar} [doc]:no redef visibility atid at_args_nopar n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [at_args_nopar.at_arg], Null, Null)}
+ | {args} [doc]:no redef visibility atid opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, opar, [at_args.expr], cpar, annotations)}
+ | {nopar} [doc]:no redef visibility atid at_args_nopar n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [at_args_nopar.expr], Null, Null)}
;
line_annotations_forclass {-> annotations}
= line_annotation_forclass+ {-> New annotations(Null, Null, [line_annotation_forclass.annotation], Null) }
;
line_annotation_forclass {-> annotation}
= [doc]:no atid_forclass annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)}
;
line_annotations_forclass {-> annotations}
= line_annotation_forclass+ {-> New annotations(Null, Null, [line_annotation_forclass.annotation], Null) }
;
line_annotation_forclass {-> annotation}
= [doc]:no atid_forclass annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)}
- | {args} [doc]:no atid_forclass opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.at_arg], cpar, annotations)}
- | {nopar} [doc]:no atid_forclass at_args_nopar n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.at_arg], Null, Null)}
+ | {args} [doc]:no atid_forclass opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.expr], cpar, annotations)}
+ | {nopar} [doc]:no atid_forclass at_args_nopar n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.expr], Null, Null)}
-at_args~nopar {-> at_arg* }
- = {many} at_arg~nopar at_args_tail* {-> [at_arg~nopar.at_arg, at_args_tail.at_arg]}
+at_args~nopar {-> expr* }
+ = {many} any_expr~nopar at_args_tail* {-> [any_expr~nopar.expr, at_args_tail.expr]}
-at_args_tail {-> at_arg}
- = comma no at_arg {-> at_arg}
+at_args_tail {-> expr}
+ = comma no any_expr {-> any_expr.expr}
-at_arg~nopar {-> at_arg}
- = {type} type {-> New at_arg.type(type)}
- | {expr} expr~nopar {-> New at_arg.expr(expr~nopar.expr)}
- | {stmt} stmt_noexpr~nopar {-> New at_arg.expr(stmt_noexpr~nopar.expr)}
-!nopar | {at} annotations {-> New at_arg.at(annotations.annotations)}
+any_expr~nopar {-> expr}
+ = {type} type {-> New expr.type(type)}
+ | {expr} expr~nopar {-> expr~nopar.expr}
+ | {stmt} stmt_noexpr~nopar {-> stmt_noexpr~nopar.expr}
+!nopar | {at} annotations {-> New expr.at(annotations.annotations)}
;
atid~forclass {-> atid}
;
atid~forclass {-> atid}
| {isset_attr} kwisset expr [id]:attrid
| {debug_type} kwdebug kwtype expr type
| {vararg} expr dotdotdot
| {isset_attr} kwisset expr [id]:attrid
| {debug_type} kwdebug kwtype expr type
| {vararg} expr dotdotdot
+ | {type} type
+ | {at} annotations
;
exprs
= {list} [exprs]:expr*
;
exprs
= {list} [exprs]:expr*
annotations = at? opar? [items]:annotation* cpar?;
annotations = at? opar? [items]:annotation* cpar?;
-annotation = doc? kwredef? visibility? atid opar? [args]:at_arg* cpar? annotations?;
+annotation = doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?;
-at_arg
- = {type} type
- | {expr} expr
- | {at} annotations
- ;
atid = {id} id | {kwextern} [id]:kwextern | {kwabstract} [id]:kwabstract | {kwimport} [id]:kwimport;
/*****************************************************************************/
atid = {id} id | {kwextern} [id]:kwextern | {kwabstract} [id]:kwabstract | {kwimport} [id]:kwimport;
/*****************************************************************************/
var n_dotdotdot: TDotdotdot is writable, noinit
end
var n_dotdotdot: TDotdotdot is writable, noinit
end
-# A list of expression separated with commas (arguments for instance)
-abstract class AExprs
- super Prod
- var n_exprs = new ANodes[AExpr](self)
+# A special expression that encapsulates a static type
+# Can only be found in special construction like arguments of annotations.
+class ATypeExpr
+ super AExpr
+ var n_type: AType is writable, noinit
+end
+
+# A special expression that encapsulate an annotation
+# Can only be found in special construction like arguments of annotations.
+class AAtExpr
+ super AExpr
end
# A special expression to debug types
end
# A special expression to debug types
var n_type: AType is writable, noinit
end
var n_type: AType is writable, noinit
end
+# A list of expression separated with commas (arguments for instance)
+abstract class AExprs
+ super Prod
+ var n_exprs = new ANodes[AExpr](self)
+end
+
# A simple list of expressions
class AListExprs
super AExprs
# A simple list of expressions
class AListExprs
super AExprs
var n_visibility: nullable AVisibility is writable
var n_atid: AAtid is writable, noinit
var n_opar: nullable TOpar = null is writable
var n_visibility: nullable AVisibility is writable
var n_atid: AAtid is writable, noinit
var n_opar: nullable TOpar = null is writable
- var n_args = new ANodes[AAtArg](self)
+ var n_args = new ANodes[AExpr](self)
var n_cpar: nullable TCpar = null is writable
end
var n_cpar: nullable TCpar = null is writable
end
-# A single argument of an annotation
-abstract class AAtArg
- super Prod
-end
-
-# A type-like argument of an annotation
-class ATypeAtArg
- super AAtArg
- var n_type: AType is writable, noinit
-end
-
-# An expression-like argument of an annotation
-class AExprAtArg
- super AAtArg
- var n_expr: AExpr is writable, noinit
-end
-
-# An annotation-like argument of an annotation
-class AAtAtArg
- super AAtArg
-end
-
# An annotation name
abstract class AAtid
super Prod
# An annotation name
abstract class AAtid
super Prod