-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* data: Factor out Word operations, WordStack, ByteArray, and Account into evm-types.md data,evm-types: Move #addr from data to evm-types * data,evm: Move M3:2048 bloomfilter from data.md to evm.md, the only place it is used * data,driver: Move #removeZeros from data to driver, the only place it is used * data,serialization: Move various helpers from data to serialization * data,evm: Move #lookup to evm, next to the opcode that uses it * data,web3: Move JSON and JSON-RPC modules into json.md data,json: move JSONKEY ::= Int to JSON module * data: Move parsing/unparsing, rlp, and merkle tree stuff to serialization.md * Update concrete-rules.txt files * tests/interactive/sumTo10.evm.parse-expected: Change EVM-DATA to EVM-TYPES * evm,evm-types: Move #lookup to EVM-TYPES
- Loading branch information
Showing
12 changed files
with
1,386 additions
and
1,340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
### JSON Formatting | ||
|
||
The JSON format is used extensively for communication in the Ethereum circles. | ||
Writing a JSON-ish parser in K takes 6 lines. | ||
|
||
```k | ||
module JSON | ||
imports INT | ||
imports STRING | ||
imports BOOL | ||
syntax JSONs ::= List{JSON,","} [klabel(JSONs) , symbol] | ||
syntax JSONKey ::= String | ||
syntax JSON ::= "null" [klabel(JSONnull) , symbol] | ||
| String | Int | Bool | ||
| JSONKey ":" JSON [klabel(JSONEntry) , symbol] | ||
| "{" JSONs "}" [klabel(JSONObject) , symbol] | ||
| "[" JSONs "]" [klabel(JSONList) , symbol] | ||
// -------------------------------------------------------------------- | ||
``` | ||
|
||
**TODO**: Adding `Int` to `JSONKey` is a hack to make certain parts of semantics easier. | ||
|
||
```k | ||
syntax JSONKey ::= Int | ||
// ---------------------- | ||
endmodule | ||
``` | ||
|
||
JSON-RPC | ||
-------- | ||
|
||
```k | ||
module JSON-RPC | ||
imports K-IO | ||
imports LIST | ||
imports JSON | ||
configuration | ||
<json-rpc> | ||
<web3socket> $SOCK:Int </web3socket> | ||
<web3clientsocket> 0:IOInt </web3clientsocket> | ||
<web3request> | ||
<jsonrpc> "":JSON </jsonrpc> | ||
<callid> 0:JSON </callid> | ||
<method> "":JSON </method> | ||
<params> [ .JSONs ] </params> | ||
<batch> undef </batch> | ||
</web3request> | ||
<web3response> .List </web3response> | ||
</json-rpc> | ||
syntax JSON ::= "undef" [klabel(JSON-RPCundef), symbol] | ||
// ------------------------------------------------------- | ||
syntax Bool ::= isProperJson ( JSON ) [function] | ||
| isProperJsonList ( JSONs ) [function] | ||
// ----------------------------------------------------- | ||
rule isProperJson(_) => false [owise] | ||
rule isProperJson(null) => true | ||
rule isProperJson(_:Int) => true | ||
rule isProperJson(_:Bool) => true | ||
rule isProperJson(_:String) => true | ||
rule isProperJson(_:JSONKey : J) => isProperJson(J) | ||
rule isProperJson([ JS ]) => isProperJsonList(JS) | ||
rule isProperJson({ JS }) => isProperJsonList(JS) | ||
rule isProperJsonList(.JSONs) => true | ||
rule isProperJsonList(J, JS) => isProperJson(J) andBool isProperJsonList(JS) | ||
endmodule | ||
``` |
Oops, something went wrong.