Browse Source

started with implementation of expressions in VB .NET ExpressionFinder Parser

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@5820 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
dceee20409
  1. 3
      src/Libraries/NRefactory/Project/NRefactory.csproj
  2. 2464
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Parser.cs
  3. 69
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/ParserHelper.atg
  4. 2
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/ParserHelper.cs
  5. 68
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/PushParser.frame
  6. 35
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Test/ParserTests.cs
  7. 13
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Test/Program.cs
  8. 8
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Test/VBParserExperiment.csproj

3
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -144,6 +144,9 @@ @@ -144,6 +144,9 @@
<None Include="Src\Parser\VBNet\Experimental\ParserHelper.atg">
<Generator>CocoParserGenerator</Generator>
</None>
<None Include="Src\Parser\VBNet\Experimental\PushParser.frame">
<DependentUpon>ParserHelper.atg</DependentUpon>
</None>
<None Include="Src\Parser\VBNet\Experimental\Scanner.frame">
<DependentUpon>ParserHelper.atg</DependentUpon>
</None>

2464
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Parser.cs

File diff suppressed because it is too large Load Diff

69
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/ParserHelper.atg

@ -5,9 +5,8 @@ using System.Text; @@ -5,9 +5,8 @@ using System.Text;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Parser.VB;
using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute;
using ICSharpCode.NRefactory.Parser.VBNet.Experimental;
COMPILER ParserHelper
PUSHCOMPILER ParserHelper
/* START AUTOGENERATED TOKENS SECTION */
TOKENS
@ -243,10 +242,12 @@ TOKENS @@ -243,10 +242,12 @@ TOKENS
PRODUCTIONS
/*------------------------------------------------------------------------*/
ParserHelper =
(. PushContext(Context.Global); .)
{ OptionStatement }
{ ImportsStatement }
{ AttributeBlock }
{ NamespaceMemberDeclaration }
(. PopContext(); .)
.
StatementTerminator = EOL | ":" .
@ -259,7 +260,6 @@ ImportsStatement = @@ -259,7 +260,6 @@ ImportsStatement =
"Imports" { ANY } StatementTerminator
.
AttributeBlock =
"<" { ANY } ">" [ EOL ]
.
@ -279,22 +279,23 @@ TypeDeclaration = @@ -279,22 +279,23 @@ TypeDeclaration =
{ TypeModifier }
"Module" { ANY } StatementTerminator
(. PushContext(Context.Type); .)
{ ModuleMemberDeclaration }
{ MemberDeclaration }
"End" "Module" StatementTerminator
(. PopContext(); .)
.
ModuleMemberDeclaration
MemberDeclaration =
(. PushContext(Context.Member); .)
=
SubOrFunctionDeclaration
(
SubOrFunctionDeclaration
)
(. PopContext(); .)
.
SubOrFunctionDeclaration =
{ AttributeBlock } { MemberModifier } ("Sub" | "Function")
(. PushContext(Context.IdentifierExpected); .) ANY (. PopContext(); .)
[ "(" [ ParameterList ] ")" ] EOL
[ "(" [ ParameterList ] ")" ] [ "As" TypeName ] EOL
[ Block ]
"End" ("Sub" | "Function") StatementTerminator
.
@ -304,13 +305,62 @@ ParameterList = @@ -304,13 +305,62 @@ ParameterList =
.
Parameter =
{ AttributeBlock } { ParameterModifier } Identifier [ "As" ANY ] [ "=" { ANY } ]
{ AttributeBlock } { ParameterModifier } Identifier [ "As" TypeName ] [ "=" Expression ]
.
Block =
EOL
.
Expression =
Literal |
( "(" Expression ")" ) |
( Identifier [ "(" "Of" TypeName { "," TypeName } ")" ] ) |
"AddressOf" Expression |
.
PrimitiveTypeName =
"Byte" |
"SByte" |
"UShort" |
"Short" |
"UInteger" |
"Integer" |
"ULong" |
"Long" |
"Single" |
"Double" |
"Decimal" |
"Boolean" |
"Date" |
"Char" |
"String" |
"Object"
.
TypeName = ( "Global" | Identifier | PrimitiveTypeName ) { TypeSuffix } { "." IdentifierOrKeyword { TypeSuffix } } .
TypeSuffix = "(" ( "Of" TypeName { "," TypeName } | { "," /*[ EOL ]*/ } ) ")" .
IdentifierOrKeyword = ANY .
Literal = LiteralString |
LiteralCharacter |
LiteralInteger |
LiteralDouble |
LiteralSingle |
LiteralDecimal |
LiteralDate |
"True" |
"False" |
"Nothing" |
/* from InstanceExpression */
"Me" |
"MyBase" |
"MyClass"
.
/* This production handles pseudo keywords that are needed in the grammar */
Identifier
(. PushContext(Context.IdentifierExpected); .)
@ -383,5 +433,6 @@ ParameterModifier = @@ -383,5 +433,6 @@ ParameterModifier =
"ParamArray"
.
END ParserHelper.

2
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/ParserHelper.cs

@ -10,7 +10,7 @@ using System.Collections.Generic; @@ -10,7 +10,7 @@ using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Parser.VBNet.Experimental
{
partial class Parser
public partial class Parser
{
Stack<Context> stack = new Stack<Context>();

68
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/PushParser.frame

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
/*----------------------------------------------------------------------
Compiler Generator Coco/R,
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
extended by M. Loeberbauer & A. Woess, Univ. of Linz
with improvements by Pat Terry, Rhodes University
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As an exception, it is allowed to write an extension of Coco/R that is
used as a plugin in non-free software.
If not otherwise stated, any source code generated by Coco/R (other than
Coco/R itself) does not fall under the GNU General Public License.
----------------------------------------------------------------------*/
-->begin
using System;
using System.Collections.Generic;
-->namespace
partial class Parser {
-->constants
const bool T = true;
const bool x = false;
-->declarations
readonly Stack<int> stateStack = new Stack<int>();
public Parser()
{
stateStack.Push(-1); // required so that we don't crash when leaving the root production
}
void Expect(int expectedKind, Token t)
{
if (t.kind != expectedKind)
Error(t);
}
void Error(Token t)
{
}
public void InformToken(Token t)
{
-->informToken
}
static readonly bool[,] set = {
-->initialization
};
} // end Parser
$$$

35
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Test/ParserTests.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
// <version>$Revision$</version>
// </file>
using System;
using NUnit.Framework;
namespace VBParserExperiment
{
[TestFixture]
public class ParserTests
{
[Test]
public void TestMethod()
{
// TODO: Add your test.
}
[TestFixtureSetUp]
public void Init()
{
// TODO: Add Init code.
}
[TestFixtureTearDown]
public void Dispose()
{
// TODO: Add tear down code.
}
}
}

13
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Test/Program.cs

@ -8,7 +8,8 @@ @@ -8,7 +8,8 @@
using System;
using System.IO;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Parser.VB;
using ICSharpCode.NRefactory.Parser;
using VB = ICSharpCode.NRefactory.Parser.VB;
using ICSharpCode.NRefactory.Parser.VBNet.Experimental;
namespace VBParserExperiment
@ -40,9 +41,13 @@ End Namespace @@ -40,9 +41,13 @@ End Namespace
public static void Main(string[] args)
{
Parser p = new Parser(ParserFactory.CreateLexer(SupportedLanguage.VBNet, new StringReader(data)));
p.Parse();
Parser p = new Parser();
ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, new StringReader(data));
Token t;
do {
t = lexer.NextToken();
p.InformToken(t);
} while (t.Kind != VB.Tokens.EOF);
Console.ReadKey(true);
}

8
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Experimental/Test/VBParserExperiment.csproj

@ -30,6 +30,9 @@ @@ -30,6 +30,9 @@
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\..\..\..\..\..\..\bin\Tools\NUnit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@ -44,6 +47,7 @@ @@ -44,6 +47,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ParserTests.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -52,10 +56,6 @@ @@ -52,10 +56,6 @@
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project>
<Name>NRefactory</Name>
</ProjectReference>
<ProjectReference Include="..\..\SharpDevelop\4.0\SharpDevelop\src\Libraries\NRefactory\Project\NRefactory.csproj">
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project>
<Name>NRefactory</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
Loading…
Cancel
Save