mercury-lang
Version:
Parser for the mercury live coding language
1,928 lines (1,927 loc) • 26.5 kB
JSON
{
"parseTree": {
"global": {
"randomSeed": [
9876
],
"highPass": [
500,
3000
],
"lowPass": [
2000,
500
],
"silence": true,
"tempo": [
"hiphop",
"uptempo"
],
"scale": [
"major",
"g#"
],
"crossFade": [
100
]
},
"variables": {
"arr1": 3.141592654,
"arr2": [
1,
2,
3.141592654
],
"arr3": [
1,
2,
[
1,
2,
3.141592654
],
56,
7.89e-13
],
"arr4": [
"hat_dub",
"hat_dub_open",
"hat_909"
],
"arr5": [
"hello world",
"foo bar"
],
"arr6": [
1,
2,
[
3,
4
],
5,
[
6,
[
7,
8
],
9
],
10,
11
],
"beat": [
1,
0,
1,
0,
1,
0,
1,
0,
1,
1,
0,
1,
0,
1,
0,
1
],
"grv": [
"hat",
"snare",
"hat",
"hat",
"kick",
"hat",
"snare",
"kick"
],
"arpMel": [
0,
2,
4,
7,
9,
9,
7,
4,
2,
0,
0,
2,
4,
7,
9,
9,
7,
4,
2,
0,
7,
9,
11,
14,
16,
16,
14,
11,
9,
7,
3,
5,
7,
10,
12,
12,
10,
7,
5,
3
],
"join": [
[
18,
17,
17,
15
],
[
7,
8,
10,
0
]
],
"notes": [
"c4",
"e4",
"f4",
"d#4",
"gb5",
"gb5",
"d#4",
"f4",
"e4",
"c4"
]
},
"objects": {
"33GEZSXS": {
"object": "synth",
"type": "saw",
"functions": {
"group": [],
"time": [
"1/1",
0
],
"note": [
0,
0
],
"env": [
1,
250
],
"beat": [
1
],
"amp": [
0.7
],
"wave2": [
"saw",
0
],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"33GEZSXS"
]
}
},
"QNHP9S5T": {
"object": "sample",
"type": "hat",
"functions": {
"group": [],
"time": [
"1/1",
0
],
"speed": [
1
],
"env": [
-1
],
"beat": [
1
],
"amp": [
0.9
],
"stretch": [
0,
1,
1
],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"QNHP9S5T"
]
}
},
"Q7HQCAX8": {
"object": "midi",
"type": "default",
"functions": {
"group": [],
"time": [
"1/1",
0
],
"note": [
0,
0
],
"env": [
100
],
"out": [
1
],
"chord": "off",
"sync": "off",
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"Q7HQCAX8"
]
}
},
"RDLC3T3M": {
"object": "loop",
"type": "amen",
"functions": {
"group": [],
"time": [
"1/1",
0
],
"speed": [
1
],
"env": [
-1
],
"beat": [
1
],
"amp": [
0.9
],
"stretch": [
1,
1,
1
],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"RDLC3T3M"
]
}
},
"Y6HZN2T3": {
"object": "polySynth",
"type": "sine",
"functions": {
"group": [],
"time": [
"1/1",
0
],
"note": [
0,
0
],
"env": [
1,
250
],
"beat": [
1
],
"amp": [
0.7
],
"wave2": [
"saw",
0
],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"Y6HZN2T3"
]
}
},
"8W6VAFDF": {
"object": "polySample",
"type": "kick",
"functions": {
"group": [],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"8W6VAFDF"
]
}
},
"FGS65O42": {
"object": "osc",
"type": "address",
"functions": {
"group": [],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"FGS65O42"
]
}
},
"GU411TDT": {
"object": "sample",
"type": [
"hat",
"kick",
"snare"
],
"functions": {
"group": [],
"time": [
"1/1",
0
],
"speed": [
1
],
"env": [
-1
],
"beat": [
1
],
"amp": [
0.9
],
"stretch": [
0,
1,
1
],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"GU411TDT"
]
}
},
"NQT0O8F3": {
"object": "synth",
"type": [
"saw",
"triangle",
"sine"
],
"functions": {
"group": [],
"time": [
"1/1",
0
],
"note": [
0,
0
],
"env": [
1,
250
],
"beat": [
1
],
"amp": [
0.7
],
"wave2": [
"saw",
0
],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"NQT0O8F3"
]
}
},
"bob": {
"object": "synth",
"type": "saw",
"functions": {
"group": [],
"time": [
"1/8"
],
"note": [
[
0,
3,
7
],
0
],
"env": [
1,
50
],
"beat": [
1
],
"amp": [
0.7
],
"wave2": [
"saw",
0
],
"add_fx": [
[
"double"
],
[
"delay",
"3/16",
0.7
],
[
"reverb",
0.5,
5
]
],
"name": [
"bob"
]
}
},
"alice": {
"object": "sample",
"type": "kick",
"functions": {
"group": [],
"time": [
0.25,
0.5
],
"speed": [
1
],
"env": [
-1
],
"beat": [
[
1,
0,
1,
1
]
],
"amp": [
0.9
],
"stretch": [
0,
1,
1
],
"add_fx": [
[
"drive"
],
[
"reverb",
0.5,
5
]
],
"name": [
"alice"
]
}
},
"ZZLP3PRT": {
"object": "synth",
"type": "square",
"functions": {
"group": [],
"time": [
"1/16"
],
"note": [
[
6,
0,
10,
8,
0,
8,
10,
0
]
],
"env": [
1,
250
],
"beat": [
[
1,
0,
1,
0,
1,
1,
0,
1
]
],
"amp": [
0.7
],
"wave2": [
"saw",
0
],
"add_fx": [
[
"reverb",
0.5,
5
]
],
"name": [
"ZZLP3PRT"
]
}
}
},
"groups": {
"all": [
"bob",
"alice"
]
},
"print": [
[
12,
34,
-56,
7.89,
1011.121,
0.4321
],
[
"a",
"A",
"b",
"B",
"c",
"C",
"d",
"D",
"e",
"E",
"f",
"F",
"g",
"G"
],
[
"a#",
"B#",
"C#",
"Dx",
"Gb",
"fbb"
],
[
"a1",
"A0",
"b2b",
"B4#",
"c1",
"C2bb",
"d4##",
"D3",
"e2",
"E1",
"f4#",
"F5",
"g6",
"G2"
],
[
"1/4",
"3/16",
"7/16",
"4/5",
"3/1"
],
[
"7/8",
"3/2",
"1/5"
],
[
"hello world",
"also a string",
"and another!",
"this works?"
],
"1 +2 /3.14* 45.67",
[
"Kick_dub",
"dub_15",
"foLey-02.wav",
"-negative"
],
[
"~mySig",
"~my-sig",
"~my_Sig",
"~23sig",
"~sig423"
]
],
"display": [],
"comments": [
"// Parsing numbers",
"// Parse note names",
"// Parse rhythmic division values",
"// Parse comments",
"// valid strings start and end with: \"\" '' ``",
"// or a combination of those works as well",
"// Parse identifier/name",
"// valid identifiers start with characters [a-zA-Z]",
"// can have _ - . and numbers [0-9]",
"// Parse Signal modulation strings TODO",
"// Parsing osc type strings TODO",
"// print [ /oscString/param /oscString/temp /anotherOsc/param ]",
"// lists can have single values, arrays, keywords and strings",
"// lists can be generated with functions",
"// generate a synth, sample, loop or midi",
"// an instrument can have an array",
"// instruments can have functions",
"// functions can have functions",
"// set functions to named instruments",
"// set functions to all instruments",
"// set global settings"
]
},
"syntaxTree": {
"@main": [
{
"@global": {
"@comment": "// Parsing numbers"
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@number": 12
},
{
"@number": 34
},
{
"@number": -56
},
{
"@number": 7.89
},
{
"@number": 1011.121
},
{
"@number": 0.4321
}
]
}
]
}
},
{
"@global": {
"@comment": "// Parse note names"
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@note": "a"
},
{
"@note": "A"
},
{
"@note": "b"
},
{
"@note": "B"
},
{
"@note": "c"
},
{
"@note": "C"
},
{
"@note": "d"
},
{
"@note": "D"
},
{
"@note": "e"
},
{
"@note": "E"
},
{
"@note": "f"
},
{
"@note": "F"
},
{
"@note": "g"
},
{
"@note": "G"
}
]
}
]
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@note": "a#"
},
{
"@note": "B#"
},
{
"@note": "C#"
},
{
"@note": "Dx"
},
{
"@note": "Gb"
},
{
"@note": "fbb"
}
]
}
]
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@note": "a1"
},
{
"@note": "A0"
},
{
"@identifier": "b2b"
},
{
"@identifier": "B4#"
},
{
"@note": "c1"
},
{
"@identifier": "C2bb"
},
{
"@identifier": "d4##"
},
{
"@note": "D3"
},
{
"@note": "e2"
},
{
"@note": "E1"
},
{
"@identifier": "f4#"
},
{
"@note": "F5"
},
{
"@note": "g6"
},
{
"@note": "G2"
}
]
}
]
}
},
{
"@global": {
"@comment": "// Parse rhythmic division values"
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@division": "1/4"
},
{
"@division": "3/16"
},
{
"@division": "7/16"
},
{
"@division": "4/5"
},
{
"@division": "3/1"
}
]
}
]
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@division": "7/8"
},
{
"@division": "3/2"
},
{
"@division": "1/5"
}
]
}
]
}
},
{
"@global": {
"@comment": "// Parse comments"
}
},
{
"@global": {
"@comment": "// valid strings start and end with: \"\" '' ``"
}
},
{
"@global": {
"@comment": "// or a combination of those works as well"
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@string": "hello world"
},
{
"@string": "also a string"
},
{
"@string": "and another!"
},
{
"@string": "this works?"
}
]
}
]
}
},
{
"@global": {
"@print": [
{
"@string": "1 +2 /3.14* 45.67"
}
]
}
},
{
"@global": {
"@comment": "// Parse identifier/name"
}
},
{
"@global": {
"@comment": "// valid identifiers start with characters [a-zA-Z]"
}
},
{
"@global": {
"@comment": "// can have _ - . and numbers [0-9]"
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@identifier": "Kick_dub"
},
{
"@identifier": "dub_15"
},
{
"@identifier": "foLey-02.wav"
},
{
"@identifier": "-negative"
}
]
}
]
}
},
{
"@global": {
"@comment": "// Parse Signal modulation strings TODO"
}
},
{
"@global": {
"@print": [
{
"@array": [
{
"@signal": "~mySig"
},
{
"@signal": "~my-sig"
},
{
"@signal": "~my_Sig"
},
{
"@signal": "~23sig"
},
{
"@signal": "~sig423"
}
]
}
]
}
},
{
"@global": {
"@comment": "// Parsing osc type strings TODO"
}
},
{
"@global": {
"@comment": "// print [ /oscString/param /oscString/temp /anotherOsc/param ]"
}
},
{
"@global": {
"@comment": "// lists can have single values, arrays, keywords and strings"
}
},
{
"@list": {
"@name": "arr1",
"@params": {
"@number": 3.141592654
}
}
},
{
"@list": {
"@name": "arr2",
"@params": {
"@array": [
{
"@number": 1
},
{
"@number": 2
},
{
"@identifier": "arr1"
}
]
}
}
},
{
"@list": {
"@name": "arr3",
"@params": {
"@array": [
{
"@number": 1
},
{
"@number": 2
},
{
"@identifier": "arr2"
},
{
"@number": 56
},
{
"@number": 7.89e-13
}
]
}
}
},
{
"@list": {
"@name": "arr4",
"@params": {
"@array": [
{
"@identifier": "hat_dub"
},
{
"@identifier": "hat_dub_open"
},
{
"@identifier": "hat_909"
}
]
}
}
},
{
"@list": {
"@name": "arr5",
"@params": {
"@array": [
{
"@string": "hello world"
},
{
"@string": "foo bar"
}
]
}
}
},
{
"@list": {
"@name": "arr6",
"@params": {
"@array": [
{
"@number": 1
},
{
"@number": 2
},
{
"@array": [
{
"@number": 3
},
{
"@number": 4
}
]
},
{
"@number": 5
},
{
"@array": [
{
"@number": 6
},
{
"@array": [
{
"@number": 7
},
{
"@number": 8
}
]
},
{
"@number": 9
}
]
},
{
"@number": 10
},
{
"@number": 11
}
]
}
}
},
{
"@global": {
"@comment": "// lists can be generated with functions"
}
},
{
"@list": {
"@name": "beat",
"@params": {
"@function": {
"@name": "euclid",
"@args": [
{
"@number": 16
},
{
"@number": 9
},
{
"@number": 0
}
]
}
}
}
},
{
"@list": {
"@name": "grv",
"@params": {
"@function": {
"@name": "choose",
"@args": [
{
"@number": 8
},
{
"@array": [
{
"@identifier": "hat"
},
{
"@identifier": "kick"
},
{
"@identifier": "snare"
}
]
}
]
}
}
}
},
{
"@list": {
"@name": "arpMel",
"@params": {
"@function": {
"@name": "clone",
"@args": [
{
"@function": {
"@name": "palin",
"@args": [
{
"@function": {
"@name": "spread",
"@args": [
{
"@number": 5
},
{
"@number": 0
},
{
"@number": 12
}
]
}
}
]
}
},
{
"@number": 0
},
{
"@number": 0
},
{
"@number": 7
},
{
"@number": 3
}
]
}
}
}
},
{
"@list": {
"@name": "join",
"@params": {
"@array": [
{
"@function": {
"@name": "random",
"@args": [
{
"@number": 4
},
{
"@number": 10
},
{
"@number": 20
}
]
}
},
{
"@function": {
"@name": "urn",
"@args": [
{
"@number": 4
}
]
}
}
]
}
}
},
{
"@list": {
"@name": "notes",
"@params": {
"@function": {
"@name": "palin",
"@args": [
{
"@array": [
{
"@note": "c4"
},
{
"@note": "e4"
},
{
"@note": "f4"
},
{
"@note": "d#4"
},
{
"@note": "gb5"
}
]
}
]
}
}
}
},
{
"@global": {
"@comment": "// generate a synth, sample, loop or midi"
}
},
{
"@object": {
"@new": {
"@inst": "synth",
"@type": {
"@identifier": "saw"
}
}
}
},
{
"@object": {
"@new": {
"@inst": "sample",
"@type": {
"@identifier": "hat"
}
}
}
},
{
"@object": {
"@new": {
"@inst": "midi",
"@type": {
"@identifier": "default"
}
}
}
},
{
"@object": {
"@new": {
"@inst": "loop",
"@type": {
"@identifier": "amen"
}
}
}
},
{
"@object": {
"@new": {
"@inst": "polySynth",
"@type": {
"@identifier": "sine"
}
}
}
},
{
"@object": {
"@new": {
"@inst": "polySample",
"@type": {
"@identifier": "kick"
}
}
}
},
{
"@object": {
"@new": {
"@inst": "osc",
"@type": {
"@identifier": "address"
}
}
}
},
{
"@global": {
"@comment": "// an instrument can have an array"
}
},
{
"@object": {
"@new": {
"@inst": "sample",
"@type": {
"@array": [
{
"@identifier": "hat"
},
{
"@identifier": "kick"
},
{
"@identifier": "snare"
}
]
}
}
}
},
{
"@object": {
"@new": {
"@inst": "synth",
"@type": {
"@array": [
{
"@identifier": "saw"
},
{
"@identifier": "triangle"
},
{
"@identifier": "sine"
}
]
}
}
}
},
{
"@global": {
"@comment": "// instruments can have functions"
}
},
{
"@object": {
"@new": {
"@inst": "synth",
"@type": {
"@identifier": "saw"
},
"@functions": [
{
"@function": {
"@name": "note",
"@args": [
{
"@array": [
{
"@number": 0
},
{
"@number": 3
},
{
"@number": 7
}
]
},
{
"@number": 0
}
]
}
},
{
"@function": {
"@name": "time",
"@args": [
{
"@division": "1/8"
}
]
}
},
{
"@function": {
"@name": "env",
"@args": [
{
"@number": 1
},
{
"@number": 50
}
]
}
},
{
"@function": {
"@name": "name",
"@args": [
{
"@identifier": "bob"
}
]
}
}
]
}
}
},
{
"@object": {
"@new": {
"@inst": "sample",
"@type": {
"@identifier": "kick"
},
"@functions": [
{
"@function": {
"@name": "time",
"@args": [
{
"@number": 0.25
},
{
"@number": 0.5
}
]
}
},
{
"@function": {
"@name": "beat",
"@args": [
{
"@array": [
{
"@number": 1
},
{
"@number": 0
},
{
"@number": 1
},
{
"@number": 1
}
]
}
]
}
},
{
"@function": {
"@name": "name",
"@args": [
{
"@identifier": "alice"
}
]
}
}
]
}
}
},
{
"@global": {
"@comment": "// functions can have functions"
}
},
{
"@object": {
"@new": {
"@inst": "synth",
"@type": {
"@identifier": "square"
},
"@functions": [
{
"@function": {
"@name": "note",
"@args": [
{
"@function": {
"@name": "sine",
"@args": [
{
"@number": 8
},
{
"@number": 5.512
},
{
"@number": 0
},
{
"@number": 12
}
]
}
}
]
}
},
{
"@function": {
"@name": "beat",
"@args": [
{
"@function": {
"@name": "euclid",
"@args": [
{
"@number": 8
},
{
"@number": 5
}
]
}
}
]
}
},
{
"@function": {
"@name": "time",
"@args": [
{
"@division": "1/16"
}
]
}
}
]
}
}
},
{
"@global": {
"@comment": "// set functions to named instruments"
}
},
{
"@object": {
"@set": {
"@name": "bob",
"@functions": [
{
"@function": {
"@name": "add_fx",
"@args": [
{
"@identifier": "double"
}
]
}
},
{
"@function": {
"@name": "add_fx",
"@args": [
{
"@identifier": "delay"
},
{
"@division": "3/16"
},
{
"@number": 0.7
}
]
}
}
]
}
}
},
{
"@object": {
"@set": {
"@name": "alice",
"@functions": [
{
"@function": {
"@name": "add_fx",
"@args": [
{
"@identifier": "drive"
}
]
}
}
]
}
}
},
{
"@global": {
"@comment": "// set functions to all instruments"
}
},
{
"@object": {
"@set": {
"@name": "all",
"@functions": [
{
"@function": {
"@name": "add_fx",
"@args": [
{
"@identifier": "reverb"
},
{
"@number": 0.5
},
{
"@number": 5
}
]
}
}
]
}
}
},
{
"@global": {
"@comment": "// set global settings"
}
},
{
"@object": {
"@set": {
"@name": "randomSeed",
"@functions": [
{
"@number": 9876
}
]
}
}
},
{
"@object": {
"@set": {
"@name": "tempo",
"@functions": [
{
"@number": 143
},
{
"@number": 1000
}
]
}
}
},
{
"@object": {
"@set": {
"@name": "scale",
"@functions": [
{
"@identifier": "major"
},
{
"@note": "g#"
}
]
}
}
},
{
"@object": {
"@set": {
"@name": "hipass",
"@functions": [
{
"@number": 500
},
{
"@number": 3000
}
]
}
}
},
{
"@object": {
"@set": {
"@name": "lopass",
"@functions": [
{
"@number": 2000
},
{
"@number": 500
}
]
}
}
},
{
"@object": {
"@set": {
"@name": "crossFade",
"@functions": [
{
"@number": 100
}
]
}
}
},
{
"@object": {
"@set": {
"@name": "tempo",
"@functions": [
{
"@identifier": "hiphop"
},
{
"@identifier": "uptempo"
}
]
}
}
},
{
"@global": {
"@settings": {
"@identifier": "silence"
}
}
}
]
},
"errors": [
"Unknown instrument type: polySample",
"Unknown instrument type: osc",
"Error at line 83: Unexpected divider: '/' at new sample bell gain(/<-"
]
}