Skip to content

Commit

Permalink
trying to connect the skeleton demo to fodder
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Jan 24, 2013
1 parent d35cc96 commit 215b3a2
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions shared/rascal/src/demo/SkeletonCS.rsc
Expand Up @@ -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*;

Expand All @@ -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 = ![{]* !>> ![{];

Expand All @@ -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 += ["<ud.usingDirectiveInsides>"];
return "<us>";
}

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 <f>...");
//if (good+bad % 100 == 0)
println("<good+bad> files processed: <good> successes, <bad> failures.");
try
{
parse(#start[CompilationUnit], dir+f);
good += 1;
}
catch ParseError(_):
//catch:
bad += 1;
}
println("Grand total: <good> files parsed, <bad> files failed.");
}

0 comments on commit 215b3a2

Please sign in to comment.