Compare commits
3 Commits
2bc28d47ea
...
bc77be79d2
Author | SHA1 | Date | |
---|---|---|---|
bc77be79d2 | |||
62451f3a92 | |||
2e48921bb1 |
@ -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.ptypename}"
|
"statevalues[$-1-n_states+#{index}].pvalue.v_#{rule.components[index - 1].ptypename}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
code = code.gsub(/\$\$/) do |match|
|
code = code.gsub(/\$\$/) do |match|
|
||||||
|
@ -2,22 +2,45 @@ class JSONValue
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONObject < JSONValue
|
class JSONObject : JSONValue
|
||||||
{
|
{
|
||||||
JSONValue[string] value;
|
JSONValue[string] value;
|
||||||
|
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
this(JSONValue[string] value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONArray < JSONValue
|
class JSONArray : JSONValue
|
||||||
{
|
{
|
||||||
JSONValue[] value;
|
JSONValue[] value;
|
||||||
|
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
this(JSONValue[] value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONNumber < JSONValue
|
class JSONNumber : JSONValue
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
|
|
||||||
|
this(double value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONString < JSONValue
|
class JSONString : JSONValue
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
|
|
||||||
@ -27,14 +50,14 @@ class JSONString < JSONValue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONTrue < JSONValue
|
class JSONTrue : JSONValue
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONFalse < JSONValue
|
class JSONFalse : JSONValue
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONNull < JSONValue
|
class JSONNull : JSONValue
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ describe Propane do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile(test_file)
|
def compile(*test_files)
|
||||||
result = system(*%w[gdc -funittest -o spec/run/testparser spec/run/testparser.d], test_file)
|
result = system(*%w[gdc -funittest -o spec/run/testparser spec/run/testparser.d -Ispec], *test_files)
|
||||||
expect(result).to be_truthy
|
expect(result).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -341,9 +341,15 @@ 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 /\\}/RuRfaw2CHgpvCWu;
|
token rbrace /\\}/;
|
||||||
token lbracket /\\[/;
|
token lbracket /\\[/;
|
||||||
token rbracket /\\]/;
|
token rbracket /\\]/;
|
||||||
token comma /,/;
|
token comma /,/;
|
||||||
@ -360,7 +366,8 @@ token number /-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][-+]?[0-9]+)?/ <<
|
|||||||
negative = true;
|
negative = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$$ = new JSONNumber();
|
double n = 1.0;
|
||||||
|
$$ = new JSONNumber(n);
|
||||||
>>
|
>>
|
||||||
token true <<
|
token true <<
|
||||||
$$ = new JSONTrue();
|
$$ = new JSONTrue();
|
||||||
@ -375,8 +382,8 @@ token null <<
|
|||||||
$mode(string);
|
$mode(string);
|
||||||
string_value = "";
|
string_value = "";
|
||||||
>>
|
>>
|
||||||
string: token string /"/ <<
|
string: token string (string) /"/ <<
|
||||||
$$ = new JSONString(string_value);
|
$$ = string_value;
|
||||||
$mode(default);
|
$mode(default);
|
||||||
>>
|
>>
|
||||||
string: /\\\\"/ <<
|
string: /\\\\"/ <<
|
||||||
@ -414,7 +421,7 @@ Start -> Value <<
|
|||||||
$$ = $1;
|
$$ = $1;
|
||||||
>>
|
>>
|
||||||
Value -> string <<
|
Value -> string <<
|
||||||
$$ = $1;
|
$$ = new JSONString($1);
|
||||||
>>
|
>>
|
||||||
Value -> number <<
|
Value -> number <<
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
@ -440,7 +447,7 @@ Object -> lbrace rbrace <<
|
|||||||
Object -> lbrace KeyValues rbrace <<
|
Object -> lbrace KeyValues rbrace <<
|
||||||
$$ = new JSONObject($2);
|
$$ = new JSONObject($2);
|
||||||
>>
|
>>
|
||||||
KeyValues -> KeyValue <<
|
KeyValues (dict) -> KeyValue <<
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
>>
|
>>
|
||||||
KeyValues -> KeyValues comma KeyValue <<
|
KeyValues -> KeyValues comma KeyValue <<
|
||||||
@ -450,15 +457,23 @@ KeyValues -> KeyValues comma KeyValue <<
|
|||||||
}
|
}
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
>>
|
>>
|
||||||
KeyValue -> string colon Value <<
|
KeyValue (dict) -> 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")
|
compile("spec/test_parsing_json.d", "spec/json_types.d")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user