[svn] r6435: nemerle/trunk/ncc: parsing/PreParser.n passes.n
VladD2
svnadmin at nemerle.org
Sat Jul 8 14:08:02 CEST 2006
Log:
Has add notification about namespace parsing.
Author: VladD2
Date: Sat Jul 8 14:08:01 2006
New Revision: 6435
Modified:
nemerle/trunk/ncc/parsing/PreParser.n
nemerle/trunk/ncc/passes.n
Modified: nemerle/trunk/ncc/parsing/PreParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/PreParser.n (original)
+++ nemerle/trunk/ncc/parsing/PreParser.n Sat Jul 8 14:08:01 2006
@@ -49,6 +49,7 @@
{
protected lexer : LexerBase;
protected mutable last_token : Token = null;
+ private mutable last_declaration_token : Token = null;
mutable Env : GlobalEnv;
mutable finished : bool = false;
@@ -363,11 +364,12 @@
def loop () {
def tok = get_token ();
+
match (tok) {
| Token.Keyword ("using") =>
finish_current (current_begin);
- def prevEnv = Env;
+ def oldEnv = Env;
def (id, idLoc) = get_qualified_identifier ();
match (get_token ()) {
@@ -379,7 +381,7 @@
def using_tok = Token.Using (loc, Env);
current_stream.Add (using_tok);
- lexer.Manager.NotifyUsingDirectiveParsed(id, prevEnv, idLoc);
+ lexer.Manager.OnAfterUsingDirectiveParse(id, idLoc, oldEnv, Env);
| Token.Operator ("=") =>
def (id', idLoc') = get_qualified_identifier ();
@@ -398,7 +400,7 @@
def using_tok = Token.Using (tok.Location + st.Location, Env);
current_stream.Add (using_tok);
- lexer.Manager.NotifyUsingDirectiveParsed(id', prevEnv, idLoc');
+ lexer.Manager.OnAfterUsingDirectiveParse(id', idLoc', oldEnv, Env);
| x => Message.Error (x.Location, "expecting `;' or `='")
}
@@ -408,22 +410,36 @@
| Token.Keyword ("namespace") =>
finish_current (current_begin);
- def (id, _) = get_qualified_identifier ();
+ def (id, idLoc) = get_qualified_identifier ();
match (get_token ()) {
| Token.BeginBrace as br =>
def loc = tok.Location + br.Location;
- def oldenv = Env;
+ def oldEnv = Env;
Env = Env.EnterIntoNamespace (id);
lexer.Keywords = Env.Keywords;
+ lexer.Manager.OnBeforeNamespaceParse ();
+
def decls = ParseTopLevelImpl ();
def namespace_tok = Token.Namespace (loc, Env, decls);
- Env = oldenv;
+ // make location of namespace body
+ def nsBodyLoc = if (last_declaration_token is null)
+ loc
+ else
+ {
+ def end = last_declaration_token.Location;
+ last_declaration_token = null;
+ // make location of namespace body
+ Location(loc.FileIndex, loc.EndLine, loc.EndColumn, end.Line, end.Column);
+ }
+
+ lexer.Manager.OnAfterNamespaceParse (id, idLoc, oldEnv, Env, nsBodyLoc);
+
+ Env = oldEnv;
lexer.Keywords = Env.Keywords;
current_stream.Add (namespace_tok);
-
| x => Message.Error (x.Location, "expecting `{' opening namespace scope")
}
finish_current (current_begin);
@@ -431,6 +447,7 @@
// finish entire brace group
| Token.EndBrace =>
+ last_declaration_token = tok;
reset_comment (tok);
finish_parent (parent_begin, current_begin);
@@ -440,6 +457,7 @@
| Token.EndOfFile when parent_begin == 0 =>
def brace_group = finish_parent (parent_begin, current_begin);
finished = true;
+ last_declaration_token = tok;
brace_group;
| _ => handle_default_token (current_begin, tok); loop ()
Modified: nemerle/trunk/ncc/passes.n
==============================================================================
--- nemerle/trunk/ncc/passes.n (original)
+++ nemerle/trunk/ncc/passes.n Sat Jul 8 14:08:01 2006
@@ -119,19 +119,46 @@
}
/** Called by parser when simple "using" directive parsed .
- * qualifiedIdentifier : list [string] - qualified identifier/
+ * name : list [string] - qualified identifier/
* prevEnv : GlobalEnv - GlobalEnv before adding current using directive.
* location : Location - location of qualified identifier.
*/
- protected mutable _usingDirectiveParsed : list [string] * GlobalEnv * Location -> void;
+ protected mutable _afterUsingDirectiveParse
+ : list [string] * Location * GlobalEnv * GlobalEnv -> void;
- internal NotifyUsingDirectiveParsed(
- qualifiedIdentifier : list [string],
- prevEnv : GlobalEnv,
- location : Location) : void
+ internal OnAfterUsingDirectiveParse(
+ name : list [string],
+ nameLocation : Location,
+ beforeEnv : GlobalEnv,
+ afterEnv : GlobalEnv
+ ) : void
{
- when (_usingDirectiveParsed != null)
- _usingDirectiveParsed (qualifiedIdentifier, prevEnv, location);
+ when (_afterUsingDirectiveParse != null)
+ _afterUsingDirectiveParse (name, nameLocation, beforeEnv, afterEnv);
+ }
+
+ protected mutable _beforeNamespaceParse : void -> void;
+
+ internal OnBeforeNamespaceParse () : void
+ {
+ when (_beforeNamespaceParse != null)
+ _beforeNamespaceParse ();
+ }
+
+ protected mutable _afterNamespaceParse
+ : list [string] * Location * GlobalEnv * GlobalEnv * Location -> void;
+
+ internal OnAfterNamespaceParse (
+ name : list [string],
+ nameLocation : Location,
+ outsideEnv : GlobalEnv,
+ insideEnv : GlobalEnv,
+ namespaceLocation : Location
+ ) : void
+ {
+ when (_afterNamespaceParse != null)
+ _afterNamespaceParse (name, nameLocation, outsideEnv,
+ insideEnv, namespaceLocation);
}
More information about the svn
mailing list