Skip to content

Commit

Permalink
fix: jq's operator inputs skips the file's head line + add test for f…
Browse files Browse the repository at this point in the history
…unctions
  • Loading branch information
piotr-semenov committed Apr 21, 2024
1 parent 8e918eb commit 7aa63fa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,21 @@ $(BUILD_DIR)gp_commands.tsv:
gp -fq 2> /dev/null |\
tr -d '\"') \"\$$(echo -e ?@ | gp -fq | tr -d '\n')\"" >> $@

$(BUILD_DIR)gp_member_functions.txt:
$(BUILD_DIR)gp_member_functions.tsv:
@printf 'Member\n' > $@
@sed -E 's|([a-z])([0-9]+)-\1([0-9]+)|\1{\2..\3}|p' \
<(echo '?.' | gp -fq | grep : | cut -d':' -f1 | tr ',' '\n') |\
sort |\
uniq |\
xargs -I@ $(SHELL) -c 'echo -e @"\n"' | xargs -n1 > $@
xargs -I@ $(SHELL) -c 'echo -e @"\n"' | xargs -n1 >> $@

$(BUILD_DIR)gp_builtins.json: $(addprefix $(BUILD_DIR)gp_, commands.tsv member_functions.txt)
$(BUILD_DIR)gp_builtins.json: $(addprefix $(BUILD_DIR)gp_, commands.tsv member_functions.tsv)
@jq -s '.[0] * .[1]' <(cat $(BUILD_DIR)gp_commands.tsv |\
jq -R -f <(echo "[inputs | split(\"\t\") | {name: .[0], type: .[1]}] |\
group_by(.type) |\
map({ key: (.[0].type), value: [.[] | .name] }) |\
from_entries")) \
<(cat $(BUILD_DIR)gp_member_functions.txt |\
<(cat $(BUILD_DIR)gp_member_functions.tsv |\
jq -R '{"entity.name.function.member": [inputs]}') |\
jq -r '{"scopes": .}' > $@

Expand Down
42 changes: 42 additions & 0 deletions tests/Functions.test.gp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## SYNTAX TEST "source.parigp" "Functions"

Col([])
##^^^ source.parigp entity.name.function

x = Mod(4, 5);
x.mod
## ^^^ source.parigp entity.name.function.member

ellinit([0, 0, 0, -1, 0]).b2
##^^^^^^^ source.parigp entity.name.function
## ^^ source.parigp entity.name.function.member

allocatemem();
##^^^^^^^^^^^ source.parigp keyword.control

# Code from https://stackoverflow.com/a/67286398
counts_for(v: t_VEC, lower: t_INT, upper: t_INT) = {
my(counts = vector(1+upper-lower));
## ^^ source.parigp keyword.control
## ^^^^^^ source.parigp entity.name.function

for(i=1, #v, counts[1+v[i]-lower]++);
## ^^^ source.parigp keyword.control
vector(#counts, i, [i-1, counts[i]])
## ^^^^^^ source.parigp entity.name.function
};

counts_for1(v: t_VEC) = {
counts_for(v, vecmin(v), vecmax(v))
## ^^^^^^ source.parigp entity.name.function
## ^^^^^^ source.parigp entity.name.function
};

most_frequent(v: t_VEC) = {
my(counts=counts_for1(v));
## ^^ source.parigp keyword.control
vecsort(counts, [2], 4)[1][1]
## ^^^^^^^ source.parigp entity.name.function
};

most_frequent(V1)

0 comments on commit 7aa63fa

Please sign in to comment.