[GODCC][COMMITTED] Use clearer names for JSON modes
Jose E. Marchesi
jemarch@gnu.org
Tue Apr 22 01:11:12 GMT 2025
---
src/godcc.a68 | 36 ++++++++++-----------
src/json.a68 | 86 +++++++++++++++++++++++++--------------------------
2 files changed, 61 insertions(+), 61 deletions(-)
diff --git a/src/godcc.a68 b/src/godcc.a68
index 56dc897..33dbd89 100644
--- a/src/godcc.a68
+++ b/src/godcc.a68
@@ -149,8 +149,8 @@ begin string godcc_version = "1.0";
ce_socket := -1
end;
- proc ce_get_json = (string what) JSONVal:
- begin JSONVal val;
+ proc ce_get_json = (string what) JSON_Val:
+ begin JSON_Val val;
proc h = (int e, n, fd) void:
(if e /= 0 then error ("received JSON in chunks") fi;
val := json_from_fd (n, fd));
@@ -164,8 +164,8 @@ begin string godcc_version = "1.0";
val
end;
- proc ce_post_json = (string what, JSONVal val) JSONVal:
- begin JSONVal out_val;
+ proc ce_post_json = (string what, JSON_Val val) JSON_Val:
+ begin JSON_Val out_val;
proc h = (int e, n, fd) void:
(if e /= 0 then error ("received JSON in chunks") fi;
out_val := json_from_fd (n, fd));
@@ -199,9 +199,9 @@ begin string godcc_version = "1.0";
proc do_languages = void:
begin
ce_connect;
- JSONVal languages = ce_get_json ("languages");
+ JSON_Val languages = ce_get_json ("languages");
json_foreach_elem (languages,
- (JSONVal v) void:
+ (JSON_Val v) void:
puts (json_str (json_obj_sel (v, "id")) + "\n"));
ce_disconnect
end;
@@ -224,20 +224,20 @@ begin string godcc_version = "1.0";
proc do_formats = void:
begin
- proc do_format = (JSONVal f) void:
- begin JSONVal format_name = json_obj_sel (f, "name"),
+ proc do_format = (JSON_Val f) void:
+ begin JSON_Val format_name = json_obj_sel (f, "name"),
format_styles = json_obj_sel (f, "styles");
puts (json_str (format_name));
json_for_each_elem (format_styles,
- (JSONVal style) void:
+ (JSON_Val style) void:
puts (" (" + json_str (style) + ")"));
puts ("\n");
false
end;
ce_connect;
- JSONVal formats = ce_get_json ("formats");
+ JSON_Val formats = ce_get_json ("formats");
json_foreach_elem (formats, do_format);
ce_disconnect
end;
@@ -288,19 +288,19 @@ begin string godcc_version = "1.0";
while (line := fgets (fd, 0)) /= "" do src +:= line od;
# Prepare the JSON query. #
- ref JSONFld fields := nil;
- fields := heap JSONFld := ("source", json_escape_string (src), fields);
+ ref JSON_Fld fields := nil;
+ fields := heap JSON_Fld := ("source", json_escape_string (src), fields);
if style /= ""
- then fields := heap JSONFld := ("base", style, fields) fi;
- fields := heap JSONFld := ("useSpaces", use_spaces, fields);
- fields := heap JSONFld := ("tabWidth", tab_width, fields);
- JSONObj obj;
+ then fields := heap JSON_Fld := ("base", style, fields) fi;
+ fields := heap JSON_Fld := ("useSpaces", use_spaces, fields);
+ fields := heap JSON_Fld := ("tabWidth", tab_width, fields);
+ JSON_Obj obj;
fields of obj := fields;
- JSONVal cmd = obj;
+ JSON_Val cmd = obj;
# Query the server. #
ce_connect;
- JSONVal res = ce_post_json ("format/" + formatter, cmd);
+ JSON_Val res = ce_post_json ("format/" + formatter, cmd);
ce_disconnect;
# Process the response. #
diff --git a/src/json.a68 b/src/json.a68
index a97004e..ef3f9a4 100644
--- a/src/json.a68
+++ b/src/json.a68
@@ -18,42 +18,42 @@
# PR SUPPER PR #
-mode JSONVal = union (bool,int,string,JSONArr,JSONObj),
- JSONArr = struct (ref JSONElm elements),
- JSONObj = struct (ref JSONFld fields),
- JSONElm = struct (JSONVal value, ref JSONElm next),
- JSONFld = struct (JSONVal name, value, ref JSONFld next);
+mode JSON_Val = union (bool,int,string,JSON_Arr,JSON_Obj),
+ JSON_Arr = struct (ref JSON_Elm elements),
+ JSON_Obj = struct (ref JSON_Fld fields),
+ JSON_Elm = struct (JSON_Val value, ref JSON_Elm next),
+ JSON_Fld = struct (JSON_Val name, value, ref JSON_Fld next);
-ref JSONElm json_no_elm = nil;
-ref JSONFld json_no_fld = nil;
+ref JSON_Elm json_no_elm = nil;
+ref JSON_Fld json_no_fld = nil;
proc json_to_string = (JSONVal val) string:
case val
in (bool b): (b | "true" | "false"),
(int i): itoa (i),
(string s): """" + s + """",
- (JSONArr a): "[" + (ref JSONElm elem := elements of a, string res;
- for i while elem :/=: json_no_elm
- do (i > 1 | res +:= ",");
- res +:= json_to_string (value of elem);
- elem := next of elem
- od;
- res) + "]",
- (JSONObj o): "{" + (ref JSONFld field := fields of o, string res;
- for i while field :/=: json_no_fld
- do (i > 1 | res +:= ",");
- res +:= json_to_string (name of field);
- res +:= ":";
- res +:= json_to_string (value of field);
- field := next of field
- od;
- res) + "}"
+ (JSON_Arr a): "[" + (ref JSON_Elm elem := elements of a, string res;
+ for i while elem :/=: json_no_elm
+ do (i > 1 | res +:= ",");
+ res +:= json_to_string (value of elem);
+ elem := next of elem
+ od;
+ res) + "]",
+ (JSON_Obj o): "{" + (ref JSON_Fld field := fields of o, string res;
+ for i while field :/=: json_no_fld
+ do (i > 1 | res +:= ",");
+ res +:= json_to_string (name of field);
+ res +:= ":";
+ res +:= json_to_string (value of field);
+ field := next of field
+ od;
+ res) + "}"
esac;
char eof = invalid_char;
char ungetch := eof;
-proc json_from_fd = (int maxchars, int fd) JSONVal:
+proc json_from_fd = (int maxchars, int fd) JSON_Val:
begin
char ch;
int usedchars;
@@ -108,19 +108,19 @@ begin
for i to UPB s
do expect_char (s[i]) od;
- proc parse_array = JSONArr:
- begin JSONArr res, ref JSONElm elems;
+ proc parse_array = JSON_Arr:
+ begin JSON_Arr res, ref JSON_Elm elems;
for i while getchar /= "]"
do ungetch := ch;
if i > 1 then ungetch := ch; expect_char (",") fi;
- JSONVal val = json_from_fd (maxchars - usedchars, fd);
+ JSON_Val val = json_from_fd (maxchars - usedchars, fd);
# Array elements should keep written order. #
elems := (elems :=: json_no_elm
- | heap JSONElm := (val, nil)
- | (ref JSONElm e := elems;
+ | heap JSON_Elm := (val, nil)
+ | (ref JSON_Elm e := elems;
while next of e :/=: json_no_elm
do e := next of e od;
- next of e := heap JSONElm := (val, nil);
+ next of e := heap JSON_Elm := (val, nil);
elems))
od;
elements of res := elems;
@@ -128,15 +128,15 @@ begin
res
end;
- proc parse_object = JSONObj:
- begin JSONObj res, ref JSONFld fields;
+ proc parse_object = JSON_Obj:
+ begin JSON_Obj res, ref JSON_Fld fields;
for i while getchar /= "}"
do ungetch := ch;
if i > 1 then expect_char (",") fi;
- JSONVal name = json_from_fd (maxchars - usedchars, fd);
+ JSON_Val name = json_from_fd (maxchars - usedchars, fd);
expect_char (":");
- JSONVal value = json_from_fd (maxchars - usedchars, fd);
- fields := heap JSONFld := (name, value, fields)
+ JSON_Val value = json_from_fd (maxchars - usedchars, fd);
+ fields := heap JSON_Fld := (name, value, fields)
od;
fields of res := fields;
(ch = eof | parse_error ("unclosed object in JSON string"));
@@ -153,16 +153,16 @@ begin
| parse_error ("invalid JSON"); skip)
end;
-proc json_int = (JSONVal v) int:
+proc json_int = (JSON_Val v) int:
(v | (int i): i | error ("expected integer in json str"); skip);
-proc json_str = (JSONVal v) string:
+proc json_str = (JSON_Val v) string:
(v | (string s): s | error ("expected string in json str"); skip);
-proc json_foreach_elem = (JSONVal v, proc(JSONVal)void h) void:
+proc json_foreach_elem = (JSON_Val v, proc(JSON_Val)void h) void:
begin case v
- in (JSONArr a):
- (ref JSONElm elem := elements of a;
+ in (JSON_Arr a):
+ (ref JSON_Elm elem := elements of a;
while elem :/=: json_no_elm
do h (value of elem);
elem := next of elem
@@ -171,10 +171,10 @@ begin case v
esac
end;
-proc json_obj_sel = (JSONVal v, string fname) JSONVal:
+proc json_obj_sel = (JSON_Val v, string fname) JSON_Val:
begin case v
- in (JSONObj o):
- begin ref JSONFld field := fields of o, bool found := false;
+ in (JSON_Obj o):
+ begin ref JSON_Fld field := fields of o, bool found := false;
while (field :/=: json_no_fld) AND NOT found
do if json_str (name of field) = fname
then found := true
--
2.30.2
More information about the Algol68
mailing list