Semicolons are optional, but if they are used, they must appear at
the end of an assignment. (We may generalize this in the future.)
---
 src/compiler/parser.y   |    6 +++-
 src/compiler/scanner.re |    1 +
 src/compiler/test/wrap  |   91 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 1 deletions(-)
 create mode 100755 src/compiler/test/wrap

diff --git a/src/compiler/parser.y b/src/compiler/parser.y
index e06c6f7..53695ed 100644
--- a/src/compiler/parser.y
+++ b/src/compiler/parser.y
@@ -100,11 +100,15 @@ assignments ::= assignments assignment.
 
 assignments ::= .
 
-assignment ::= ident(I) TOK_ASSIGN node(N). {
+assignment ::= ident(I) TOK_ASSIGN node(N) opt_semi. {
        fpvm_do_assign(state->comm->fragment, I->label, N);
        fpvm_parse_free(N);
 }
 
+opt_semi ::= opt_semi TOK_SEMI.
+
+opt_semi ::= .
+
 node(N) ::= TOK_CONSTANT(C). {
        N = node(TOK_CONSTANT, "", NULL, NULL, NULL);
        N->contents.constant = C->constant;
diff --git a/src/compiler/scanner.re b/src/compiler/scanner.re
index a267730..e42cf21 100644
--- a/src/compiler/scanner.re
+++ b/src/compiler/scanner.re
@@ -91,6 +91,7 @@ int scan(struct scanner *s)
                ")"                     { return TOK_RPAREN; }
                ","                     { return TOK_COMMA; }
                "="                     { return TOK_ASSIGN; }
+               ";"                     { return TOK_SEMI; }
                [\x00-\xff]             { return TOK_ERROR; }
        */
 }
diff --git a/src/compiler/test/wrap b/src/compiler/test/wrap
new file mode 100755
index 0000000..1e978ee
--- /dev/null
+++ b/src/compiler/test/wrap
@@ -0,0 +1,91 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+ptest "wrap: baseline" <<EOF
+a = b + c
+EOF
+expect <<EOF
+a = (+ b c)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "wrap: with newline" <<EOF
+a = b +
+c
+EOF
+expect <<EOF
+a = (+ b c)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "wrap: two assignments on two lines" <<EOF
+a = b + c
+d = e + f
+EOF
+expect <<EOF
+a = (+ b c)
+d = (+ e f)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "wrap: two assignments on one line" <<EOF
+a = b + c  d = e + f
+EOF
+expect <<EOF
+a = (+ b c)
+d = (+ e f)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "wrap: one assignment ending with semicolon" <<EOF
+a = b + c;
+EOF
+expect <<EOF
+a = (+ b c)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "wrap: one assignment ending with multiple semicolons" <<EOF
+a = b + c;;;;;;;;;;;
+EOF
+expect <<EOF
+a = (+ b c)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "wrap: two assignments separated by semicolon" <<EOF
+a = b + c; d = e + f
+EOF
+expect <<EOF
+a = (+ b c)
+d = (+ e f)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest_fail "wrap: one assignment containing semicolon (1)" <<EOF
+a = b +; c
+EOF
+expect <<EOF
+FPVM: parse error
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest_fail "wrap: one assignment containing semicolon (2)" <<EOF
+a = b; + c
+EOF
+expect <<EOF
+a = b
+FPVM: parse error
+EOF
+
+###############################################################################
-- 
1.7.1

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

Reply via email to