mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
Add CommonWalker base class for common helper methods
This commit is contained in:
parent
d68a8dd4a0
commit
85bce1eac3
22
CSharpTranslator/antlr3/src/cs2j/CSharp/CommonWalker.cs
Normal file
22
CSharpTranslator/antlr3/src/cs2j/CSharp/CommonWalker.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Antlr.Runtime.Tree;
|
||||
using Antlr.Runtime;
|
||||
|
||||
namespace RusticiSoftware.Translator.CSharp
|
||||
{
|
||||
public class CommonWalker : TreeParser
|
||||
{
|
||||
protected CommonWalker(ITreeNodeStream input, RecognizerSharedState state)
|
||||
: base(input, state)
|
||||
{ }
|
||||
|
||||
|
||||
protected void Debug(String s)
|
||||
{
|
||||
Console.Out.WriteLine(s);
|
||||
}
|
||||
}
|
||||
}
|
63
CSharpTranslator/antlr3/src/cs2j/CSharp/SignatureExtracter.g
Normal file
63
CSharpTranslator/antlr3/src/cs2j/CSharp/SignatureExtracter.g
Normal file
@ -0,0 +1,63 @@
|
||||
// SignatureExtracter.g
|
||||
//
|
||||
// Crawler that extracts the signatures (typereptemplates) from a CSharp AST
|
||||
//
|
||||
// Kevin Glynn
|
||||
// kevin.glynn@twigletsoftware.com
|
||||
// June 2010
|
||||
|
||||
tree grammar SignatureExtracter;
|
||||
|
||||
options {
|
||||
tokenVocab=cs;
|
||||
ASTLabelType=CommonTree;
|
||||
language=CSharp2;
|
||||
superClass='RusticiSoftware.Translator.CSharp.CommonWalker';
|
||||
//backtrack=true;
|
||||
}
|
||||
|
||||
@namespace { RusticiSoftware.Translator.CSharp }
|
||||
|
||||
@header
|
||||
{
|
||||
using System.Text;
|
||||
using RusticiSoftware.Translator.CLR;
|
||||
}
|
||||
|
||||
@members
|
||||
{
|
||||
// As we scan the AST we collect these features until
|
||||
// we reach the end, then calculate the TypeRep and insert it into
|
||||
// the TypeEnv
|
||||
private IList<PropRepTemplate> Properties = new List<PropRepTemplate>();
|
||||
private IList<MethodRepTemplate> Methods = new List<MethodRepTemplate>();
|
||||
private IList<ConstructorRepTemplate> Constructors = new List<ConstructorRepTemplate>();
|
||||
private IList<FieldRepTemplate> Fields = new List<FieldRepTemplate>();
|
||||
private IList<CastRepTemplate> Casts = new List<CastRepTemplate>();
|
||||
}
|
||||
|
||||
/********************************************************************************************
|
||||
Parser section
|
||||
*********************************************************************************************/
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
compilation_unit:
|
||||
{ Debug("Debug: start"); } using_directives
|
||||
;
|
||||
|
||||
using_directives:
|
||||
^(USING_DIRECTIVE 'using' { Console.Out.WriteLine("Debug: using"); } namespace_name ';')
|
||||
;
|
||||
|
||||
namespace_name:
|
||||
^(NAMESPACE_OR_TYPE_NAME namespace_component)
|
||||
;
|
||||
|
||||
namespace_component:
|
||||
^(NSTN identifier)
|
||||
;
|
||||
|
||||
identifier:
|
||||
^(ID id=IDENTIFIER { Console.Out.WriteLine("Identifier: " + id.Text);})
|
||||
;
|
||||
|
@ -44,7 +44,7 @@ namespace_component2:
|
||||
;
|
||||
|
||||
identifier2:
|
||||
^(ID id=IDENTIFIER { Console.Out.WriteLine("Identifier: " + id.Text);})
|
||||
^(ID IDENTIFIER { Console.Out.WriteLine("Identifier: " + $IDENTIFIER.Text);})
|
||||
;
|
||||
|
||||
compilation_unit:
|
||||
|
@ -57,6 +57,7 @@
|
||||
<Compile Include="AntlrUtils\AntlrUtils.cs" />
|
||||
<Compile Include="CLR\cs2j.cs" />
|
||||
<Compile Include="CLR\TypeRep.cs" />
|
||||
<Compile Include="CSharp\CommonWalker.cs" />
|
||||
<Compile Include="CSharp\csCrawl.cs" />
|
||||
<Compile Include="CSharp\csLexer.cs" />
|
||||
<Compile Include="CSharp\csParser.cs" />
|
||||
@ -64,10 +65,12 @@
|
||||
<Compile Include="CSharp\minDriver.cs" />
|
||||
<Compile Include="CSharp\PreProcessor.cs" />
|
||||
<Compile Include="CLR\TranslationTemplate.cs" />
|
||||
<Compile Include="CSharp\SignatureExtracter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utils\DirectoryHT.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CSharp\SignatureExtracter.g" />
|
||||
<None Include="CSharp\csCrawl.g" />
|
||||
<None Include="CSharp\cs.g" />
|
||||
</ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user