Skip to content

Commit 1ff7fb4

Browse files
committed
updates
1 parent a38dac0 commit 1ff7fb4

File tree

410 files changed

+39062
-13272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+39062
-13272
lines changed

cmd/lsp.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/minecraftmetascript/mms/lsp"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
// lspCmd represents the lsp command
11+
var lspCmd = &cobra.Command{
12+
Use: "lsp",
13+
14+
Run: func(cmd *cobra.Command, args []string) {
15+
if lsp.Start() != nil {
16+
panic("Failed to start LSP server")
17+
} else {
18+
fmt.Println("LSP Started")
19+
}
20+
},
21+
}
22+
23+
func init() {
24+
rootCmd.AddCommand(lspCmd)
25+
}

flake.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description = "DevShell with Antlr4 and Go";
33

44
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs/d98abf5cf5914e5e4e9d57205e3af55ca90ffc1d";
5+
nixpkgs.url = "github:NixOS/nixpkgs/648f70160c03151bc2121d179291337ad6bc564b";
66
flake-utils.url = "github:numtide/flake-utils";
77

88
};
@@ -85,16 +85,21 @@
8585
buildPhase = ''
8686
export GOOS=js
8787
export GOARCH=wasm
88+
export HOME="$TMPDIR"
89+
export GOPATH="$TMPDIR/go"
90+
export GOMODCACHE="$GOPATH/pkg/mod"
8891
export GOCACHE="$TMPDIR/go-cache"
89-
go build -o main.wasm
92+
export GOPROXY=off
93+
94+
go build -o main.wasm -mod=vendor
9095
'';
9196
installPhase = ''
9297
mkdir -p $out/js/dist
9398
mv main.wasm $out/js/dist
9499
cp $src/wasm/* $out/js -r
95100
cp $src/wasm/.* $out/js -r
96101
97-
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" $out/
102+
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" $out/
98103
'';
99104
};
100105
}

go.mod

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
module github.com/minecraftmetascript/mms
22

3-
go 1.23
3+
go 1.24.4
44

55
require (
66
github.com/antlr4-go/antlr/v4 v4.13.1
7-
github.com/spf13/cobra v1.9.1
8-
github.com/tliron/glsp v0.2.2
7+
github.com/spf13/cobra v1.10.1
8+
github.com/tliron/commonlog v0.2.20
9+
github.com/tliron/glsp v0.2.3-0.20250617204849-59d6e3155c81
910
)
1011

1112
require (
1213
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
13-
github.com/gorilla/websocket v1.5.1 // indirect
14+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
1415
github.com/iancoleman/strcase v0.3.0 // indirect
1516
github.com/inconshreveable/mousetrap v1.1.0 // indirect
16-
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
17+
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
1718
github.com/mattn/go-isatty v0.0.20 // indirect
18-
github.com/mattn/go-runewidth v0.0.14 // indirect
19-
github.com/muesli/termenv v0.15.2 // indirect
20-
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
19+
github.com/muesli/termenv v0.16.0 // indirect
20+
github.com/petermattis/goid v0.0.0-20250904145737-900bdf8bb490 // indirect
2121
github.com/pkg/errors v0.9.1 // indirect
22-
github.com/rivo/uniseg v0.2.0 // indirect
23-
github.com/sasha-s/go-deadlock v0.3.1 // indirect
24-
github.com/sourcegraph/jsonrpc2 v0.2.0 // indirect
25-
github.com/spf13/pflag v1.0.6 // indirect
26-
github.com/tliron/commonlog v0.2.8 // indirect
27-
github.com/tliron/kutil v0.3.11 // indirect
28-
golang.org/x/crypto v0.15.0 // indirect
29-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
30-
golang.org/x/net v0.17.0 // indirect
31-
golang.org/x/sys v0.14.0 // indirect
32-
golang.org/x/term v0.14.0 // indirect
22+
github.com/rivo/uniseg v0.4.7 // indirect
23+
github.com/sasha-s/go-deadlock v0.3.6 // indirect
24+
github.com/segmentio/ksuid v1.0.4 // indirect
25+
github.com/sourcegraph/jsonrpc2 v0.2.1 // indirect
26+
github.com/spf13/pflag v1.0.10 // indirect
27+
github.com/tliron/kutil v0.3.27 // indirect
28+
golang.org/x/crypto v0.42.0 // indirect
29+
golang.org/x/exp v0.0.0-20250911091902-df9299821621 // indirect
30+
golang.org/x/net v0.44.0 // indirect
31+
golang.org/x/sys v0.36.0 // indirect
32+
golang.org/x/term v0.35.0 // indirect
3333
)

go.sum

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,53 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
44
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
55
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
66
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
7-
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
8-
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
7+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
8+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
99
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
1010
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
1111
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
1212
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
13-
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
14-
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
13+
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
14+
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
1515
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
1616
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
17-
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
18-
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
19-
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
20-
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
21-
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
22-
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
17+
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
18+
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
19+
github.com/petermattis/goid v0.0.0-20250813065127-a731cc31b4fe/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
20+
github.com/petermattis/goid v0.0.0-20250904145737-900bdf8bb490 h1:QTvNkZ5ylY0PGgA+Lih+GdboMLY/G9SEGLMEGVjTVA4=
21+
github.com/petermattis/goid v0.0.0-20250904145737-900bdf8bb490/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
2322
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
2423
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
25-
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
26-
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
24+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
25+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
2726
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
28-
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
29-
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
30-
github.com/sourcegraph/jsonrpc2 v0.2.0 h1:KjN/dC4fP6aN9030MZCJs9WQbTOjWHhrtKVpzzSrr/U=
31-
github.com/sourcegraph/jsonrpc2 v0.2.0/go.mod h1:ZafdZgk/axhT1cvZAPOhw+95nz2I/Ra5qMlU4gTRwIo=
32-
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
33-
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
34-
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
35-
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
36-
github.com/tliron/commonlog v0.2.8 h1:vpKrEsZX4nlneC9673pXpeKqv3cFLxwpzNEZF1qiaQQ=
37-
github.com/tliron/commonlog v0.2.8/go.mod h1:HgQZrJEuiKLLRvUixtPWGcmTmWWtKkCtywF6x9X5Spw=
38-
github.com/tliron/glsp v0.2.2 h1:IKPfwpE8Lu8yB6Dayta+IyRMAbTVunudeauEgjXBt+c=
39-
github.com/tliron/glsp v0.2.2/go.mod h1:GMVWDNeODxHzmDPvYbYTCs7yHVaEATfYtXiYJ9w1nBg=
40-
github.com/tliron/kutil v0.3.11 h1:kongR0dhrrn9FR/3QRFoUfQe27t78/xQvrU9aXIy5bk=
41-
github.com/tliron/kutil v0.3.11/go.mod h1:4IqOAAdpJuDxYbJxMv4nL8LSH0mPofSrdwIv8u99PDc=
42-
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
43-
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
44-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
45-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
46-
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
47-
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
27+
github.com/sasha-s/go-deadlock v0.3.6 h1:TR7sfOnZ7x00tWPfD397Peodt57KzMDo+9Ae9rMiUmw=
28+
github.com/sasha-s/go-deadlock v0.3.6/go.mod h1:CUqNyyvMxTyjFqDT7MRg9mb4Dv/btmGTqSR+rky/UXo=
29+
github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c=
30+
github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=
31+
github.com/sourcegraph/jsonrpc2 v0.2.1 h1:2GtljixMQYUYCmIg7W9aF2dFmniq/mOr2T9tFRh6zSQ=
32+
github.com/sourcegraph/jsonrpc2 v0.2.1/go.mod h1:ZafdZgk/axhT1cvZAPOhw+95nz2I/Ra5qMlU4gTRwIo=
33+
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
34+
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
35+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
36+
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
37+
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
38+
github.com/tliron/commonlog v0.2.20 h1:LjzkpM5tc9pB2UHVe4wnKN5ay5BxSFnDGCNhsKFqELo=
39+
github.com/tliron/commonlog v0.2.20/go.mod h1:v/8FkL/gzsX/1N48vK1luLa4xFasHfzYBONX7/4mD5Y=
40+
github.com/tliron/glsp v0.2.3-0.20250617204849-59d6e3155c81 h1:gQPs3aNGs4z0AWq4v1iyaA6eyoE0RvGihgDPw6REIhY=
41+
github.com/tliron/glsp v0.2.3-0.20250617204849-59d6e3155c81/go.mod h1:0mr4+bYwGddJfGuaxnUZBSxkshSzFOIyTmBRvfJDBo4=
42+
github.com/tliron/kutil v0.3.27 h1:Wb0V5jdbTci6Let1tiGY741J/9FIynmV/pCsPDPsjcM=
43+
github.com/tliron/kutil v0.3.27/go.mod h1:AHeLNIFBSKBU39ELVHZdkw2f/ez2eKGAAGoxwBlhMi8=
44+
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
45+
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
46+
golang.org/x/exp v0.0.0-20250911091902-df9299821621 h1:2id6c1/gto0kaHYyrixvknJ8tUK/Qs5IsmBtrc+FtgU=
47+
golang.org/x/exp v0.0.0-20250911091902-df9299821621/go.mod h1:TwQYMMnGpvZyc+JpB/UAuTNIsVJifOlSkrZkhcvpVUk=
48+
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
49+
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
4850
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
49-
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
50-
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
51-
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
52-
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
51+
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
52+
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
53+
golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
54+
golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
5355
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5456
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

grammar/Core_Lang.g4

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Noise, DensityFunctions, Surface;
44

55
declare: Identifier NL* '=' NL*;
66

7+
78
builder_XZScale: '.XZScale(' NL* number NL* ')';
89
builder_YScale: '.YScale(' NL* number NL* ')';
910
builder_XZFactor: '.XZFactor(' NL* number NL* ')';
@@ -20,12 +21,12 @@ builder_Offset: '.Offset' '(' NL* Int NL* ')';
2021
builder_Add:'.Add' '(' ')' ;
2122
builder_Mul: '.Mul(' NL* number NL* ')';
2223
builder_MulInt: '.Mul(' NL* Int NL* ')';
23-
builder_Min: '.Min(' NL* number NL* ')';
24-
builder_Max: '.Max(' NL* number NL* ')';
24+
builder_Min: '.Min(' NL* (number) NL* ')';
25+
builder_Max: '.Max(' NL* (number) NL* ')';
2526
builder_Top: '.Top' '(' NL* verticalAnchor NL* ')';
26-
builder_TopLiteral: '.Top' '(' Int ')';
27+
builder_TopLiteral: '.Top' '(' (Int) ')';
2728
builder_Bottom: '.Bottom' '(' NL* verticalAnchor NL* ')';
28-
builder_BottomLiteral: '.Bottom' '('NL* Int NL* ')';
29+
builder_BottomLiteral: '.Bottom' '('NL* (Int) NL* ')';
2930
builder_InRange: '.InRange' '(' NL* densityFn NL* ')';
3031
builder_OutRange: '.OutRange' '(' NL* densityFn NL* ')';
3132

grammar/DensityFunctions.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ grammar DensityFunctions;
22

33
import Core_Lang, Noise;
44

5-
densityFnBlock: 'DensityFn' NL* '{' NL* (densityFnDeclaration NL*)* NL* '}';
5+
densityFnBlock: 'DensityFn' NL* '{' NL* ((densityFnDeclaration) NL*)* NL* '}';
6+
67

78
densityFnDeclaration: declare densityFn;
89
densityFn: (

grammar/Func.g4

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
grammar Func;
2+
3+
import Core_Lang;
4+
5+
FuncParamType: 'int' | 'float';
6+
7+
Variable: '$' [a-zA-Z] [a-z0-9A-Z_]*;
8+
paramDef: Variable ':' FuncParamType;
9+
funcOf: 'func' NL* '(' NL* (paramDef NL* ',' NL*)* NL* (paramDef)? NL* ')' NL* '->';
10+
param: Identifier | number;
11+
funcCall: Identifier '(' (param ',')* (param)? ')';

grammar/MinecraftMetascript.g4

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
grammar MinecraftMetascript;
22

3-
import Surface,DensityFunctions, Noise, NoiseRouter, NoiseSettings, Core_Lang;
3+
// Imports maintain priority order
4+
// (e.g. Core_Lang has the lowest priority, and only matches when no other grammars contain matches)
5+
import
6+
Surface,
7+
DensityFunctions,
8+
Noise,
9+
NoiseRouter,
10+
NoiseSettings,
11+
Core_Lang;
412

513
script: NL* (namespace NL*)*;
614

lang/File.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lang
22

33
import (
4+
"github.com/antlr4-go/antlr/v4"
45
"github.com/minecraftmetascript/mms/lang/grammar"
56
"github.com/minecraftmetascript/mms/lang/traversal"
67
)
@@ -28,3 +29,34 @@ func (f *File) Parse() error {
2829

2930
return nil
3031
}
32+
33+
func rulesAt(parent antlr.ParserRuleContext, position int) ([]antlr.ParserRuleContext, error) {
34+
out := make([]antlr.ParserRuleContext, 0)
35+
out = append(out, parent)
36+
if parent.GetStart().GetStart() > position || position > parent.GetStop().GetStop() {
37+
return nil, nil
38+
}
39+
40+
for _, child := range parent.GetChildren() {
41+
if rule, ok := child.(antlr.ParserRuleContext); ok {
42+
if rule.GetStart().GetStart() < position && position < rule.GetStop().GetStop() {
43+
// We are within this rule
44+
result, err := rulesAt(rule, position)
45+
if err != nil {
46+
return nil, err
47+
}
48+
if result != nil {
49+
out = append(out, result...)
50+
}
51+
}
52+
}
53+
}
54+
return out, nil
55+
56+
}
57+
58+
func (f *File) GetRulesAtPosition(position int) []antlr.ParserRuleContext {
59+
rules, _ := rulesAt(f.Script, position)
60+
return rules
61+
62+
}

0 commit comments

Comments
 (0)