[svn] r7498: nemerle/trunk/ncc/parsing/Lexer.n
divan
svnadmin at nemerle.org
Tue Feb 27 01:15:58 CET 2007
Log:
Fix bug 945.
Author: divan
Date: Tue Feb 27 01:15:57 2007
New Revision: 7498
Modified:
nemerle/trunk/ncc/parsing/Lexer.n
Modified: nemerle/trunk/ncc/parsing/Lexer.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Lexer.n (original)
+++ nemerle/trunk/ncc/parsing/Lexer.n Tue Feb 27 01:15:57 2007
@@ -1160,16 +1160,17 @@
parse_preprocessor () : void
{
- // eof isn't checked, because we are eating and expecting something
- // not white before end of line
- def eat_spaces () : char {
- mutable c = ' ';
- while (Char.IsWhiteSpace (c) && c != '\n')
- c = read_or_eol ();
- c
+ def eat_spaces () : void {
+ mutable c = peek ();
+ while (Char.IsWhiteSpace (c))
+ {
+ ignore (read ());
+ c = peek ();
+ }
};
def read_word () : string {
- def word = StringBuilder (eat_spaces ().ToString ());
+ eat_spaces ();
+ def word = StringBuilder ();
try {
while (IsIdBeginning (peek_or_white ()) || Char.IsDigit (peek_or_white ()))
_ = word.Append (read ())
@@ -1226,10 +1227,11 @@
throw LexerBase.Error ("unbalanced #endif");
| "line" =>
- mutable c = eat_spaces ();
+ eat_spaces ();
+ mutable c = peek_or_white ();
def (new_line, new_file) =
if (c == 'd') {
- if (read_word () == "efault") {
+ if (read_word () == "default") {
ignore (read_to_the_end_of_line ());
(-1, null)
}
@@ -1239,14 +1241,13 @@
else {
def num = StringBuilder ();
def loop () {
- ignore (num.Append (c));
+ when (char.IsDigit (c))
+ {
+ ignore (num.Append (read ()));
c = peek_or_white ();
- when (char.IsDigit (c)) {
- _ = read ();
loop ();
}
}
- when (char.IsDigit (c))
loop ();
if (num.Length > 0)
(Int32.Parse (num.ToString ()), read_to_the_end_of_line ().Trim ())
@@ -1295,11 +1296,21 @@
_ = read_to_the_end_of_line ();
| "define" =>
- defines = defines.Replace (read_word (), true);
+ def w = read_word ();
+ when (w == "")
+ throw LexerBase.Error ("#define should be followed by name to define");
+ when (w == "true" || w == "false")
+ throw LexerBase.Error ($ "Attempt to define $w");
+ defines = defines.Replace (w, true);
_ = read_to_the_end_of_line ()
| "undef" =>
- defines = defines.Replace (read_word (), false);
+ def w = read_word ();
+ when (w == "")
+ throw LexerBase.Error ("#undef should be followed by name to undefine");
+ when (w == "true" || w == "false")
+ throw LexerBase.Error ($ "Attempt to undefine $w");
+ defines = defines.Replace (w, false);
_ = read_to_the_end_of_line ()
| "pragma" =>
More information about the svn
mailing list