Compare commits

..

1 Commits

Author SHA1 Message Date
2bc28d47ea JSON parser checkpoint 2022-11-13 22:49:18 -05:00
3 changed files with 23 additions and 61 deletions

View File

@ -191,7 +191,7 @@ class Propane
end end
code = code.gsub(/\$(\d+)/) do |match| code = code.gsub(/\$(\d+)/) do |match|
index = $1.to_i index = $1.to_i
"statevalues[$-1-n_states+#{index}].pvalue.v_#{rule.components[index - 1].ptypename}" "statevalues[$-1-n_states+#{index}].pvalue.v_#{rule.ptypename}"
end end
else else
code = code.gsub(/\$\$/) do |match| code = code.gsub(/\$\$/) do |match|

View File

@ -2,45 +2,22 @@ class JSONValue
{ {
} }
class JSONObject : JSONValue class JSONObject < JSONValue
{ {
JSONValue[string] value; JSONValue[string] value;
this()
{
} }
this(JSONValue[string] value) class JSONArray < JSONValue
{
this.value = value;
}
}
class JSONArray : JSONValue
{ {
JSONValue[] value; JSONValue[] value;
this()
{
} }
this(JSONValue[] value) class JSONNumber < JSONValue
{
this.value = value;
}
}
class JSONNumber : JSONValue
{ {
double value; double value;
this(double value)
{
this.value = value;
}
} }
class JSONString : JSONValue class JSONString < JSONValue
{ {
string value; string value;
@ -50,14 +27,14 @@ class JSONString : JSONValue
} }
} }
class JSONTrue : JSONValue class JSONTrue < JSONValue
{ {
} }
class JSONFalse : JSONValue class JSONFalse < JSONValue
{ {
} }
class JSONNull : JSONValue class JSONNull < JSONValue
{ {
} }

View File

@ -19,8 +19,8 @@ describe Propane do
end end
end end
def compile(*test_files) def compile(test_file)
result = system(*%w[gdc -funittest -o spec/run/testparser spec/run/testparser.d -Ispec], *test_files) result = system(*%w[gdc -funittest -o spec/run/testparser spec/run/testparser.d], test_file)
expect(result).to be_truthy expect(result).to be_truthy
end end
@ -341,15 +341,9 @@ EOF
import json_types; import json_types;
string string_value; string string_value;
>> >>
ptype JSONValue;
ptype array = JSONValue[];
ptype dict = JSONValue[string];
ptype string = string;
drop /\\s+/; drop /\\s+/;
token lbrace /\\{/; token lbrace /\\{/;
token rbrace /\\}/; token rbrace /\\}/RuRfaw2CHgpvCWu;
token lbracket /\\[/; token lbracket /\\[/;
token rbracket /\\]/; token rbracket /\\]/;
token comma /,/; token comma /,/;
@ -366,8 +360,7 @@ token number /-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][-+]?[0-9]+)?/ <<
negative = true; negative = true;
} }
} }
double n = 1.0; $$ = new JSONNumber();
$$ = new JSONNumber(n);
>> >>
token true << token true <<
$$ = new JSONTrue(); $$ = new JSONTrue();
@ -382,8 +375,8 @@ token null <<
$mode(string); $mode(string);
string_value = ""; string_value = "";
>> >>
string: token string (string) /"/ << string: token string /"/ <<
$$ = string_value; $$ = new JSONString(string_value);
$mode(default); $mode(default);
>> >>
string: /\\\\"/ << string: /\\\\"/ <<
@ -421,7 +414,7 @@ Start -> Value <<
$$ = $1; $$ = $1;
>> >>
Value -> string << Value -> string <<
$$ = new JSONString($1); $$ = $1;
>> >>
Value -> number << Value -> number <<
$$ = $1; $$ = $1;
@ -447,7 +440,7 @@ Object -> lbrace rbrace <<
Object -> lbrace KeyValues rbrace << Object -> lbrace KeyValues rbrace <<
$$ = new JSONObject($2); $$ = new JSONObject($2);
>> >>
KeyValues (dict) -> KeyValue << KeyValues -> KeyValue <<
$$ = $1; $$ = $1;
>> >>
KeyValues -> KeyValues comma KeyValue << KeyValues -> KeyValues comma KeyValue <<
@ -457,23 +450,15 @@ KeyValues -> KeyValues comma KeyValue <<
} }
$$ = $1; $$ = $1;
>> >>
KeyValue (dict) -> string colon Value << KeyValue -> string colon Value <<
$$ = [$1: $3]; $$ =
>>
Array -> lbracket rbracket <<
$$ = new JSONArray();
>>
Array -> lbracket Values rbracket <<
$$ = new JSONArray($2);
>>
Values (array) -> Value <<
$$ = [$1];
>>
Values -> Values comma Value <<
$$ = $1 ~ [$3];
>> >>
Array -> lbracket rbracket;
Array -> lbracket Values rbracket;
Values -> Value;
Values -> Values comma Value;
EOF EOF
build_parser build_parser
compile("spec/test_parsing_json.d", "spec/json_types.d") compile("spec/test_parsing_json.d")
end end
end end