state.id contained a stale pointer when parsing EOF. Updated the
tests that reported the previous identifier.
---
 src/compiler/parser_helper.c |   24 ++++++++++++++++--------
 src/compiler/test/codegen    |    4 ++--
 src/compiler/test/error      |    4 ++--
 src/compiler/test/location   |    4 ++--
 4 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/compiler/parser_helper.c b/src/compiler/parser_helper.c
index 316d798..546b48a 100644
--- a/src/compiler/parser_helper.c
+++ b/src/compiler/parser_helper.c
@@ -66,6 +66,15 @@ const char *fpvm_parse(const char *expr, int start_token,
        Parse(p, start_token, NULL, &state);
        tok = scan(s);
        while(tok != TOK_EOF) {
+               if(tok == TOK_ERROR) {
+                       asprintf(&error,
+                           "FPVM, line %d: scan error near '%c'",
+                           s->lineno, printable_char(s->cursor[-1]));
+                       ParseFree(p, free);
+                       delete_scanner(s);
+                       return error;
+               }
+
                identifier = malloc(sizeof(struct id));
                identifier->token = tok;
                identifier->lineno = s->lineno;
@@ -84,17 +93,16 @@ const char *fpvm_parse(const char *expr, int start_token,
                }
 
                state.id = identifier;
-               if(tok == TOK_ERROR) {
-                       asprintf(&error,
-                           "FPVM, line %d: scan error near '%c'",
-                           s->lineno, printable_char(s->cursor[-1]));
-                       ParseFree(p, free);
-                       delete_scanner(s);
-                       return error;
-               }
                Parse(p, tok, identifier, &state);
                tok = scan(s);
        }
+
+       identifier = malloc(sizeof(struct id));
+       identifier->token = TOK_EOF;
+       identifier->lineno = s->lineno;
+       identifier->label = "EOF";
+
+       state.id = identifier;
        Parse(p, TOK_EOF, NULL, &state);
        ParseFree(p, free);
        delete_scanner(s);
diff --git a/src/compiler/test/codegen b/src/compiler/test/codegen
index da90615..93aa7c5 100755
--- a/src/compiler/test/codegen
+++ b/src/compiler/test/codegen
@@ -15,7 +15,7 @@ ptest_fail "codegen: global foo = 1" -c -q <<EOF
 foo = 1
 EOF
 expect <<EOF
-FPVM, line 1: unknown parameter near ''
+FPVM, line 2: unknown parameter near 'EOF'
 EOF
 
 #------------------------------------------------------------------------------
@@ -24,7 +24,7 @@ ptest_fail "codegen: wave_a = bar" -c -q <<EOF
 wave_a = bar
 EOF
 expect <<EOF
-FPVM, line 1: value must be a constant near 'bar'
+FPVM, line 2: value must be a constant near 'EOF'
 EOF
 
 ###############################################################################
diff --git a/src/compiler/test/error b/src/compiler/test/error
index c8a07cf..ca4fa04 100755
--- a/src/compiler/test/error
+++ b/src/compiler/test/error
@@ -17,7 +17,7 @@ x = a b
 EOF
 expect <<EOF
 x = a
-FPVM, line 1: parse error near 'b'
+FPVM, line 2: parse error near 'EOF'
 EOF
 
 #------------------------------------------------------------------------------
@@ -35,7 +35,7 @@ ptest_fail "code generation error" -f "codegen" <<EOF
 x = a + b
 EOF
 expect <<EOF
-FPVM, line 1: codegen near 'b'
+FPVM, line 2: codegen near 'EOF'
 EOF
 
 ###############################################################################
diff --git a/src/compiler/test/location b/src/compiler/test/location
index c9bee39..55a693c 100755
--- a/src/compiler/test/location
+++ b/src/compiler/test/location
@@ -93,14 +93,14 @@ x =
 EOF
 expect <<EOF
 a = b
-FPVM, line 2: parse error near '='
+FPVM, line 3: parse error near 'EOF'
 EOF
 
 #------------------------------------------------------------------------------
 
 ptest_fail "location: error is EOF" "x="
 expect <<EOF
-FPVM, line 1: parse error near '='
+FPVM, line 1: parse error near 'EOF'
 EOF
 
 #------------------------------------------------------------------------------
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to