Skip to content

Commit 1baf388

Browse files
Add analyzer. (#7)
* Update run.sh Analyzer uses `uiua run` to make style comments, advice, and warnings * Update run.sh * Update analyzer to only analyze .ua files, add tests * Add newlines to the ends of expected_tags files * Add debug * Can't use bash in sh, can I? * Clean up expected * Update analyzer, this should pass the ci * newlines causing trouble as always * Remove debug * wow the ci is strict * Remove jq debug as well * format * Could this finally fix it? * Revert "Could this finally fix it?" This reverts commit 8dc5f1d. * each isn't yet deprecated in uiua 14 * Pleasing the CI yet another time * Yep. CI. * Make the analyzer add type * Remove todo Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com> * Remove rest of TODO as well * Update Dockerfile * Update Dockerfile * Fix tests --------- Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com>
1 parent c5970af commit 1baf388

12 files changed

Lines changed: 73 additions & 8 deletions

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM rust:1.82.0-alpine3.20 AS builder
1+
FROM rust:1.87.0-alpine3.20 AS builder
22

33
RUN apk add --no-cache linux-headers make musl-dev
44

5-
RUN cargo install uiua@0.14.1
5+
RUN cargo install --git https://github.com/uiua-lang/uiua --rev aa6310c uiua
66

77
FROM alpine:3.20
88

bin/run.sh

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env sh
22

33
# Synopsis:
44
# Run the analyzer on a solution.
@@ -21,6 +21,33 @@ if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
2121
exit 1
2222
fi
2323

24+
analyze_files() {
25+
TEMP1=$(mktemp)
26+
for file in "$1"/*.ua; do
27+
[ -e "$file" ] || continue
28+
uiua run "$file" >> "$TEMP1"
29+
done
30+
31+
RESULT=$(cat "$TEMP1")
32+
33+
jq -n --arg in "$RESULT" '
34+
{
35+
comments: (
36+
$in
37+
| split("─")
38+
| map(gsub("^\\s+|\\s+$"; ""))
39+
| map(gsub("(?s)\\n\\s+at.+?\\|"; "\n"))
40+
| map(select(test("^(Warning|Advice|Style):")))
41+
| map({
42+
comment: "uiua.general.generic_message",
43+
params: { comment: . },
44+
type: (if . | test("^Warning:") then "actionable" else "informative" end)
45+
})
46+
)
47+
}
48+
'
49+
}
50+
2451
slug="$1"
2552
solution_dir=$(realpath "${2%/}")
2653
output_dir=$(realpath "${3%/}")
@@ -33,10 +60,7 @@ mkdir -p "${output_dir}"
3360
echo "${slug}: analyzing..."
3461

3562
# Analyze the solution
36-
# TODO: replace the below command with your own command(s)
37-
# to analyze the solution and output the analysis.json and
38-
# tags.json files
39-
echo '{"comments": []}' > "${analysis_file}"
63+
analyze_files $2 > "${analysis_file}"
4064
echo '{"tags": []}' > "${tags_file}"
4165

4266
echo "${slug}: done"

tests/deprecated/deprecated.ua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Logo ← ☇ 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"comments": [
3+
{
4+
"comment": "uiua.general.generic_message",
5+
"params": {
6+
"comment": "Warning: ☇ rerank is deprecated and will be removed in a future version, use subscripted ♭ deshape or °⊸(⧻△) instead\n Logo ← ☇ 0"
7+
},
8+
"type": "actionable"
9+
}
10+
]
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"tags": []}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"comments": [
3+
{
4+
"comment": "uiua.general.generic_message",
5+
"params": {
6+
"comment": "Advice: Split this into multiple lines (heuristic: 65/60) 😠\n Logo ← ⍜°⍉(⊂⊃(+0.1↧¤ ⊃((<⊙(⌵/ℂ))0.95|⊂⊙0.5⇌˙×)) (×⊃(=∩⌟<0.2 0.7 /+×⟜ⁿ1_2)((<⊙(⌵/ℂ))1))) ˙⊞⊟-⊸¬÷⟜⇡200"
7+
},
8+
"type": "informative"
9+
}
10+
]
11+
}

tests/long-line/expected_tags.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"tags": []}

tests/long-line/long-line.ua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Logo ← ⍜°⍉(⊂⊃(+0.1↧¤ ⊃((<⊙(⌵/ℂ))0.95|⊂⊙0.5⇌˙×)) (×⊃(=∩⌟<0.2 0.7 /+×⟜ⁿ1_2)((<⊙(⌵/ℂ))1))) ˙⊞⊟-⊸¬÷⟜⇡200
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{"comments": []}
1+
{
2+
"comments": []
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"comments": [
3+
{
4+
"comment": "uiua.general.generic_message",
5+
"params": {
6+
"comment": "Style: Prefer `⟜` over `⊃∘` for clarity\n Image ← ⊞+.÷⊃∘⇡100"
7+
},
8+
"type": "informative"
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)