2008-05-26 Jamie McCracken <jamiemcc@gnome.org>
+ * vala/valagenieparser.vala:
+
+ allow init block to be used in context.root namespace where
+ its parsed and converted to the "main" function
+
+2008-05-26 Jamie McCracken <jamiemcc@gnome.org>
+
* vala/valagenieparser.vala: added missing throws ParseError to get_for_statement_type method
2008-05-26 Jamie McCracken <jamiemcc@gnome.org>
}
}
- Symbol parse_declaration () throws ParseError {
+ Symbol parse_declaration (bool is_root = false) throws ParseError {
comment = scanner.pop_comment ();
var attrs = parse_attributes ();
case TokenType.CLASS:
return parse_class_declaration (attrs);
case TokenType.INIT:
+ if (is_root) {
+ return parse_main_method_declaration (attrs);
+ }
return parse_constructor_declaration (attrs);
case TokenType.DELEGATE:
return parse_delegate_declaration (attrs);
}
void parse_namespace_member (Namespace ns) throws ParseError {
- var sym = parse_declaration ();
+
+ var sym = parse_declaration ((ns == context.root));
if (sym is Namespace) {
ns.add_namespace ((Namespace) sym);
} else if (sym is Class) {
}
}
+
+ Method parse_main_method_declaration (Gee.List<Attribute>? attrs) throws ParseError {
+ var id = "main";
+ var begin = get_location ();
+ DataType type = new VoidType ();
+ expect (TokenType.INIT);
+
+ var method = new Method (id, type, get_src_com (begin));
+ method.access = SymbolAccessibility.PUBLIC;
+
+ set_attributes (method, attrs);
+
+ method.binding = MemberBinding.STATIC;
+
+ var sym = new UnresolvedSymbol (null, "string", get_src (begin));
+ type = new UnresolvedType.from_symbol (sym, get_src (begin));
+ type.value_owned = true;
+ type = new ArrayType (type, 1, get_src (begin));
+ type.nullable = false;
+
+ var param = new FormalParameter ("args", type, get_src (begin));
+ method.add_parameter (param);
+
+
+ expect (TokenType.EOL);
+
+ if (accept_block ()) {
+ method.body = parse_block ();
+ }
+
+ return method;
+ }
+
Method parse_method_declaration (Gee.List<Attribute>? attrs) throws ParseError {
var begin = get_location ();
DataType type = new VoidType ();