[svn] r5855: nemerle/trunk/ncc/parsing/PreParser.n
malekith
svnadmin at nemerle.org
Thu Oct 27 09:52:51 CEST 2005
Log:
Use Stack for storing stack of indents (more intuitive). Kill indent_level.
Author: malekith
Date: Thu Oct 27 09:52:51 2005
New Revision: 5855
Modified:
nemerle/trunk/ncc/parsing/PreParser.n
Modified: nemerle/trunk/ncc/parsing/PreParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/PreParser.n (original)
+++ nemerle/trunk/ncc/parsing/PreParser.n Thu Oct 27 09:52:51 2005
@@ -452,7 +452,6 @@
public class PreParserIndent : PreParser {
// For indentation syntax
- mutable indent_level : int;
mutable current_indent : string = "";
// The number of unmatched { ( [ tokens found in the user code at this point
mutable explicit_groups : int;
@@ -462,7 +461,7 @@
mutable had_some_real_input : bool;
mutable force_brace_after_newline : bool;
- indent_strings : System.Collections.Generic.List [string];
+ indent_strings : Stack [string] = Stack (20);
tokens_pending : Queue [Token] = Queue ();
// 'set' directives handling
@@ -472,8 +471,7 @@
public this (lex : LexerBase) {
base (lex);
- indent_strings = System.Collections.Generic.List (20);
- _ = indent_strings.Add ("");
+ indent_strings.Push ("");
}
push_end_brace () : void
@@ -490,9 +488,9 @@
| Token.EndOfFile =>
insertLocation = lexer_tok.Location;
- while (indent_level > 0) {
+ while (indent_strings.Count > 1) {
+ _ = indent_strings.Pop ();
push_end_brace ();
- indent_level--;
}
when (set_class)
push_end_brace ();
@@ -644,8 +642,7 @@
handle_real_token (tok)
| _ =>
- indent_level++;
- _ = indent_strings.Add (new_indent);
+ indent_strings.Push (new_indent);
tokens_pending.Push (Token.BeginBrace (insertLocation, true));
handle_real_token (tok);
//Message.Debug (tok.Location, "Generate '{'");
@@ -654,20 +651,16 @@
}
// Otherwise, we've unintented:
else {
- def i = indent_strings.IndexOf (new_indent);
- when (i == -1) {
+ if (indent_strings.Contains (new_indent)) {
+ while (indent_strings.Top != new_indent) {
+ push_end_brace ();
+ _ = indent_strings.Pop ();
+ }
+ handle_real_token (tok)
+ } else {
// TODO: make a better error message -- checkout python error message
throw PreParserException (tok.Location, "inconsistent indentation");
}
-
- repeat (indent_level - i)
- push_end_brace ();
-
- indent_level = i;
- indent_strings.RemoveRange (i + 1, indent_strings.Count - (i + 1));
-
- handle_real_token (tok);
- //Message.Debug (tok.Location, $"Generate $insert_unindents '}'");
}
get_token ()
More information about the svn
mailing list