From 215b3a2649145f66a2a7d1f35650ef132b07c19c Mon Sep 17 00:00:00 2001 From: grammarware Date: Thu, 24 Jan 2013 15:29:07 +0100 Subject: [PATCH] trying to connect the skeleton demo to fodder --- shared/rascal/src/demo/SkeletonCS.rsc | 60 +++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/shared/rascal/src/demo/SkeletonCS.rsc b/shared/rascal/src/demo/SkeletonCS.rsc index c3fadef0..43338881 100644 --- a/shared/rascal/src/demo/SkeletonCS.rsc +++ b/shared/rascal/src/demo/SkeletonCS.rsc @@ -4,8 +4,30 @@ module demo::SkeletonCS import ParseTree; import util::IDE; import IO; - -layout WS = [\t-\n\r\ ]* !>> [\t-\n\r\ ]; +import Exception; +import String; + +//extend lang::std::Layout; // + \0xFEFF + +lexical Whitespace + = [\u0009-\u000D \u0020 \u0085 \u00A0 \u1680 \u180E \u2000-\u200A \u2028 \u2029 \u202F \u205F \u3000 \uFEFF] + ; +layout Standard + = WhitespaceOrComment* + !>> [\u0009-\u000D \u0020 \u0085 \u00A0 \u1680 \u180E \u2000-\u200A \u2028 \u2029 \u202F \u205F \u3000 \uFEFF] + !>> "//"; + +syntax WhitespaceOrComment + = whitespace: Whitespace + | comment: Comment + ; +lexical Comment + = @category="Comment" "//" ![\n\r]* $ + | @category="Comment" "/*" CommentElement* "*/" + ; +lexical CommentElement = ![*] | [*] !>> "/"; + +//layout WS = [\t-\n\r\ \uFEFF]* !>> [\t-\n\r\ \uFEFF]; start syntax CompilationUnit = UsingDirective* usingDirectives GlobalAttributeSection* NamespaceMemberDeclaration*; @@ -23,11 +45,13 @@ syntax Modifier = "new" | "internal" | "private" | "abstract" - | "sealed"; + | "sealed" + | "static" // added from another version of C# +; syntax AttributeSection = "[" LexNotRightSquareBracket attributeSectionInsides "]"; -syntax NamespaceMemberDeclarationInsides = NamespaceMemberName namespaceMemberName LexNotWhitespace identifier1 LexNotLeftCurly? identifier2 LexBalancedCurlies namespaceMemberInsides ";"?; +syntax NamespaceMemberDeclarationInsides = NamespaceMemberName namespaceMemberName LexNotWhitespace? identifier1 LexNotLeftCurly? identifier2 LexBalancedCurlies namespaceMemberInsides ";"?; lexical LexNotLeftCurly = ![{]* !>> ![{]; @@ -54,18 +78,40 @@ public void main() registerContributions("CSharp",{popup(menu("CSharp",[edit("using2dot",using2dot)]))}); println("Menu item registered.");} -public str using2dot(CompilationUnit cu, loc z) +public str using2dot(start[CompilationUnit] cu, loc z) { list[str] us = []; - for (UsingDirective ud <- cu.usingDirectives) + for (UsingDirective ud <- cu.top.usingDirectives) us += [""]; return ""; } public void tryit() { - r = parse(#CompilationUnit, |home:///projects/slps/shared/rascal/src/demo/Program.cs|); + r = parse(#start[CompilationUnit], |home:///projects/slps/shared/rascal/src/demo/sample.cs|); println(r); println(using2dot(r,|cwd:///|)); //println("Language registered."); +} + +public void tryall() +{ + loc dir = |home:///projects/fodder/csharp/mono/|; + int good = 0, bad = 0; + for (f <- listEntries(dir)) + { + if (!endsWith(f,".cs")) continue; + println("Processing ..."); + //if (good+bad % 100 == 0) + println(" files processed: successes, failures."); + try + { + parse(#start[CompilationUnit], dir+f); + good += 1; + } + catch ParseError(_): + //catch: + bad += 1; + } + println("Grand total: files parsed, files failed."); } \ No newline at end of file