mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
Start of support for classes
- Simplified pretty printer code by passing modifier template into definitions.
This commit is contained in:
parent
84983f7a83
commit
1ecc21f0c8
@ -42,6 +42,17 @@ scope NSContext {
|
|||||||
return ((NSContext_scope)$NSContext.ToArray()[$NSContext.Count-2]).currentNS;
|
return ((NSContext_scope)$NSContext.ToArray()[$NSContext.Count-2]).currentNS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TREE CONSTRUCTION
|
||||||
|
protected CommonTree mkPayloadList(List<string> payloads) {
|
||||||
|
CommonTree root = (CommonTree)adaptor.Nil;
|
||||||
|
|
||||||
|
foreach (string p in payloads) {
|
||||||
|
adaptor.AddChild(root, (CommonTree)adaptor.Create(PAYLOAD, p));
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************
|
/********************************************************************************************
|
||||||
@ -618,7 +629,9 @@ attribute_argument_expression:
|
|||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
class_declaration returns [string name]:
|
class_declaration returns [string name]:
|
||||||
'class' type_or_generic { $name = mkTypeName($type_or_generic.type, $type_or_generic.generic_arguments); } class_base? type_parameter_constraints_clauses? class_body ';'? ;
|
c='class' type_or_generic { $name = mkTypeName($type_or_generic.type, $type_or_generic.generic_arguments); } class_base? type_parameter_constraints_clauses? class_body ';'?
|
||||||
|
-> ^(CLASS[$c.Token] PAYLOAD[$type_or_generic.type] ^(PAYLOAD_LIST { mkPayloadList($type_or_generic.generic_arguments) } )
|
||||||
|
class_base? type_parameter_constraints_clauses? class_body );
|
||||||
class_base:
|
class_base:
|
||||||
// syntactically base class vs interface name is the same
|
// syntactically base class vs interface name is the same
|
||||||
//':' class_type (',' interface_type_list)? ;
|
//':' class_type (',' interface_type_list)? ;
|
||||||
|
@ -43,21 +43,17 @@ options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compilation_unit
|
compilation_unit
|
||||||
@init {
|
:
|
||||||
List<string> preComments = null;
|
^(PACKAGE nm=PAYLOAD modifiers? type_declaration[$modifiers.st]) ->
|
||||||
}:
|
|
||||||
^(PACKAGE { preComments = collectComments($PACKAGE.TokenStartIndex); } nm=PAYLOAD modifiers? type_declaration) ->
|
|
||||||
package(now = {DateTime.Now}, includeDate = {true}, packageName = {$nm.text},
|
package(now = {DateTime.Now}, includeDate = {true}, packageName = {$nm.text},
|
||||||
comments = { preComments },
|
|
||||||
modifiers = {$modifiers.st},
|
|
||||||
type = {$type_declaration.st},
|
type = {$type_declaration.st},
|
||||||
endComments = {IsLast ? collectComments() : null});
|
endComments = {IsLast ? collectComments() : null});
|
||||||
|
|
||||||
type_declaration:
|
type_declaration [StringTemplate modifiersST]:
|
||||||
class_declaration
|
class_declaration[modifiersST] -> { $class_declaration.st }
|
||||||
| struct_declaration
|
| struct_declaration
|
||||||
| interface_declaration
|
| interface_declaration
|
||||||
| enum_declaration -> { $enum_declaration.st }
|
| enum_declaration[modifiersST] -> { $enum_declaration.st }
|
||||||
| delegate_declaration ;
|
| delegate_declaration ;
|
||||||
// Identifiers
|
// Identifiers
|
||||||
qualified_identifier:
|
qualified_identifier:
|
||||||
@ -80,7 +76,7 @@ class_member_declaration:
|
|||||||
| event_declaration // 'event'
|
| event_declaration // 'event'
|
||||||
| 'partial' (method_declaration
|
| 'partial' (method_declaration
|
||||||
| interface_declaration
|
| interface_declaration
|
||||||
| class_declaration
|
| class_declaration[$m.st]
|
||||||
| struct_declaration)
|
| struct_declaration)
|
||||||
| interface_declaration // 'interface'
|
| interface_declaration // 'interface'
|
||||||
| 'void' method_declaration
|
| 'void' method_declaration
|
||||||
@ -93,9 +89,9 @@ class_member_declaration:
|
|||||||
)
|
)
|
||||||
// common_modifiers// (method_modifiers | field_modifiers)
|
// common_modifiers// (method_modifiers | field_modifiers)
|
||||||
|
|
||||||
| class_declaration // 'class'
|
| class_declaration[$m.st] // 'class'
|
||||||
| struct_declaration // 'struct'
|
| struct_declaration // 'struct'
|
||||||
| enum_declaration // 'enum'
|
| enum_declaration[$m.st] // 'enum'
|
||||||
| delegate_declaration // 'delegate'
|
| delegate_declaration // 'delegate'
|
||||||
| conversion_operator_declaration
|
| conversion_operator_declaration
|
||||||
| constructor_declaration // | static_constructor_declaration
|
| constructor_declaration // | static_constructor_declaration
|
||||||
@ -550,8 +546,13 @@ attribute_argument_expression:
|
|||||||
// Class Section
|
// Class Section
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
class_declaration:
|
class_declaration[StringTemplate modifiersST]
|
||||||
'class' type_or_generic class_base? type_parameter_constraints_clauses? class_body ';'? ;
|
@init {
|
||||||
|
List<string> preComments = null;
|
||||||
|
}:
|
||||||
|
^(c=CLASS { preComments = collectComments($c.TokenStartIndex); } nm=PAYLOAD ^(PAYLOAD_LIST PAYLOAD* )
|
||||||
|
class_base? type_parameter_constraints_clauses? class_body )
|
||||||
|
-> class(modifiers = {modifiersST}, name={ $nm }, comments = { preComments } ) ;
|
||||||
class_base:
|
class_base:
|
||||||
// syntactically base class vs interface name is the same
|
// syntactically base class vs interface name is the same
|
||||||
//':' class_type (',' interface_type_list)? ;
|
//':' class_type (',' interface_type_list)? ;
|
||||||
@ -628,9 +629,12 @@ remove_accessor_declaration:
|
|||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// enum declaration
|
// enum declaration
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
enum_declaration:
|
enum_declaration[StringTemplate modifiersST]
|
||||||
'enum' identifier enum_base? enum_body ';'?
|
@init {
|
||||||
-> enum(name={$identifier.text}, body={$enum_body.st}) ;
|
List<string> preComments = null;
|
||||||
|
}:
|
||||||
|
e='enum' { preComments = collectComments($e.TokenStartIndex); } identifier enum_base? enum_body ';'?
|
||||||
|
-> enum(comments = { preComments}, modifiers = { $modifiersST }, name={$identifier.text}, body={$enum_body.st}) ;
|
||||||
enum_base:
|
enum_base:
|
||||||
':' integral_type ;
|
':' integral_type ;
|
||||||
enum_body:
|
enum_body:
|
||||||
@ -764,11 +768,11 @@ struct_member_declaration:
|
|||||||
| event_declaration // 'event'
|
| event_declaration // 'event'
|
||||||
| 'partial' (method_declaration
|
| 'partial' (method_declaration
|
||||||
| interface_declaration
|
| interface_declaration
|
||||||
| class_declaration
|
| class_declaration[$m.st]
|
||||||
| struct_declaration)
|
| struct_declaration)
|
||||||
|
|
||||||
| interface_declaration // 'interface'
|
| interface_declaration // 'interface'
|
||||||
| class_declaration // 'class'
|
| class_declaration[$m.st] // 'class'
|
||||||
| 'void' method_declaration
|
| 'void' method_declaration
|
||||||
| type ( (member_name '(') => method_declaration
|
| type ( (member_name '(') => method_declaration
|
||||||
| (member_name '{') => property_declaration
|
| (member_name '{') => property_declaration
|
||||||
@ -780,7 +784,7 @@ struct_member_declaration:
|
|||||||
// common_modifiers// (method_modifiers | field_modifiers)
|
// common_modifiers// (method_modifiers | field_modifiers)
|
||||||
|
|
||||||
| struct_declaration // 'struct'
|
| struct_declaration // 'struct'
|
||||||
| enum_declaration // 'enum'
|
| enum_declaration[$m.st] // 'enum'
|
||||||
| delegate_declaration // 'delegate'
|
| delegate_declaration // 'delegate'
|
||||||
| conversion_operator_declaration
|
| conversion_operator_declaration
|
||||||
| constructor_declaration // | static_constructor_declaration
|
| constructor_declaration // | static_constructor_declaration
|
||||||
|
@ -513,7 +513,8 @@ attribute_argument_expression:
|
|||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
class_declaration:
|
class_declaration:
|
||||||
'class' type_or_generic class_base? type_parameter_constraints_clauses? class_body ';'? ;
|
^(CLASS PAYLOAD ^(PAYLOAD_LIST PAYLOAD* )
|
||||||
|
class_base? type_parameter_constraints_clauses? class_body ) ;
|
||||||
class_base:
|
class_base:
|
||||||
// syntactically base class vs interface name is the same
|
// syntactically base class vs interface name is the same
|
||||||
//':' class_type (',' interface_type_list)? ;
|
//':' class_type (',' interface_type_list)? ;
|
||||||
|
@ -9,10 +9,12 @@ options {
|
|||||||
tokens {
|
tokens {
|
||||||
PACKAGE;
|
PACKAGE;
|
||||||
ENUM_BODY;
|
ENUM_BODY;
|
||||||
|
CLASS;
|
||||||
|
|
||||||
FINAL; /* final modifier */
|
FINAL; /* final modifier */
|
||||||
|
|
||||||
PAYLOAD; // carries arbitrary text for the output file
|
PAYLOAD; // carries arbitrary text for the output file
|
||||||
|
PAYLOAD_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@namespace { RusticiSoftware.Translator.CSharp }
|
@namespace { RusticiSoftware.Translator.CSharp }
|
||||||
|
@ -21,16 +21,26 @@ package(now, includeDate, packageName, comments, modifiers, type, endComments) :
|
|||||||
package <packageName>;
|
package <packageName>;
|
||||||
|
|
||||||
<comments; separator="\n">
|
<comments; separator="\n">
|
||||||
|
<type>
|
||||||
<modifiers> <type>
|
|
||||||
|
|
||||||
<endComments; separator="\n">
|
<endComments; separator="\n">
|
||||||
>>
|
>>
|
||||||
|
|
||||||
|
// ******* CLASSES ***********
|
||||||
|
|
||||||
enum(comments, attributes, name, body) ::= <<
|
class(modifiers, comments, attributes, name, body) ::= <<
|
||||||
<comments; separator="\n">
|
<comments; separator="\n">
|
||||||
enum <name>
|
<modifiers(modifiers)>class <name>
|
||||||
|
{
|
||||||
|
<body>
|
||||||
|
}
|
||||||
|
>>
|
||||||
|
|
||||||
|
// ******* ENUMS ***********
|
||||||
|
|
||||||
|
enum(modifiers,comments, attributes, name, body) ::= <<
|
||||||
|
<comments; separator="\n">
|
||||||
|
<modifiers(modifiers)>enum <name>
|
||||||
{
|
{
|
||||||
<body>
|
<body>
|
||||||
}
|
}
|
||||||
@ -43,7 +53,8 @@ enum_member(comments, value) ::= <<
|
|||||||
<value>
|
<value>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
modifiers(mods) ::= "<mods; separator=\" \">"
|
modifiers(mods) ::= "<mods; separator=\" \"><if(mods)> <endif>"
|
||||||
|
//modifiers(mods) ::= "<mods; separator=\" \">"
|
||||||
|
|
||||||
// utility
|
// ******* UTILITY ***********
|
||||||
string(payload) ::= "<payload>"
|
string(payload) ::= "<payload>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user