mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
option to omit timestamps, static constructors, indexers
This commit is contained in:
parent
f441c00bb5
commit
11624cc674
@ -32,12 +32,16 @@ namespace RusticiSoftware.Translator.CSharp
|
|||||||
|
|
||||||
public bool Warnings { get; set; }
|
public bool Warnings { get; set; }
|
||||||
|
|
||||||
private bool translatorKeepParens = true;
|
|
||||||
public bool TranslatorKeepParens
|
public bool TranslatorKeepParens
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TranslatorAddTimeStamp
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
public CS2JSettings ()
|
public CS2JSettings ()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -65,6 +69,7 @@ namespace RusticiSoftware.Translator.CSharp
|
|||||||
Warnings = false;
|
Warnings = false;
|
||||||
|
|
||||||
TranslatorKeepParens = true;
|
TranslatorKeepParens = true;
|
||||||
|
TranslatorAddTimeStamp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,7 @@ namespace RusticiSoftware.Translator.CSharp
|
|||||||
.Add ("exappdir=", dirs => addDirectories(cfg.ExAppRoot, dirs))
|
.Add ("exappdir=", dirs => addDirectories(cfg.ExAppRoot, dirs))
|
||||||
.Add ("exclude=", dirs => addDirectories(cfg.Exclude, dirs))
|
.Add ("exclude=", dirs => addDirectories(cfg.Exclude, dirs))
|
||||||
.Add ("translator-keep-parens=", v => cfg.TranslatorKeepParens = Boolean.Parse(v))
|
.Add ("translator-keep-parens=", v => cfg.TranslatorKeepParens = Boolean.Parse(v))
|
||||||
|
.Add ("translator-timestamp-files=", v => cfg.TranslatorAddTimeStamp = Boolean.Parse(v))
|
||||||
;
|
;
|
||||||
|
|
||||||
//TODO: fix enum dump
|
//TODO: fix enum dump
|
||||||
|
@ -302,7 +302,7 @@ class_member_declaration:
|
|||||||
| e3=enum_declaration -> ^(ENUM[$e3.start.Token, "ENUM"] $a? $m? $e3)
|
| e3=enum_declaration -> ^(ENUM[$e3.start.Token, "ENUM"] $a? $m? $e3)
|
||||||
| d3=delegate_declaration -> ^(DELEGATE[$d3.start.Token, "DELEGATE"] $a? $m? $d3)
|
| d3=delegate_declaration -> ^(DELEGATE[$d3.start.Token, "DELEGATE"] $a? $m? $d3)
|
||||||
| co3=conversion_operator_declaration -> ^(CONVERSION_OPERATOR[$co3.start.Token, "CONVERSION"] $a? $m? $co3)
|
| co3=conversion_operator_declaration -> ^(CONVERSION_OPERATOR[$co3.start.Token, "CONVERSION"] $a? $m? $co3)
|
||||||
| con3=constructor_declaration -> ^(CONSTRUCTOR[$con3.start.Token, "CONSTRUCTOR"] $a? $m? $con3)
|
| con3=constructor_declaration[$a.tree, $m.tree, $m.modList] -> $con3
|
||||||
| de3=destructor_declaration -> ^(DESTRUCTOR[$de3.start.Token, "DESTRUCTOR"] $a? $m? $de3)
|
| de3=destructor_declaration -> ^(DESTRUCTOR[$de3.start.Token, "DESTRUCTOR"] $a? $m? $de3)
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
@ -1152,7 +1152,7 @@ interface_event_declaration [CommonTree atts, CommonTree mods]:
|
|||||||
'event' type identifier ';' ;
|
'event' type identifier ';' ;
|
||||||
interface_indexer_declaration [CommonTree atts, CommonTree mods, CommonTree type]:
|
interface_indexer_declaration [CommonTree atts, CommonTree mods, CommonTree type]:
|
||||||
// attributes? 'new'? type
|
// attributes? 'new'? type
|
||||||
'this' '[' formal_parameter_list ']' '{' interface_accessor_declarations[atts,mods,type, "INDEX"] '}' ;
|
'this' '[' formal_parameter_list ']' '{' indexer_accessor_declarations[atts,mods,type,$formal_parameter_list.tree] '}' ;
|
||||||
interface_accessor_declarations [CommonTree atts, CommonTree mods, CommonTree type, String propName]:
|
interface_accessor_declarations [CommonTree atts, CommonTree mods, CommonTree type, String propName]:
|
||||||
interface_accessor_declaration[atts, mods, type, propName]+
|
interface_accessor_declaration[atts, mods, type, propName]+
|
||||||
;
|
;
|
||||||
@ -1211,11 +1211,26 @@ scope TypeContext;
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
indexer_declaration [CommonTree atts, CommonTree mods, CommonTree type]:
|
indexer_declaration [CommonTree atts, CommonTree mods, CommonTree type]:
|
||||||
indexer_declarator '{' accessor_declarations[atts, mods, type, "INDEX", "INDEX"] '}' ;
|
'this' '[' formal_parameter_list ']' '{' indexer_accessor_declarations[atts, mods, type, $formal_parameter_list.tree] '}' ;
|
||||||
indexer_declarator:
|
//indexer_declarator:
|
||||||
//(type_name '.')?
|
//(type_name '.')?
|
||||||
'this' '[' formal_parameter_list ']' ;
|
// 'this' '[' formal_parameter_list ']' ;
|
||||||
|
|
||||||
|
|
||||||
|
indexer_accessor_declarations [CommonTree atts, CommonTree mods, CommonTree type, CommonTree idxparams]:
|
||||||
|
indexer_accessor_declaration[atts, mods, type, idxparams]+;
|
||||||
|
|
||||||
|
indexer_accessor_declaration [CommonTree atts, CommonTree mods, CommonTree type, CommonTree idxparams]
|
||||||
|
@init {
|
||||||
|
CommonTree idxBlock = null;
|
||||||
|
}:
|
||||||
|
la=attributes? lm=accessor_modifier?
|
||||||
|
(g='get' ((';')=> gbe=';' { idxBlock = $gbe.tree; }
|
||||||
|
| gb=block { idxBlock = $gb.tree; } ) geti=magicIdxGetter[atts, $la.tree, mods, $lm.tree, type, $g.token, idxBlock, idxparams] -> $geti
|
||||||
|
| s='set' ((';')=> sbe=';' { idxBlock = $sbe.tree; }
|
||||||
|
| sb=block { idxBlock = $sb.tree; } ) seti=magicIdxSetter[atts, $la.tree, mods, $lm.tree, type, $s.token, idxBlock, idxparams] -> $seti)
|
||||||
|
;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
operator_declaration:
|
operator_declaration:
|
||||||
operator_declarator operator_body ;
|
operator_declarator operator_body ;
|
||||||
@ -1242,9 +1257,10 @@ operator_body:
|
|||||||
block ;
|
block ;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
constructor_declaration:
|
constructor_declaration[CommonTree atts, CommonTree mods, List<String> modList]:
|
||||||
i=identifier '(' p=formal_parameter_list? ')' init=constructor_initializer? b=constructor_body[$init.tree]
|
i=identifier '(' p=formal_parameter_list? ')' init=constructor_initializer? b=constructor_body[$init.tree] sb=magicSmotherExceptions[$b.tree]
|
||||||
-> $i $p? $b;
|
-> {modList.Contains("static")}? ^(STATIC_CONSTRUCTOR[$i.tree.Token, "CONSTRUCTOR"] { dupTree($atts) } { dupTree($mods) } $sb)
|
||||||
|
-> ^(CONSTRUCTOR[$i.tree.Token, "CONSTRUCTOR"] { dupTree($atts) } { dupTree($mods) } $i $p? $b);
|
||||||
constructor_initializer:
|
constructor_initializer:
|
||||||
':' tok='this' '(' argument_list? ')'
|
':' tok='this' '(' argument_list? ')'
|
||||||
-> ^(APPLY[$tok.token, "APPLY"] $tok argument_list?) SEMI[$tok.token, ";"]
|
-> ^(APPLY[$tok.token, "APPLY"] $tok argument_list?) SEMI[$tok.token, ";"]
|
||||||
@ -1567,6 +1583,20 @@ magicGetterBody[IToken getTok, String varName]:
|
|||||||
magicSetterBody[IToken setTok, String varName]:
|
magicSetterBody[IToken setTok, String varName]:
|
||||||
-> OPEN_BRACE[setTok,"{"] IDENTIFIER[setTok, varName] ASSIGN[setTok,"="] IDENTIFIER[setTok, "value"] SEMI[setTok, ";"] CLOSE_BRACE[setTok,"}"] ;
|
-> OPEN_BRACE[setTok,"{"] IDENTIFIER[setTok, varName] ASSIGN[setTok,"="] IDENTIFIER[setTok, "value"] SEMI[setTok, ";"] CLOSE_BRACE[setTok,"}"] ;
|
||||||
|
|
||||||
|
magicIdxGetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken getTok, CommonTree body, CommonTree idxparams]
|
||||||
|
:
|
||||||
|
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } { dupTree(type)} IDENTIFIER[getTok, "get___idx"] { dupTree(idxparams) } { dupTree(body) } EXCEPTION[getTok, "Throwable"])
|
||||||
|
;
|
||||||
|
magicIdxSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken setTok, CommonTree body, CommonTree idxparams]
|
||||||
|
@init {
|
||||||
|
CommonTree augParams = dupTree(idxparams);
|
||||||
|
adaptor.AddChild(augParams, dupTree($type));
|
||||||
|
adaptor.AddChild(augParams, (CommonTree)adaptor.Create(IDENTIFIER, setTok, "value"));
|
||||||
|
}
|
||||||
|
:
|
||||||
|
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } ^(TYPE[setTok, "TYPE"] IDENTIFIER[setTok, "void"] ) IDENTIFIER[setTok, "set___idx"] { augParams } { dupTree(body) } EXCEPTION[setTok, "Throwable"] )
|
||||||
|
;
|
||||||
|
|
||||||
// keving: can't get this to work reasonably
|
// keving: can't get this to work reasonably
|
||||||
//magicMkConstModifiers[IToken tok, List<string> filter]:
|
//magicMkConstModifiers[IToken tok, List<string> filter]:
|
||||||
// ({ !filter.Contains("static") }?=> -> STATIC[tok, "static"] ) ( { !filter.Contains("public") }?=> -> $magicMkConstModifiers FINAL[tok, "final"] );
|
// ({ !filter.Contains("static") }?=> -> STATIC[tok, "static"] ) ( { !filter.Contains("public") }?=> -> $magicMkConstModifiers FINAL[tok, "final"] );
|
||||||
|
@ -226,7 +226,7 @@ compilation_unit
|
|||||||
}
|
}
|
||||||
:
|
:
|
||||||
^(PACKAGE nm=PAYLOAD modifiers? type_declaration[$modifiers.st] { if (IsLast) collectComments(); }) ->
|
^(PACKAGE nm=PAYLOAD modifiers? type_declaration[$modifiers.st] { if (IsLast) collectComments(); }) ->
|
||||||
package(now = {DateTime.Now}, includeDate = {true}, packageName = {($nm.text != null && $nm.text.Length > 0 ? $nm.text : null)},
|
package(now = {DateTime.Now}, includeDate = {Cfg.TranslatorAddTimeStamp}, packageName = {($nm.text != null && $nm.text.Length > 0 ? $nm.text : null)},
|
||||||
type = {$type_declaration.st},
|
type = {$type_declaration.st},
|
||||||
endComments = { CollectedComments });
|
endComments = { CollectedComments });
|
||||||
|
|
||||||
@ -269,6 +269,8 @@ class_member_declaration returns [List<String> preComments]:
|
|||||||
| ^(CONVERSION_OPERATOR attributes? modifiers? conversion_operator_declaration)
|
| ^(CONVERSION_OPERATOR attributes? modifiers? conversion_operator_declaration)
|
||||||
| ^(CONSTRUCTOR attributes? modifiers? identifier formal_parameter_list? { $preComments = CollectedComments; } block)
|
| ^(CONSTRUCTOR attributes? modifiers? identifier formal_parameter_list? { $preComments = CollectedComments; } block)
|
||||||
-> constructor(modifiers={$modifiers.st}, name={ $identifier.st }, params={ $formal_parameter_list.st }, bodyIsSemi = { $block.isSemi }, body={ $block.st })
|
-> constructor(modifiers={$modifiers.st}, name={ $identifier.st }, params={ $formal_parameter_list.st }, bodyIsSemi = { $block.isSemi }, body={ $block.st })
|
||||||
|
| ^(STATIC_CONSTRUCTOR attributes? modifiers? block)
|
||||||
|
-> static_constructor(modifiers={$modifiers.st}, bodyIsSemi = { $block.isSemi }, body={ $block.st })
|
||||||
| ^(DESTRUCTOR attributes? modifiers? destructor_declaration)
|
| ^(DESTRUCTOR attributes? modifiers? destructor_declaration)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ class_member_declaration:
|
|||||||
| ^(DELEGATE attributes? modifiers? delegate_declaration)
|
| ^(DELEGATE attributes? modifiers? delegate_declaration)
|
||||||
| ^(CONVERSION_OPERATOR attributes? modifiers? conversion_operator_declaration)
|
| ^(CONVERSION_OPERATOR attributes? modifiers? conversion_operator_declaration)
|
||||||
| ^(CONSTRUCTOR attributes? modifiers? identifier formal_parameter_list? block)
|
| ^(CONSTRUCTOR attributes? modifiers? identifier formal_parameter_list? block)
|
||||||
|
| ^(STATIC_CONSTRUCTOR attributes? modifiers? block)
|
||||||
| ^(DESTRUCTOR attributes? modifiers? destructor_declaration)
|
| ^(DESTRUCTOR attributes? modifiers? destructor_declaration)
|
||||||
;
|
;
|
||||||
// class_member_declaration:
|
// class_member_declaration:
|
||||||
|
@ -46,6 +46,7 @@ tokens {
|
|||||||
APPLY;
|
APPLY;
|
||||||
ARGS;
|
ARGS;
|
||||||
NEW;
|
NEW;
|
||||||
|
STATIC_CONSTRUCTOR;
|
||||||
|
|
||||||
RETURN = 'return';
|
RETURN = 'return';
|
||||||
PRIVATE = 'private';
|
PRIVATE = 'private';
|
||||||
|
@ -61,6 +61,14 @@ constructor(modifiers, name, params, exception="Throwable", body, bodyIsSemi) ::
|
|||||||
<\n>
|
<\n>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
|
static_constructor(modifiers, body, bodyIsSemi) ::= <<
|
||||||
|
<modifiers(modifiers)><if(bodyIsSemi)>;
|
||||||
|
<else>
|
||||||
|
<body>
|
||||||
|
<endif>
|
||||||
|
<\n>
|
||||||
|
>>
|
||||||
|
|
||||||
method(modifiers, typeparams, type, name, params, exceptions, body, bodyIsSemi) ::= <<
|
method(modifiers, typeparams, type, name, params, exceptions, body, bodyIsSemi) ::= <<
|
||||||
<modifiers(modifiers)><typeparams> <type> <name>(<params; separator=", ">)<if(exceptions)> throws <exceptions; separator=", "><endif> <if(bodyIsSemi)>;
|
<modifiers(modifiers)><typeparams> <type> <name>(<params; separator=", ">)<if(exceptions)> throws <exceptions; separator=", "><endif> <if(bodyIsSemi)>;
|
||||||
<else>
|
<else>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user