diff --git a/compiler/lexer/lexer.go b/compiler/lexer/lexer.go index 383670f..1bcfe41 100644 --- a/compiler/lexer/lexer.go +++ b/compiler/lexer/lexer.go @@ -330,10 +330,11 @@ func (l *Lexer) scanString(quote byte) token.Token { } // isStringBracket returns true if [ should be treated as string delimiter. -// Harbour: [text] is string when not preceded by ident, ), ], literal. +// Harbour: [text] is string when not preceded by ident, ), ], literal, +// or `}` (close of array literal — `{1,2,3}[2]` is index access). func (l *Lexer) isStringBracket() bool { switch l.lastKind { - case token.IDENT, token.RPAREN, token.RBRACKET, + case token.IDENT, token.RPAREN, token.RBRACKET, token.RBRACE, token.INT, token.LONG, token.DOUBLE, token.STRING, token.TRUE, token.FALSE, token.NIL_LIT: return false // array index context diff --git a/tests/examples_build.sh b/tests/examples_build.sh new file mode 100755 index 0000000..bba82a6 --- /dev/null +++ b/tests/examples_build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# Build-only sweep of every example PRG. Doesn't run them (many are +# interactive / database / network). Just checks the compiler accepts +# them cleanly. +set -e +cd /Users/charleskwon/Projects/fivedev/five + +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT + +pass=0 +fail=0 +declare -a failed + +for src in examples/*.prg; do + name=$(basename "$src" .prg) + if ./five build "$src" -o "$work/$name" >"$work/$name.out" 2>&1; then + # Check for parse / preprocessor errors even when build "succeeded" + if grep -qE '^(five: [0-9]+ (parse|preprocessor) error|panic:)' "$work/$name.out"; then + echo "FAIL $name (build returned 0 but errors detected)" + tail -5 "$work/$name.out" | sed 's/^/ /' + fail=$((fail+1)) + failed+=("$name") + else + pass=$((pass+1)) + fi + else + echo "FAIL $name" + tail -5 "$work/$name.out" | sed 's/^/ /' + fail=$((fail+1)) + failed+=("$name") + fi +done + +echo +echo "================================================================" +echo " Build sweep: $pass / $((pass+fail)) examples build cleanly" +echo "================================================================" +if [ ${#failed[@]} -gt 0 ]; then + echo "Failed:" + for n in "${failed[@]}"; do echo " $n"; done +fi