Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions .helix/languages.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[language-server.mms-lsp]
command = "go"
args = ["run", "main.go", "lsp"]

[[language]]
name = "mms"
scope = "source.mms"
injection-regex = "mms"
file-types = ["mms"]
comment-tokens = "#"
language-servers = [ "mms-lsp" ]
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

packages.default = pkgs.buildGoModule {
pname = "mms";
version = "0.3.1";
version = "0.3.2";
src = ./.;
vendorHash = null;
# If you use vendoring, run `go mod vendor` and replace null with the hash
Expand All @@ -79,7 +79,7 @@

packages.wasm = pkgs.stdenvNoCC.mkDerivation {
pname = "mms-wasm";
version = "0.3.1";
version = "0.3.2";
src = ./.;
buildInputs = [ pkgs.go ];
buildPhase = ''
Expand Down
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@ go 1.23
require (
github.com/antlr4-go/antlr/v4 v4.13.1
github.com/spf13/cobra v1.9.1
github.com/tliron/glsp v0.2.2
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sourcegraph/jsonrpc2 v0.2.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/tliron/commonlog v0.2.8 // indirect
github.com/tliron/kutil v0.3.11 // indirect
golang.org/x/crypto v0.15.0 // indirect
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Critical: golang.org/x/crypto v0.15.0 has multiple CRITICAL vulns — bump to a safe version

Static analysis flags several critical advisories on v0.15.0. Please upgrade x/crypto to the latest patched release and re-tidy.

Run to determine and apply the latest version, then verify vuln closure:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show latest available
go list -m -u -json golang.org/x/crypto | jq -r '.Path, ("current="+.Version), ("latest="+(.Update.version // "n/a"))'

# Upgrade to latest safe (edit if you must pin)
go get golang.org/x/crypto@latest
go mod tidy

# Optional: check for known vulns across deps (requires osv-scanner)
# osv-scanner --skip-git -r .

Length of output: 210


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Bypass vendor directory for upgrade check
go list -m -u -json golang.org/x/crypto -mod=mod | jq -r '.Path, ("current="+.Version), ("latest="+(.Update.version // "n/a"))'

# Upgrade to latest bypassing vendor
go get golang.org/x/crypto@latest -mod=mod
go mod tidy -mod=mod

# Optional: re-run vulnerability scan if osv-scanner is installed
# osv-scanner --skip-git -r .

Length of output: 109


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Force module mode to bypass vendor directory
export GOFLAGS=-mod=mod

# Show current and latest versions of x/crypto
go list -m -u -json golang.org/x/crypto | jq -r '.Path, ("current="+.Version), ("latest="+(.Update.version // "n/a"))'

# Upgrade to the latest version and tidy
go get golang.org/x/crypto@latest
go mod tidy

Length of output: 969


Critical: Upgrade applied but tidy failing due to missing grammar module

  • golang.org/x/crypto successfully upgraded from v0.15.0 → v0.42.0 (vulnerabilities addressed)
  • go mod tidy now errors on github.com/minecraftmetascript/mms/lang/grammar: ensure that package path exists or update the import/version for the grammar module before merging
🧰 Tools
🪛 OSV Scanner (2.1.0)

[CRITICAL] 28-28: golang.org/x/crypto 0.15.0: Man-in-the-middle attacker can compromise integrity of secure channel in golang.org/x/crypto

(GO-2023-2402)


[CRITICAL] 28-28: golang.org/x/crypto 0.15.0: Misuse of connection.serverAuthenticate may cause authorization bypass in golang.org/x/crypto

(GO-2024-3321)


[CRITICAL] 28-28: golang.org/x/crypto 0.15.0: Potential denial of service in golang.org/x/crypto

(GO-2025-3487)


[CRITICAL] 28-28: golang.org/x/crypto 0.15.0: Prefix Truncation Attack against ChaCha20-Poly1305 and Encrypt-then-MAC aka Terrapin

(GHSA-45x7-px36-x8w8)


[CRITICAL] 28-28: golang.org/x/crypto 0.15.0: golang.org/x/crypto Vulnerable to Denial of Service (DoS) via Slow or Incomplete Key Exchange

(GHSA-hcg3-q754-cr77)


[CRITICAL] 28-28: golang.org/x/crypto 0.15.0: Misuse of ServerConfig.PublicKeyCallback may cause authorization bypass in golang.org/x/crypto

(GHSA-v778-237x-gjrc)

🤖 Prompt for AI Agents
In go.mod around line 28, after upgrading golang.org/x/crypto, go mod tidy fails
because the import github.com/minecraftmetascript/mms/lang/grammar cannot be
resolved; verify that the module path and version exist (or correct the path),
then update go.mod to point to a valid module/version (or add a replace
directive to the correct local or upstream module path), run `go get
github.com/minecraftmetascript/mms@<valid-version>` (or `go mod edit
-replace=...` if using a fork/local copy), and finally run `go mod tidy` to
remove or fix broken imports; if the grammar package is no longer used, remove
its imports from source instead.

golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
)
40 changes: 40 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
github.com/sourcegraph/jsonrpc2 v0.2.0 h1:KjN/dC4fP6aN9030MZCJs9WQbTOjWHhrtKVpzzSrr/U=
github.com/sourcegraph/jsonrpc2 v0.2.0/go.mod h1:ZafdZgk/axhT1cvZAPOhw+95nz2I/Ra5qMlU4gTRwIo=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/tliron/commonlog v0.2.8 h1:vpKrEsZX4nlneC9673pXpeKqv3cFLxwpzNEZF1qiaQQ=
github.com/tliron/commonlog v0.2.8/go.mod h1:HgQZrJEuiKLLRvUixtPWGcmTmWWtKkCtywF6x9X5Spw=
github.com/tliron/glsp v0.2.2 h1:IKPfwpE8Lu8yB6Dayta+IyRMAbTVunudeauEgjXBt+c=
github.com/tliron/glsp v0.2.2/go.mod h1:GMVWDNeODxHzmDPvYbYTCs7yHVaEATfYtXiYJ9w1nBg=
github.com/tliron/kutil v0.3.11 h1:kongR0dhrrn9FR/3QRFoUfQe27t78/xQvrU9aXIy5bk=
github.com/tliron/kutil v0.3.11/go.mod h1:4IqOAAdpJuDxYbJxMv4nL8LSH0mPofSrdwIv8u99PDc=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
32 changes: 30 additions & 2 deletions grammar/Core_Lang.g4
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
grammar Core_Lang;

import Noise, DensityFunctions, Surface;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Break circular grammar import (Core_Lang ↔ DensityFunctions).

Core_Lang imports DensityFunctions, and DensityFunctions imports Core_Lang. ANTLR import cycles are not supported and will fail generation. Move densityFn-dependent builders out of Core_Lang and drop the import.

-import Noise, DensityFunctions, Surface;
+import Noise, Surface;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import Noise, DensityFunctions, Surface;
import Noise, Surface;


builder_XZScale: '.XZScale(' NL* number NL* ')';
builder_YScale: '.YScale(' NL* number NL* ')';
builder_XZFactor: '.XZFactor(' NL* number NL* ')';
builder_YFactor: '.YFactor(' NL* number NL* ')';
builder_Noise: '.Noise' (noiseDefinition | ('(' NL* resourceReference NL* ')'));
builder_Smear: 'Smear' '(' NL* number NL* ')';
builder_Type1: '.Type1' '(' ')';
builder_Type2: '.Type2' '(' ')';
builder_ShiftX: '.ShiftX' '(' NL* densityFn NL* ')';
builder_ShiftY: '.ShiftY' '(' NL* densityFn NL* ')';
builder_ShiftZ: '.ShiftZ' '(' NL* densityFn NL* ')';
builder_Amplitudes: '.Amplitudes' '(' (number ',')* number ')';
builder_Offset: '.Offset' '(' NL* Int NL* ')';
builder_Add:'.Add' '(' ')' ;
builder_Mul: '.Mul(' NL* number NL* ')';
builder_MulInt: '.Mul(' NL* Int NL* ')';
builder_Min: '.Min(' NL* number NL* ')';
builder_Max: '.Max(' NL* number NL* ')';
builder_Top: '.Top' '(' NL* verticalAnchor NL* ')';
builder_TopLiteral: '.Top' '(' Int ')';
builder_Bottom: '.Bottom' '(' NL* verticalAnchor NL* ')';
builder_BottomLiteral: '.Bottom' '('NL* Int NL* ')';
builder_InRange: '.InRange' '(' NL* densityFn NL* ')';
builder_OutRange: '.OutRange' '(' NL* densityFn NL* ')';


resourceReference: (Identifier ':')? Identifier;


Int: '-'? [0-9]+;
Float: ('-'? [0-9]+ '.' [0-9]+);
Float: ('-'? [0-9]* '.' [0-9]+);
String: '"' ~[\r\n]* '"';
number: Int | Float;

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

BlockComment: '/*' .*? '*/' -> channel(HIDDEN);
LineComment: '//' ~[\r\n]* -> channel(HIDDEN);
98 changes: 98 additions & 0 deletions grammar/DensityFunctions.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
grammar DensityFunctions;

import Core_Lang, Noise;

densityFnBlock: 'DensityFn' NL* '{' NL* (densityFnDeclaration NL*)* NL* '}';

densityFnDeclaration: Identifier NL* '=' NL* densityFn;
densityFn: (
densityFn_SingleInput
| densityFn_Cache
| densityFn_DualInput
| densityFn_Constant
| densityFn_Noise
| densityFn_NoInput
| densityFn_OldBlendedNoise
| densityFn_WierdScaledSampler
| densityFn_ShiftedNoise
| densityFn_RangeChoice
| densityFn_Clamp
| densityFn_YClampedGradient
| densityFn_SplineFn
| densityFn_Reference // should be last
) densityFn_Math?;

densityFn_NoInput: (
'BlendAlpha'
| 'BlendOffset'
| 'EndIslands'
);

densityFn_SingleInput: (
'Interpolated'
| 'BlendDensity'
| 'FlatCache'
| 'Abs'
| 'Square'
| 'Cube'
| 'HalfNeg'
| 'QuarterNeg'
| 'Squeeze'
| 'Shift'
| 'ShiftA'
| 'ShiftB'
) NL* '(' NL* densityFn NL* ')';

densityFn_InlineNoise: noise;

densityFn_Noise: (
('Noise' NL* '(' NL* (resourceReference) NL* ')') | densityFn_InlineNoise
) NL* (densityFn_NoiseBuilder NL*)*;

densityFn_NoiseBuilder: builder_XZScale | builder_YScale;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Localize densityFn-dependent builders here to break grammar cycle (paired with Core_Lang.g4 change).

These builders reference densityFn; defining them in Core_Lang creates a circular import (Core_Lang ↔ DensityFunctions). Add them here and remove from Core_Lang.

 densityFn_NoiseBuilder: builder_XZScale | builder_YScale;
+
+// densityFn-scoped builders (moved from Core_Lang to avoid circular import)
+builder_Shift: '.Shift' '(' Axis ',' densityFn ')';
+builder_InRange: '.InRange' '(' densityFn ')';
+builder_OutRange: '.OutRange' '(' densityFn ')';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
densityFn_NoiseBuilder: builder_XZScale | builder_YScale;
densityFn_NoiseBuilder: builder_XZScale | builder_YScale;
// densityFn-scoped builders (moved from Core_Lang to avoid circular import)
builder_Shift: '.Shift' '(' Axis ',' densityFn ')';
builder_InRange: '.InRange' '(' densityFn ')';
builder_OutRange: '.OutRange' '(' densityFn ')';
🤖 Prompt for AI Agents
In grammar/DensityFunctions.g4 around line 52, localize the densityFn-dependent
builder rules (specifically builder_XZScale and builder_YScale) here instead of
in Core_Lang to break the circular grammar dependency; move the full rule
definitions for those builders from Core_Lang into this file, update any rule
references to point to these local definitions, and remove their definitions
from Core_Lang so Core_Lang only references densityFn (no reciprocal import).
Ensure rule names and token references remain identical and run the grammar
build to confirm no unresolved references.


DensityFn_CacheKind: '2d' | 'Once' | 'All';
densityFn_Cache: 'Cache' NL* '(' NL* DensityFn_CacheKind NL* ',' NL* densityFn NL* ')';

densityFn_DualInput: (
| 'Min'
| 'Max'
) NL* '(' NL* densityFn ',' NL* densityFn NL* ')';
Comment on lines +57 to +60
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove stray empty alternative in densityFn_DualInput (parsing bug).

The leading | introduces an empty alternative, making ( valid without Min/Max. This will parse invalid input and likely breaks intent.

Apply:

-densityFn_DualInput: (
-    | 'Min'
-    | 'Max'
-) NL* '(' NL* densityFn ',' NL* densityFn NL* ')';
+densityFn_DualInput: (
+      'Min'
+    | 'Max'
+) NL* '(' NL* densityFn ',' NL* densityFn NL* ')';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
densityFn_DualInput: (
| 'Min'
| 'Max'
) NL* '(' NL* densityFn ',' NL* densityFn NL* ')';
densityFn_DualInput: (
'Min'
| 'Max'
) NL* '(' NL* densityFn ',' NL* densityFn NL* ')';
🤖 Prompt for AI Agents
In grammar/DensityFunctions.g4 around lines 57 to 60, the densityFn_DualInput
rule contains a leading '|' which creates an empty alternative allowing '('
without 'Min' or 'Max'; remove the stray leading '|' so the alternatives are
enumerated properly (e.g. replace the block so the first alternative is 'Min'
and the second is 'Max') and keep the surrounding NL* and punctuation unchanged
to restore correct parsing.


densityFn_OldBlendedNoise: 'OldBlendedNoise' NL* '(' NL* ')' NL* (densityFn_OldBlendedNoiseBuilder NL*)*;
densityFn_OldBlendedNoiseBuilder:
builder_XZScale
| builder_YScale
| builder_XZFactor
| builder_YFactor
| builder_Smear;


densityFn_WierdScaledSampler: 'WeirdScaledSampler' NL* '(' NL* densityFn NL* ')' NL* (densityFn_WierdScaledSamplerBuilder NL*)*;

densityFn_WierdScaledSamplerBuilder: builder_Type1 | builder_Type2 | builder_Noise;

densityFn_ShiftedNoise: 'ShiftedNoise' NL* '(' NL* ')' NL* (densityFn_ShiftedNoiseBuilder NL*)*;
densityFn_ShiftedNoiseBuilder: builder_Noise | builder_XZScale | builder_YScale | builder_ShiftX | builder_ShiftY | builder_ShiftZ;

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

densityFn_Clamp: 'Clamp' NL* '(' densityFn ')' NL* (densityFn_ClampBuilder NL*)*;
densityFn_ClampBuilder: builder_Min | builder_Max;

densityFn_YClampedGradient: 'YClampedGradient' NL* '(' NL* ')' NL* (densityFn_YClampedGradientBuilder NL*)*;
densityFn_YClampedGradientBuilder: builder_TopLiteral | builder_BottomLiteral | builder_Min | builder_Max;

densityFn_SplineFn: densityFn_Spline;
densityFn_Spline: 'Spline' NL* (('(' NL* densityFn NL* ')' NL* (densityFn_SplinePoint NL*)* ) | '(' number ')');
densityFn_SplinePoint: '.Point' '(' number ',' (number | densityFn_Spline | resourceReference) ',' number ')';
Comment on lines +88 to +89
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Eliminate Spline ambiguity (both alts match Spline(number)).

As written, Spline(5) matches both alts since number ∈ densityFn_Constant. Require at least one .Point when using the densityFn alt, or drop the number-only alternative.

Apply:

-densityFn_Spline: 'Spline' NL* (('(' NL* densityFn NL* ')' NL* (densityFn_SplinePoint NL*)* ) | '(' number ')');
+densityFn_Spline:
+  'Spline' NL* (
+      '(' NL* densityFn NL* ')' NL* (densityFn_SplinePoint NL*)+
+    | '(' NL* number NL* ')'
+  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
densityFn_Spline: 'Spline' NL* (('(' NL* densityFn NL* ')' NL* (densityFn_SplinePoint NL*)* ) | '(' number ')');
densityFn_SplinePoint: '.Point' '(' number ',' (number | densityFn_Spline | resourceReference) ',' number ')';
densityFn_Spline:
'Spline' NL* (
'(' NL* densityFn NL* ')' NL* (densityFn_SplinePoint NL*)+
| '(' NL* number NL* ')'
);
🤖 Prompt for AI Agents
In grammar/DensityFunctions.g4 around lines 88-89, the Spline rule is ambiguous
because Spline(number) matches both alternatives; change the first alternative
that accepts '(' NL* densityFn NL* ')' NL* (densityFn_SplinePoint NL*)* to
require at least one .Point by making the trailing points repetition one-or-more
(i.e., change the '*' for densityFn_SplinePoint to '+') so Spline(number) no
longer matches that alt (alternatively remove the standalone '(' number ')'
alternative if you prefer the simpler syntax).


densityFn_Constant: number;
densityFn_Reference: resourceReference;
densityFn_Math: ('+' | '*') NL* densityFn;


/*
5.15 spline
*/
6 changes: 3 additions & 3 deletions grammar/MinecraftMetascript.g4
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
grammar MinecraftMetascript;

import Surface, Noise, Core_Lang;
import Surface,DensityFunctions, Noise, Core_Lang;

script: NL* (namespace NL*)*;

namespaceDeclaration: 'namespace' Identifier;
namespaceDeclaration: 'Namespace' Identifier;
namespace: namespaceDeclaration NL* '{' NL* (contentBlocks NL*)* NL* '}';

contentBlocks: surfaceBlock | noiseBlock;
contentBlocks: surfaceBlock | noiseBlock | densityFnBlock;
7 changes: 4 additions & 3 deletions grammar/Noise.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ noiseBlock: 'Noise' NL* '{' NL* (noiseDeclaration NL*)* NL* '}';

noiseDeclaration: Identifier '=' noise;

noise: 'Noise' '(' NL* Int NL* ')' NL* (noise_Builder NL*)*;
noise: 'Noise' noiseDefinition;

noise_Builder: noise_Builder_Amplitudes;
noise_Builder_Amplitudes: '.Amplitudes' '(' (number ',')* number ')';
noiseDefinition: '(' NL* Int NL* ')' NL* (noise_Builder NL*)*;

noise_Builder: builder_Amplitudes;
27 changes: 9 additions & 18 deletions grammar/Surface.g4
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ surfaceStatement: verticalAnchorDeclaration | surfaceConditionDeclaration | surf
verticalAnchor: ('~'? Int) | Identifier;
verticalAnchorDeclaration: Identifier '=' NL* verticalAnchor;

sharedBuilder_Offset: '.Offset(' Int ')';
sharedBuilder_Add:'.Add()';
sharedBuilder_Mul: '.Mul(' number ')';
sharedBuilder_MulInt: '.Mul(' Int ')';

surfaceCondition:
(
surfaceCondition_Not
Expand Down Expand Up @@ -47,9 +42,7 @@ surfaceCondition_Freezing: 'Freezing' '(' ')';


// These are split out to make them easier to differentiate in the go code
surfaceCondition_NoiseThresholdBuilder_Min: '.Min(' number ')';
surfaceCondition_NoiseThresholdBuilder_Max: '.Max(' number ')';
surfaceCondition_NoiseThresholdBuilder: surfaceCondition_NoiseThresholdBuilder_Max | surfaceCondition_NoiseThresholdBuilder_Min;
surfaceCondition_NoiseThresholdBuilder: builder_Max | builder_Min;
surfaceCondition_NoiseThreshold: 'NoiseThreshold' '(' resourceReference ')' NL* (surfaceCondition_NoiseThresholdBuilder NL*)*;

StoneDepthMode: 'Floor' | 'Ceiling';
Expand All @@ -58,31 +51,29 @@ surfaceCondition_StoneDepth:
(surfaceCondition_StoneDepthBuilder NL*)*;

surfaceCondition_StoneDepthBuilder:
sharedBuilder_Offset
| sharedBuilder_Add
builder_Offset
| builder_Add
| surfaceCondition_StoneDepthBuilder_SecondaryDepthRange
;

surfaceCondition_StoneDepthBuilder_SecondaryDepthRange:'.SecondaryDepthRange(' Int ')';

surfaceCondition_VerticalGradient: 'VerticalGradient' '(' String ')' NL* (surfaceCondition_VerticalGradientBuilder NL*)*;
surfaceCondition_VerticalGradientBuilder:
surfaceCondition_VerticalGradientBuilder_Top
| surfaceCondition_VerticalGradientBuilder_Bottom
builder_Top
| builder_Bottom
;

surfaceCondition_VerticalGradientBuilder_Top: '.Top' '(' verticalAnchor ')';
surfaceCondition_VerticalGradientBuilder_Bottom: '.Bottom' '(' verticalAnchor ')';


surfaceCondition_AboveWater: 'AboveWater' '(' ')' NL* (surfaceCondition_AboveWaterBuilder NL*)*;
surfaceCondition_AboveWaterBuilder:
sharedBuilder_Offset
| sharedBuilder_Add
| sharedBuilder_Mul;
builder_Offset
| builder_Add
| builder_Mul;

surfaceCondition_YAbove: 'YAbove' '(' verticalAnchor ')' NL* (surfaceCondition_YAboveBuilder NL*)* ;
surfaceCondition_YAboveBuilder: sharedBuilder_MulInt | sharedBuilder_Add;
surfaceCondition_YAboveBuilder: builder_MulInt | builder_Add;

surfaceRuleDeclaration: Identifier '=' NL* surfaceRule;
surfaceRule: surfaceRule_Block
Expand Down
5 changes: 4 additions & 1 deletion lang/File.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lang

import (
"github.com/minecraftmetascript/mms/lang/grammar"
"github.com/minecraftmetascript/mms/lang/traversal"
)

Expand All @@ -9,6 +10,7 @@ type File struct {
Path string
Project *Project
Diagnostics []traversal.Diagnostic
Script *grammar.ScriptContext
}

func (f *File) Parse() error {
Expand All @@ -18,10 +20,11 @@ func (f *File) Parse() error {
return err
}
parser := traversal.NewParser(f.Content, f.Path, f.Project.GlobalScope, &f.Diagnostics)
err = parser.Parse()
script, err := parser.Parse()
if err != nil {
return err
}
f.Script = script

return nil
}
1 change: 1 addition & 0 deletions lang/Project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)
import _ "github.com/minecraftmetascript/mms/lang/constructs/worldgen/surface_rules"
import _ "github.com/minecraftmetascript/mms/lang/constructs/worldgen/noise"
import _ "github.com/minecraftmetascript/mms/lang/constructs/worldgen/density_functions"

type Project struct {
Files map[string]*File
Expand Down
1 change: 1 addition & 0 deletions lang/builder_chain/BuilderChain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Invoke[Target any](bc *BuilderChain[Target], ctx antlr.ParserRuleContext, t
ctxType = ctxType.Elem()
}

fmt.Println(ctxType.Name())
fn, ok := bc.fns[ctxType]
if !ok {
return false
Expand Down
Loading