Permalink
Browse files

TestParser for TestUtil

  • Loading branch information...
1 parent 8d02b02 commit 7eabf20f45f1dc47525fcc158653a6d363b981d3 @someone-with-default-username someone-with-default-username committed Aug 10, 2012
View
8 Tests/TestUtil/Framework/GoldTest.n
@@ -27,7 +27,13 @@ namespace TestUtil.Framework
public override Run() : Result
{
- Result.Success()
+ def testSource = N2.SourceSnapshot(File.ReadAllText(_filePath), fileName = _filePath);
+ def parser = TestParser.GrammarImpl();
+ def (pos, ast) = parser.TryParseStart(testSource);
+ if(pos >= 0)
+ Result.Success()
+ else
+ Result.UnableToRun("Parse error")
}
private _filePath : string;
View
94 Tests/TestUtil/Framework/TestParser.n2
@@ -0,0 +1,94 @@
+using N2;
+
+syntax module TestParser
+{
+ token field Quote = "\"";
+ token field Comma = ",";
+ token field OpenBrace = "{";
+ token field CloseBrace = "}";
+ token field Quote = "\"";
+ token field Comma = ",";
+ token field Prefix = "\\u";
+
+ span class String;
+ span class Keyword = ['a'..'z']['a'..'z']+;
+ span class Operator = ['+', '-', '/', '*', '^', '?', ':']+;
+ span class OpenBrace = "(" | "{" | "[";
+ span class CloseBrace = ")" | "}" | "]";
+
+ braces "{", "}";
+
+ token Any = ['\u0000'..'\uFFFF'];
+ token NewLineCharacter = '\n'
+ | '\r'
+ | '\u2028' /* line separator */
+ | '\u2029'; /* paragraph separator */
+ token NewLine = "\r\n" | NewLineCharacter;
+ token Whitespace = [Zs]
+ | '\t'
+ | '\v' /* vertial tab */
+ | '\f'; /* form feed */
+ token Space = Whitespace | NewLine;
+ token Spaces = Space+;
+
+ syntax IgnoreToken;
+
+ [Ast( Start, Body, NewLine)]
+ syntax SingleLineComment is IgnoreToken = "//" (!NewLine Any)* NewLine?;
+
+ [Ast( Start, Body, End)]
+ syntax MultiLineComment is IgnoreToken = "/*" (!"*/" Any)* "*/";
+
+ syntax SpaceToken is IgnoreToken = Spaces;
+
+ void s = IgnoreToken*; /* optional spacer */
+ void S = !IdentifierPartCharacters s; /* identifier break spacer */
+
+ token LetterCharacter = ['A'..'Z', 'a'..'z', 'а'..'я', 'А'..'Я'];//[Lu, Ll, Lt, Lm, Lo, Nl];
+ token CombiningCharacter = [Mn, Mc];
+ token DecimalDigitCharacter = [Nd];
+ token ConnectingCharacter = [Pc];
+ token FormattingCharacter = [Cf];
+ token IdentifierStartCharacter = LetterCharacter | "_";
+ token IdentifierPartCharacters = LetterCharacter | DecimalDigitCharacter | ConnectingCharacter | CombiningCharacter | FormattingCharacter;
+ token IdentifierBody = IdentifierStartCharacter IdentifierPartCharacters*;
+ token HexDigit = ['0'..'9', 'a'..'f', 'A'..'F'];
+ token ReservedStringChar = "\"" | "\\";
+ token ReservedCharChar = "\'" | "\\";
+
+ token Terminator = "go" NewLine;
+
+ token TestBody = Any*;
+
+ [SpanClass(String)]
+ syntax StringLiteral = "\"" StringPart* "\"" s;
+
+ syntax StringPart;
+
+ [Ast( Chars)]
+ syntax SimpleStringPart is StringPart = (!ReservedStringChar Any)+;
+
+ syntax UnicodeEscapeSequenceStringPart is StringPart = "\\u" HexDigit HexDigit HexDigit HexDigit;
+
+ [Ast( Backslash, Char)]
+ syntax EscapeSequenceStringPart is StringPart = "\\" Any;
+
+ syntax Identifier = IdentifierBody s;
+
+ [Ast( Names)]
+ syntax QIdentifier = (Identifier; "."s)+;
+
+ syntax TopDeclaration;
+
+ [Ast( _, FilePath, _, _, _)]
+ syntax AssemblyReference is TopDeclaration = "reference"S StringLiteral "{"s (GrammarReference; ","s)* "}"s;
+
+ [Ast( GrammarName, _)]
+ syntax GrammarReference = QIdentifier StartRuleReference?;
+
+ [Ast( _, RuleName)]
+ syntax StartRuleReference = "start"S QIdentifier?;
+
+ [StartRule]
+ syntax Start = s TopDeclaration* Terminator TestBody;
+}
View
5 Tests/TestUtil/Main.n
@@ -10,11 +10,14 @@ using System.Linq;
using TestUtil.Framework;
using TestUtil.Utils;
+[assembly: N2.N2Source("Framework\\TestParser.n2")]
+
module Program
{
Main(fileMasks : array[string]) : void
{
def runner = Runner(ConsoleExecutionListener());
- runner.Run(FileSearcher.Search(fileMasks).Select(GoldTest));
+ def testsToRun = FileSearcher.Search(fileMasks).Select(GoldTest);
+ runner.Run(testsToRun);
}
}
View
10 Tests/TestUtil/TestUtil.nproj
@@ -57,6 +57,11 @@
<MacroReference Include="Nemerle.Linq">
<HintPath>$(Nemerle)\Nemerle.Linq.dll</HintPath>
</MacroReference>
+ <ProjectReference Include="..\..\N2\N2.Compiler\N2.Compiler.nproj">
+ <Name>N2.Compiler</Name>
+ <Project>{a8aaca46-ccc8-429f-b626-4cfc77f3a21a}</Project>
+ <Private>True</Private>
+ </ProjectReference>
<ProjectReference Include="..\..\N2\N2.Runtime\N2.Runtime.nproj">
<Name>N2.Runtime</Name>
<Project>{9db13eb2-28e3-432b-8c8f-0e39ef5bcc38}</Project>
@@ -99,6 +104,11 @@
<Folder Include="Utils" />
<Folder Include="Properties\" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="Framework\TestParser.n2">
+ <SubType>Content</SubType>
+ </Content>
+ </ItemGroup>
<Import Project="$(Nemerle)\Nemerle.MSBuild.targets" />
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.

0 comments on commit 7eabf20

Please sign in to comment.