A little tool for people who don't want to write a jass parser themselves. This tool can take a jass script as input and return a json representation of the jass ast or take a jass ast encoded as json and turn it into valid jass again. I don't know if this is of any value but i wanted to write this for a while. Source is of course available.
Below you can see a small example. But beware there is zero documentation. You have to figure out the json structure yourself. But that shouldn't bee too hard; just feed it with small example scripts.
test.j:
Convert it to json (note im using jq to pretty print it):
Now do some modifications:
And convert back to jass
Below you can see a small example. But beware there is zero documentation. You have to figure out the json structure yourself. But that shouldn't bee too hard; just feed it with small example scripts.
test.j:
JASS:
globals
integer array ARR
endglobals
function foo takes integer a, integer b returns integer
return a * ARR[b]
endfunction
Convert it to json (note im using jq to pretty print it):
Bash:
$ j2j to-json test.j | jq > test.json
JSON:
[
{
"def": {
"kind": "adef",
"name": "ARR",
"type": "vardef",
"vartype": "integer"
},
"kind": "global",
"type": "toplevel"
},
{
"body": [
{
"kind": "return",
"type": "stmt",
"value": {
"args": [
{
"kind": "svar",
"name": "a",
"type": "expr"
},
{
"index": {
"kind": "svar",
"name": "b",
"type": "expr"
},
"kind": "avar",
"name": "ARR",
"type": "expr"
}
],
"kind": "call",
"name": "*",
"type": "call"
}
}
],
"constant": false,
"kind": "function",
"name": "foo",
"parameters": [
[
"integer",
"a"
],
[
"integer",
"b"
]
],
"returntype": "integer",
"type": "toplevel"
}
]
Now do some modifications:
Diff:
20,21c20,21
< "kind": "svar",
< "name": "a",
---
> "kind": "rawcode",
> "value": "a",
27c27
< "name": "b",
---
> "name": "idx",
51c51
< "b"
---
> "idx"
And convert back to jass
Bash:
$ j2j to-jass test.json > new.j # test.json was modified like above
JASS:
globals
integer array ARR
endglobals
function foo takes integer a,integer idx returns integer
return ('a' * ARR [idx])
endfunction