[GODCC][COMMITTED] list languages: add language extensions
Jose E. Marchesi
jemarch@gnu.org
Fri Oct 31 22:25:37 GMT 2025
Also adapt to use the latest compiler eof_char and other fixes.
---
src/godcc-compile.a68 | 2 +-
src/godcc-list.a68 | 11 ++++++++++-
src/json.a68 | 31 ++++++++++++++++++++-----------
3 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/src/godcc-compile.a68 b/src/godcc-compile.a68
index 64f8c1f..ad15686 100644
--- a/src/godcc-compile.a68
+++ b/src/godcc-compile.a68
@@ -68,7 +68,7 @@ begin
(n > 0 | puts (fgets (fd, n))));
ce_disconnect;
- { Close files whenever required. }
+ { Close files. }
(in_fd /= 1 | fclose_checked (src_file, in_fd));
(out_fd /= 1 | fclose_checked (out_file, out_fd))
end;
diff --git a/src/godcc-list.a68 b/src/godcc-list.a68
index a7b3784..45c08e8 100644
--- a/src/godcc-list.a68
+++ b/src/godcc-list.a68
@@ -24,7 +24,16 @@ begin
JSON_Val languages := ce_get_json ("languages");
json_foreach_elem (languages,
(ref JSON_Val v) void:
- puts (json_str (v->"id") + "'n"));
+ begin puts (json_str (v->"id"));
+ puts (" (");
+ int count := 0;
+ json_foreach_elem (v->"extensions",
+ (ref JSON_Val e) void:
+ ((count > 0 | puts (", "));
+ puts (json_str (e));
+ count +:= 1));
+ puts (")'n")
+ end);
ce_disconnect
end;
diff --git a/src/json.a68 b/src/json.a68
index 8143b6b..d3136d8 100644
--- a/src/json.a68
+++ b/src/json.a68
@@ -52,6 +52,16 @@ proc json_new_arr = JSON_Val: heap JSON_Arr;
proc(string)void json_error := (string msg) void: (assert (false));
+{ Return the number of elements in a JSON array. Return 0 for other
+ kind of objects. }
+
+op LEN = (JSON_Val v) int:
+ case v
+ in (ref JSON_Arr a):
+ (int len := 0; json_foreach_elem (a, (ref JSON_Val v) void: len +:= 1); len)
+ out 0
+ esac;
+
{ The operator -> gets a JSON value, which must be an object, and a
field name, and returns a name referring to the field of that name
stored in the object. If there is no such a field, one is created
@@ -131,14 +141,13 @@ proc json_from_fd = (int maxchars, int fd,
begin
{ Simple stream of characters with EOF and error detection. }
- char eof = invalid_char;
- char ungetch := eof, ch;
+ char ungetch := eof_char, ch;
int usedchars;
proc getchar = char:
- begin if usedchars > maxchars then ch := eof
- elif ungetch /= eof
- then ch := ungetch; ungetch := eof
+ begin if usedchars > maxchars then ch := eof_char
+ elif ungetch /= eof_char
+ then ch := ungetch; ungetch := eof_char
else ch := fgetc (fd); usedchars +:= 1
fi;
ch
@@ -152,13 +161,13 @@ begin
proc expect = (string s) void:
for i to UPB s
do char c = s[i];
- if getchar = eof orel ch /= c
+ if getchar = eof_char orel ch /= c
then parse_error ("expected ''" + c + "''")
fi
od;
proc parse_error = (string msg) void:
- if ch = eof
+ if ch = eof_char
then json_error (msg + ", found end of file")
else json_error (msg + ", found ''" + ch + "''")
fi;
@@ -179,10 +188,10 @@ begin
proc parse_string = string:
begin string res;
while getchar /= """"
- do if ch = eof then json_error ("while parsing string")
+ do if ch = eof_char then json_error ("while parsing string")
elif ch = "\"
then ch = getchar;
- if ch = eof then json_error ("unterminated string escape")
+ if ch = eof_char then json_error ("unterminated string escape")
elif ch = "n" then res +:= "'n"
elif ch = "t" then res +:= "'t"
elif ch = """" then res +:= """"
@@ -210,7 +219,7 @@ begin
next of e := heap JSON_Elm := (val, nil);
elems))
od;
- (ch = eof | parse_error ("unclosed array in JSON string"));
+ (ch = eof_char | parse_error ("unclosed array in JSON string"));
heap JSON_Arr res;
elements of res := elems;
res
@@ -226,7 +235,7 @@ begin
JSON_Val value = parse_value (charsleft - usedchars);
fields := heap JSON_Fld := (name, value, fields)
od;
- (ch = eof | parse_error ("unclosed object in JSON string"));
+ (ch = eof_char | parse_error ("unclosed object in JSON string"));
heap JSON_Obj res;
fields of res := fields;
res
--
2.30.2
More information about the Algol68
mailing list