Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ourPLCC/plcc into stoneyjac…
Browse files Browse the repository at this point in the history
…kson/add-new-semantics-95
  • Loading branch information
reedeveris committed Apr 7, 2024
2 parents ba7d241 + 47f2c5d commit 56be1a9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
15 changes: 8 additions & 7 deletions tests/plcc/can-print-json-ast/prints-json-ast.bats
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/json-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/expected.json
rm -rf ${BATS_TMPDIR}/given-grammar.lang
rm -rf ${BATS_TMPDIR}/given-program.lang
rm -rf ${BATS_TMPDIR}/result.json
rm -rf ${BATS_TMPDIR}/Java
cd ../..
rm -rf ${BATS_TMPDIR}/json-test
}

@test "PLCC can print JSON AST." {
FILES="expected.json given-grammar.lang given-program.lang"
for f in $FILES ; do
cp "${BATS_TEST_DIRNAME}/${f}" "${BATS_TMPDIR}"
cp -R "${BATS_TEST_DIRNAME}/${f}" "${BATS_TMPDIR}/json-test"
done

cd "${BATS_TMPDIR}"
cd "${BATS_TMPDIR}/json-test"
plccmk --json_ast given-grammar.lang
parse -n --json_ast < given-program.lang > result.json
diff expected.json result.json
Expand Down
13 changes: 9 additions & 4 deletions tests/plcc/compiles-obj/compiles-obj.bats
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/obj-test
}

teardown() {
rm -rf "$BATS_TMPDIR/OBJ"
cd ../../../..
rm -rf ${BATS_TMPDIR}/obj-test
}

@test "PLCC compiles the OBJ language." {
# Copy the OBJ language to the temp directory for this test
cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}"
# Copy the OBJ language to the temporary directory for this test
cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}/obj-test"

# Change into the temporary OBJ directory.
cd "${BATS_TMPDIR}/OBJ"
cd "${BATS_TMPDIR}/obj-test/OBJ"

# Use plcc to generate the Java files from the OBJ grammar file.
plcc "grammar"
Expand Down
10 changes: 7 additions & 3 deletions tests/plcc/detects-illegal-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/illegal-tokens-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
rm -rf ${BATS_TMPDIR}/illegal-tokens-test
}

@test "PLCC detects illegal tokens." {
# GIVEN a grammar file with a bad token name
cat << EOF > "$BATS_TMPDIR/grammar"
cat << EOF > "${BATS_TMPDIR}/illegal-tokens-test/grammar"
token bad_token_name '.'
EOF

# WHEN plcc is ran on that grammar file
run plcc "$BATS_TMPDIR/grammar"
run plcc "${BATS_TMPDIR}/illegal-tokens-test/grammar"

# print stdout and stderr for debugging
echo "OUTPUT: $output"
Expand Down
11 changes: 7 additions & 4 deletions tests/plcc/parses.bats
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/parse-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
rm -rf ${BATS_TMPDIR}/Java
rm -rf ${BATS_TMPDIR}/parse-test
}

@test "PLCC parses." {
cat << EOF > "$BATS_TMPDIR/grammar"
cat << EOF > "${BATS_TMPDIR}/parse-test/grammar"
A 'A'
B 'B'
skip OTHER '.'
Expand All @@ -15,7 +18,7 @@ skip OTHER '.'
<aaa> **= A
EOF

RESULT="$(cd "$BATS_TMPDIR" && plccmk -c grammar > /dev/null && echo "A asdf A fdsa A B" | parse -n)"
RESULT="$(cd "${BATS_TMPDIR}/parse-test" && plccmk -c grammar > /dev/null && echo "A asdf A fdsa A B" | parse -n)"

echo "RESULT: $RESULT"
[[ "$RESULT" =~ .*OK.* ]]
Expand Down
13 changes: 8 additions & 5 deletions tests/plcc/scans-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/scan-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
rm -rf ${BATS_TMPDIR}/Java
rm -rf ${BATS_TMPDIR}/scan-test
}

@test "PLCC scans." {
cat << EOF > "$BATS_TMPDIR/grammar"
cat << EOF > "${BATS_TMPDIR}/scan-test/grammar"
skip WHITESPACE '\s'
token FOO 'foo'
token BAR 'bar'
Expand All @@ -16,8 +19,8 @@ EOF
IN="foo bar \n foobar"

TOKENS="$(
cd "$BATS_TMPDIR" &&
plccmk -c "$BATS_TMPDIR/grammar" &&
cd "${BATS_TMPDIR}/scan-test" &&
plccmk -c "grammar" &&
OUT="$(echo "$IN" | scan)" &&
echo "$OUT"
)"
Expand Down

0 comments on commit 56be1a9

Please sign in to comment.