[svn] r6138: nemerle/trunk/ncc: parsing/MainParser.n
testsuite/positive/topexpr.n
nazgul
svnadmin at nemerle.org
Sun Feb 26 12:31:53 CET 2006
Log:
Allow top level expr just after assembly attribute
Author: nazgul
Date: Sun Feb 26 12:31:50 2006
New Revision: 6138
Modified:
nemerle/trunk/ncc/parsing/MainParser.n
nemerle/trunk/ncc/testsuite/positive/topexpr.n
Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n (original)
+++ nemerle/trunk/ncc/parsing/MainParser.n Sun Feb 26 12:31:50 2006
@@ -159,13 +159,15 @@
def parser = MainParser (GlobalEnv.Core);
mutable result = [];
- mutable topstream = preparser.ParseTopLevel ().Child;
+ mutable topstream = preparser.ParseTopLevel ().Child :> Token.LooseGroup;
def iter () {
- when (topstream != null)
+ when (topstream != null) {
+ parser.eat_assembly_attributes (topstream);
+
if (IsTopLevel (topstream)) {
result = parser.ParseTopLevel (topstream, result);
- topstream = topstream.Next;
+ topstream = topstream.Next :> Token.LooseGroup;
iter ();
}
else {
@@ -180,14 +182,15 @@
result = decl :: result;
}
}
+ }
iter ();
List.Rev (result);
}
- static IsTopLevel (tok : Token) : bool
+ static IsTopLevel (tok : Token.LooseGroup) : bool
{
- match ((tok :> Token.LooseGroup).Child) {
+ match (tok.Child) {
| Token.Keyword (k) =>
match (k) {
| "public" | "private" | "static" | "internal"
@@ -197,9 +200,8 @@
| _ => false
}
- | Token.SquareGroup => true
-
- | Token.Namespace | Token.Using => true
+ | Token.SquareGroup
+ | Token.Namespace | Token.Using | null => true
| _ => false
}
@@ -468,10 +470,10 @@
/** This function parses top level group updating global environment
when entering into new namespace, using directive, class, etc.
*/
- ParseTopLevel (tok : Token, mutable acc : list [TopDeclaration]) : list [TopDeclaration]
+ ParseTopLevel (tok : Token.LooseGroup, mutable acc : list [TopDeclaration]) : list [TopDeclaration]
{
- match (tok) {
- | Token.LooseGroup (tokens) =>
+ eat_assembly_attributes (tok);
+ def tokens = tok.Child;
match (tokens) {
| Token.Namespace (new_env, _) =>
def begin_env = env;
@@ -480,7 +482,7 @@
env = new_env;
// parse elements of namespace with new environment enabled
- foreach (child is Token in tokens)
+ foreach (child :> Token.LooseGroup in tokens)
acc = ParseTopLevel (child, acc);
// bring env from outside of namespace
@@ -493,10 +495,16 @@
| Token.SquareGroup (null) => Error (tok, "empty custom attribute"); acc
+ | null => acc
+
+ | _ => ParseTypeDeclaration (tokens) :: acc
+ }
+ }
+
// assembly attribute
- | Token.SquareGroup (inner) as square =>
- match (inner) {
- | Token.LooseGroup (Token.Identifier ("assembly")) =>
+ eat_assembly_attributes (tok : Token.LooseGroup) : void {
+ match (tok.Child) {
+ | Token.SquareGroup (LooseGroup (Identifier ("assembly"))) as square =>
mutable assembly_custom = [square];
def mods = Modifiers (NemerleAttributes.None, []);
take_attributes_out (ref assembly_custom, System.AttributeTargets.Assembly,
@@ -504,18 +512,10 @@
foreach (cust in mods.custom_attrs)
AttributeCompiler.AddAssemblyAttribute (env, cust);
- // executed only in case of [assembly: .. ] [ .. ]
- if (square.Next != null)
- ParseTopLevel (Token.LooseGroup (square.Next.Location, square.Next), acc)
- else
- acc
-
- | _ => ParseTypeDeclaration (tokens) :: acc
- }
- | _ => ParseTypeDeclaration (tokens) :: acc
- }
+ tok.Child = square.Next;
+ eat_assembly_attributes (tok);
- | x => Error (x, "expecting group of tokens"); acc
+ | _ => ()
}
}
Modified: nemerle/trunk/ncc/testsuite/positive/topexpr.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/topexpr.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/topexpr.n Sun Feb 26 12:31:50 2006
@@ -1,5 +1,9 @@
using Nemerle.IO;
+[assembly: System.Reflection.AssemblyTitle("test test test")]
+
+System.Console.WriteLine("hello there!");
+
def f (x) {
x + 1
}
@@ -14,6 +18,7 @@
/*
BEGIN-OUTPUT
+hello there!
23ba
END-OUTPUT
*/
More information about the svn
mailing list