Skip to content

Commit 4d2e7a7

Browse files
committed
feat: complete density functions
1 parent bab6514 commit 4d2e7a7

739 files changed

Lines changed: 266761 additions & 2155 deletions

File tree

Some content is hidden

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

.helix/languages.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[language-server.mms-lsp]
2+
command = "go"
3+
args = ["run", "main.go", "lsp"]
4+
5+
[[language]]
6+
name = "mms"
7+
scope = "source.mms"
8+
injection-regex = "mms"
9+
file-types = ["mms"]
10+
comment-tokens = "#"
11+
language-servers = [ "mms-lsp" ]

go.mod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,29 @@ go 1.23
55
require (
66
github.com/antlr4-go/antlr/v4 v4.13.1
77
github.com/spf13/cobra v1.9.1
8+
github.com/tliron/glsp v0.2.2
89
)
910

1011
require (
12+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
13+
github.com/gorilla/websocket v1.5.1 // indirect
14+
github.com/iancoleman/strcase v0.3.0 // indirect
1115
github.com/inconshreveable/mousetrap v1.1.0 // indirect
16+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
17+
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
21+
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
1225
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
1329
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
1433
)

go.sum

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,54 @@
11
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
22
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
3+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
4+
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
35
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
6+
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=
9+
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
10+
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
411
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
512
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=
15+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
16+
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=
23+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
24+
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=
627
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=
732
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
833
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
934
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
1035
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=
1144
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
1245
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=
48+
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=
1353
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1454
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

grammar/Core_Lang.g4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ builder_Noise: '.Noise' (noiseDefinition | ('(' resourceReference ')'));
1010
builder_Smear: 'Smear' '(' number ')';
1111
builder_Type1: '.Type1' '(' ')';
1212
builder_Type2: '.Type2' '(' ')';
13-
builder_Shift: '.Shift' '(' Axis ',' densityFn ')';
13+
builder_ShiftX: '.ShiftX' '(' densityFn ')';
14+
builder_ShiftY: '.ShiftY' '(' densityFn ')';
15+
builder_ShiftZ: '.ShiftZ' '(' densityFn ')';
1416
builder_Amplitudes: '.Amplitudes' '(' (number ',')* number ')';
1517
builder_Offset: '.Offset(' Int ')';
1618
builder_Add:'.Add()';
@@ -26,10 +28,8 @@ builder_InRange: '.InRange' '(' densityFn ')';
2628
builder_OutRange: '.OutRange' '(' densityFn ')';
2729

2830

29-
3031
resourceReference: (Identifier ':')? Identifier;
3132

32-
Axis: 'x' | 'y' | 'z';
3333

3434
Int: '-'? [0-9]+;
3535
Float: ('-'? [0-9]* '.' [0-9]+);
@@ -38,7 +38,7 @@ number: Int | Float;
3838

3939
NL: [\n];
4040
WS: [ \t]+ -> skip;
41-
Identifier: [a-zA-Z][a-zA-Z0-9_]*;
41+
Identifier: [a-zA-Z] [a-zA-Z0-9_]*;
4242

4343
BlockComment: '/*' .*? '*/' -> channel(HIDDEN);
4444
LineComment: '//' ~[\r\n]* -> channel(HIDDEN);

grammar/DensityFunctions.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ densityFn_WierdScaledSampler: 'WeirdScaledSampler' NL* '(' NL* densityFn NL* ')'
7373
densityFn_WierdScaledSamplerBuilder: builder_Type1 | builder_Type2 | builder_Noise;
7474

7575
densityFn_ShiftedNoise: 'ShiftedNoise' NL* '(' NL* ')' NL* (densityFn_ShiftedNoiseBuilder NL*)*;
76-
densityFn_ShiftedNoiseBuilder: builder_Noise | builder_XZScale | builder_YScale | builder_Shift;
76+
densityFn_ShiftedNoiseBuilder: builder_Noise | builder_XZScale | builder_YScale | builder_ShiftX | builder_ShiftY | builder_ShiftZ;
7777

7878
densityFn_RangeChoice: 'RangeChoice' NL* '(' densityFn ')' NL* (densityFn_RangeChoiceBuilder NL*)*;
7979
densityFn_RangeChoiceBuilder: builder_Min | builder_Max | builder_InRange | builder_OutRange;

grammar/MinecraftMetascript.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Surface,DensityFunctions, Noise, Core_Lang;
44

55
script: NL* (namespace NL*)*;
66

7-
namespaceDeclaration: 'namespace' Identifier;
7+
namespaceDeclaration: 'Namespace' Identifier;
88
namespace: namespaceDeclaration NL* '{' NL* (contentBlocks NL*)* NL* '}';
99

1010
contentBlocks: surfaceBlock | noiseBlock | densityFnBlock;

lang/File.go

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

33
import (
4+
"github.com/minecraftmetascript/mms/lang/grammar"
45
"github.com/minecraftmetascript/mms/lang/traversal"
56
)
67

@@ -9,6 +10,7 @@ type File struct {
910
Path string
1011
Project *Project
1112
Diagnostics []traversal.Diagnostic
13+
Script *grammar.ScriptContext
1214
}
1315

1416
func (f *File) Parse() error {
@@ -18,10 +20,11 @@ func (f *File) Parse() error {
1820
return err
1921
}
2022
parser := traversal.NewParser(f.Content, f.Path, f.Project.GlobalScope, &f.Diagnostics)
21-
err = parser.Parse()
23+
script, err := parser.Parse()
2224
if err != nil {
2325
return err
2426
}
27+
f.Script = script
2528

2629
return nil
2730
}

lang/constructs/worldgen/density_functions/FunctionRef.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package density_functions
22

33
import (
44
"errors"
5-
"fmt"
65
"reflect"
76

87
"github.com/antlr4-go/antlr/v4"
@@ -57,9 +56,7 @@ func (c *ReferenceFunction) MarshalJSON() ([]byte, error) {
5756
return nil, err
5857
}
5958
if c.Value == nil {
60-
return nil, errors.New(
61-
fmt.Sprintf("unable to resolve reference %s", c.Ref.String()),
62-
)
59+
return c.Ref.MarshalJSON()
6360
}
6461
return (*c.Value).MarshalJSON()
6562
}

lang/constructs/worldgen/density_functions/RangeChoiceFn.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ func init() {
5353
input := densityFn.DensityFn()
5454
if input == nil {
5555
scope.DiagnoseSemanticError("Missing input to range choice", ctx)
56+
} else {
57+
out.Input = traversal.ConstructRegistry.Construct(input.(antlr.ParserRuleContext), currentNamespace, scope)
5658
}
57-
out.Input = traversal.ConstructRegistry.Construct(input.(antlr.ParserRuleContext), currentNamespace, scope)
5859

5960
for _, builderWrap := range densityFn.AllDensityFn_RangeChoiceBuilder() {
6061
builder_chain.Invoke(rangeChoiceBuilder, builderWrap.GetChild(0).(antlr.ParserRuleContext), out, scope, currentNamespace)

lang/constructs/worldgen/density_functions/ShiftedNoiseFn.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ func init() {
2525
builder_chain.Builder_GetFloat(ctx, func(v float64) { target.YScale = v }, scope, "YScale")
2626
},
2727
), builder_chain.Build(
28-
func(ctx *grammar.Builder_ShiftContext, target *ShiftedNoiseDensityFn, scope *traversal.Scope, namespace string) {
29-
axis := ctx.Axis()
30-
if axis == nil {
31-
scope.DiagnoseSemanticError("Missing or invalid Axis", ctx)
32-
return
33-
}
28+
func(ctx *grammar.Builder_ShiftXContext, target *ShiftedNoiseDensityFn, scope *traversal.Scope, namespace string) {
3429
childFnCtx := ctx.DensityFn()
3530
if childFnCtx == nil {
3631
scope.DiagnoseSemanticError("Missing or invalid Density Function", ctx)
@@ -40,22 +35,33 @@ func init() {
4035
if fn == nil {
4136
scope.DiagnoseSemanticError("Missing or invalid Density Function", ctx)
4237
}
38+
target.ShiftX = fn
39+
}),
40+
builder_chain.Build(
41+
func(ctx *grammar.Builder_ShiftYContext, target *ShiftedNoiseDensityFn, scope *traversal.Scope, namespace string) {
42+
childFnCtx := ctx.DensityFn()
43+
if childFnCtx == nil {
44+
scope.DiagnoseSemanticError("Missing or invalid Density Function", ctx)
45+
}
4346

44-
switch axis.GetText() {
45-
case "x":
46-
target.ShiftX = fn
47-
break
48-
case "y":
49-
target.ShiftY = fn
50-
break
51-
case "z":
52-
target.ShiftZ = fn
53-
break
54-
default:
55-
scope.DiagnoseSemanticError("Invalid Axis", ctx)
56-
break
47+
fn := traversal.ConstructRegistry.Construct(childFnCtx, namespace, scope)
48+
if fn == nil {
49+
scope.DiagnoseSemanticError("Missing or invalid Density Function", ctx)
50+
}
51+
target.ShiftY = fn
52+
}),
53+
builder_chain.Build(
54+
func(ctx *grammar.Builder_ShiftZContext, target *ShiftedNoiseDensityFn, scope *traversal.Scope, namespace string) {
55+
childFnCtx := ctx.DensityFn()
56+
if childFnCtx == nil {
57+
scope.DiagnoseSemanticError("Missing or invalid Density Function", ctx)
5758
}
5859

60+
fn := traversal.ConstructRegistry.Construct(childFnCtx, namespace, scope)
61+
if fn == nil {
62+
scope.DiagnoseSemanticError("Missing or invalid Density Function", ctx)
63+
}
64+
target.ShiftZ = fn
5965
}),
6066
)
6167
densityFn := ctx.(*grammar.DensityFn_ShiftedNoiseContext)

0 commit comments

Comments
 (0)