diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g index e8efe44..7f4d174 100644 --- a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g +++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g @@ -249,22 +249,22 @@ primary_expression_start: primary_expression_part [CommonTree lhs]: access_identifier[$lhs] | brackets_or_arguments[$lhs] - | p='++' -> ^(POSTINC[$p.token, "++"] { (CommonTree)adaptor.DupTree($lhs) } ) - | m='--' -> ^(POSTDEC[$m.token, "--"] { (CommonTree)adaptor.DupTree($lhs) } ) + | p='++' -> ^(POSTINC[$p.token, "++"] { dupTree($lhs) } ) + | m='--' -> ^(POSTDEC[$m.token, "--"] { dupTree($lhs) } ) ; access_identifier [CommonTree lhs]: - access_operator type_or_generic -> ^(access_operator { (CommonTree)adaptor.DupTree($lhs) } type_or_generic); + access_operator type_or_generic -> ^(access_operator { dupTree($lhs) } type_or_generic); access_operator: '.' | '->' ; brackets_or_arguments [CommonTree lhs]: brackets[$lhs] | arguments[$lhs] ; brackets [CommonTree lhs]: - '[' expression_list? ']' -> ^(INDEX { (CommonTree)adaptor.DupTree($lhs) } expression_list?); + '[' expression_list? ']' -> ^(INDEX { dupTree($lhs) } expression_list?); // keving: TODO: drop this. paren_expression: '(' expression ')' -> ^(PARENS expression); arguments [CommonTree lhs]: - '(' argument_list? ')' -> ^(APPLY { (CommonTree)adaptor.DupTree($lhs) } argument_list?); + '(' argument_list? ')' -> ^(APPLY { dupTree($lhs) } argument_list?); argument_list: a1=argument (',' an+=argument)* -> ^(ARGS[$a1.start.Token,"ARGS"] $a1 $an*); // 4.0 @@ -558,9 +558,9 @@ relational_expression: ( ((o='<'|o='>'|o='>='|o='<=') s2=shift_expression -> ^($o $relational_expression $s2)) | (i='is' t=non_nullable_type -> ^(INSTANCEOF[$i.Token,"instanceof"] $relational_expression $t) | i1='as' t1=non_nullable_type -> ^(COND_EXPR[$i1.Token, "?:"] - ^(INSTANCEOF[$i1.Token,"instanceof"] { (CommonTree)adaptor.DupTree($relational_expression.tree) } { (CommonTree)adaptor.DupTree($t1.tree) } ) - ^(CAST_EXPR[$i1.Token, "(cast)"] { (CommonTree)adaptor.DupTree($t1.tree) } { (CommonTree)adaptor.DupTree($relational_expression.tree) }) - ^(CAST_EXPR[$i1.Token, "(cast)"] { (CommonTree)adaptor.DupTree($t1.tree) } NULL[$i1.Token, "null"]))) + ^(INSTANCEOF[$i1.Token,"instanceof"] { dupTree($relational_expression.tree) } { dupTree($t1.tree) } ) + ^(CAST_EXPR[$i1.Token, "(cast)"] { dupTree($t1.tree) } { dupTree($relational_expression.tree) }) + ^(CAST_EXPR[$i1.Token, "(cast)"] { dupTree($t1.tree) } NULL[$i1.Token, "null"]))) )* ; equality_expression: relational_expression @@ -738,9 +738,9 @@ variable_declarator: type_name ('=' variable_initializer)? ; // eg. event EventHandler IInterface.VariableName = Foo; /////////////////////////////////////////////////////// -method_declaration[CommonTree atts, CommonTree mods, CommonTree type]: +method_declaration [CommonTree atts, CommonTree mods, CommonTree type]: member_name type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clauses? method_body - -> ^(METHOD { (CommonTree)adaptor.DupTree($atts) } { (CommonTree)adaptor.DupTree($mods) } { (CommonTree)adaptor.DupTree($type) } + -> ^(METHOD { dupTree($atts) } { dupTree($mods) } { dupTree($type) } member_name type_parameter_constraints_clauses? type_parameter_list? formal_parameter_list? method_body); //method_header[CommonTree atts, CommonTree mods, CommonTree type]: @@ -923,23 +923,25 @@ interface_body: interface_member_declarations: interface_member_declaration+ ; interface_member_declaration: - attributes? modifiers? - (void_type interface_method_declaration - | interface_event_declaration - | type ( (member_name '(') => interface_method_declaration - | (member_name '{') => interface_property_declaration - | interface_indexer_declaration) + a=attributes? m=modifiers? + (vt=void_type im1=interface_method_declaration[$a.tree, $m.tree, $vt.tree] -> $im1 + | ie=interface_event_declaration[$a.tree, $m.tree] -> $ie + | t=type ( (member_name '(') => im2=interface_method_declaration[$a.tree, $m.tree, $t.tree] -> $im2 + | (member_name '{') => ip=interface_property_declaration[$a.tree, $m.tree, $t.tree] -> ^(PROPERTY[$t.start.Token, "PROPERTY"] $a? $m? $t interface_property_declaration) + | ii=interface_indexer_declaration[$a.tree, $m.tree, $t.tree] -> $ii) ) ; -interface_property_declaration: +interface_property_declaration [CommonTree atts, CommonTree mods, CommonTree type]: identifier '{' interface_accessor_declarations '}' ; -interface_method_declaration: +interface_method_declaration [CommonTree atts, CommonTree mods, CommonTree type]: identifier generic_argument_list? - '(' formal_parameter_list? ')' type_parameter_constraints_clauses? ';' ; -interface_event_declaration: + '(' formal_parameter_list? ')' type_parameter_constraints_clauses? ';' + -> ^(METHOD { dupTree($atts) } { dupTree($mods) } { dupTree($type) } + identifier type_parameter_constraints_clauses? generic_argument_list? formal_parameter_list?); +interface_event_declaration [CommonTree atts, CommonTree mods]: //attributes? 'new'? 'event' type identifier ';' ; -interface_indexer_declaration: +interface_indexer_declaration [CommonTree atts, CommonTree mods, CommonTree type]: // attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessor_declarations '}' ; interface_accessor_declarations: diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g index 0b10c5f..0d4d7df 100644 --- a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g +++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g @@ -257,8 +257,8 @@ class_member_declaration returns [List preComments]: { $preComments = CollectedComments; } method_body) -> method(modifiers={$modifiers.st}, type={$type.st}, name={ $member_name.st }, typeparams = { $type_parameter_list.st }, params={ $formal_parameter_list.st }, bodyIsSemi = { $method_body.isSemi }, body={ $method_body.st }) // | ^(METHOD attributes? modifiers? type method_declaration) -> method(modifiers={$modifiers.st}, type={$type.st}, method={$method_declaration.st}) - | ^(INTERFACE attributes? modifiers? interface_declaration[$modifiers.st]) - | ^(CLASS attributes? modifiers? class_declaration[$modifiers.st]) + | ^(INTERFACE attributes? modifiers? interface_declaration[$modifiers.st]) -> { $interface_declaration.st } + | ^(CLASS attributes? modifiers? class_declaration[$modifiers.st]) -> { $class_declaration.st } | ^(PROPERTY attributes? modifiers? type property_declaration) | ^(INDEXER attributes? modifiers? type type_name? indexer_declaration) | ^(FIELD attributes? modifiers? type field_declaration) -> field(modifiers={$modifiers.st}, type={$type.st}, field={$field_declaration.st}) @@ -979,27 +979,25 @@ interface_declaration[StringTemplate modifiersST] @init { List preComments = null; }: - ^(c=INTERFACE { preComments = CollectedComments; } + ^(c=INTERFACE identifier type_parameter_constraints_clauses? variant_generic_parameter_list[$type_parameter_constraints_clauses.tpConstraints]? - class_extends? interface_body ) + class_extends? { preComments = CollectedComments; } interface_body ) -> iface(modifiers = {modifiersST}, name={ $identifier.st }, typeparams={$variant_generic_parameter_list.st} ,comments = { preComments }, - imps = { $class_extends.st }) ; -interface_modifiers: - modifier+ ; -interface_base: - ':' interface_type_list ; + imps = { $class_extends.st }, body = { $interface_body.st }) ; +//interface_base: +// ':' interface_type_list ; interface_body: - '{' interface_member_declarations? '}' ; -interface_member_declarations: - interface_member_declaration+ ; -interface_member_declaration: - attributes? modifiers? - ('void' interface_method_declaration - | interface_event_declaration - | type ( (member_name '(') => interface_method_declaration - | (member_name '{') => interface_property_declaration - | interface_indexer_declaration) - ) + '{' ms+=interface_member_declaration_aux* '}' -> class_body(entries = { $ms }); +interface_member_declaration_aux: + member=interface_member_declaration -> class_member(comments = { $member.preComments }, member = { $member.st }); + +interface_member_declaration returns [List preComments]: + ^(EVENT attributes? modifiers? event_declaration) + | ^(METHOD attributes? modifiers? type identifier type_parameter_constraints_clauses? type_parameter_list[$type_parameter_constraints_clauses.tpConstraints]? formal_parameter_list?) + { $preComments = CollectedComments; } + -> method(modifiers={$modifiers.st}, type={$type.st}, name={ $identifier.st }, typeparams = { $type_parameter_list.st }, params={ $formal_parameter_list.st }, bodyIsSemi = { true }) + | ^(PROPERTY attributes? modifiers? type property_declaration) + | ^(INDEXER attributes? modifiers? type type_name? indexer_declaration) ; interface_property_declaration: identifier '{' interface_accessor_declarations '}' ; diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g index 34b57ac..aa01ded 100644 --- a/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g +++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g @@ -716,13 +716,10 @@ interface_body: interface_member_declarations: interface_member_declaration+ ; interface_member_declaration: - attributes? modifiers? - ('void' interface_method_declaration - | interface_event_declaration - | type ( (member_name '(') => interface_method_declaration - | (member_name '{') => interface_property_declaration - | interface_indexer_declaration) - ) + ^(EVENT attributes? modifiers? event_declaration) + | ^(METHOD attributes? modifiers? type identifier type_parameter_constraints_clauses? type_parameter_list? formal_parameter_list?) + | ^(PROPERTY attributes? modifiers? type property_declaration) + | ^(INDEXER attributes? modifiers? type type_name? indexer_declaration) ; interface_property_declaration: identifier '{' interface_accessor_declarations '}' ;