Skip to content

Commit f21eaee

Browse files
committed
feat: overhaul language
1 parent ecdc04b commit f21eaee

File tree

16 files changed

+808
-630
lines changed

16 files changed

+808
-630
lines changed

cmd/lint.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"io/fs"
8+
"log"
9+
"os"
10+
"strings"
11+
12+
"github.com/minecraftmetascript/mms/lang"
13+
"github.com/spf13/cobra"
14+
)
15+
16+
// lintCmd represents the lint command
17+
var lintCmd = &cobra.Command{
18+
Use: "lint {input} {output}",
19+
Short: "Lints your MMS Project",
20+
Long: ``,
21+
ValidArgs: []cobra.Completion{"Input"},
22+
Run: func(cmd *cobra.Command, args []string) {
23+
if len(args) < 1 {
24+
log.Println("Please provide an input file or directory")
25+
return
26+
}
27+
inFile := args[0]
28+
if strings.HasSuffix(inFile, "/") {
29+
inFile = strings.TrimSuffix(inFile, "/")
30+
}
31+
32+
project := lang.NewProject()
33+
34+
stat, err := fs.Stat(os.DirFS("."), inFile)
35+
36+
if err != nil {
37+
log.Println("Error building project.", err)
38+
return
39+
}
40+
if stat.IsDir() {
41+
log.Println("Project is a directory")
42+
} else {
43+
if content, err := os.ReadFile(inFile); err != nil {
44+
log.Println("Error building project:")
45+
} else {
46+
f := project.AddFile(inFile, string(content))
47+
f.Parse()
48+
}
49+
}
50+
51+
if len(project.Diagnostics()) > 0 {
52+
for _, diag := range project.Diagnostics() {
53+
log.Println(diag)
54+
}
55+
} else {
56+
log.Println("Project has no errors or warnings")
57+
}
58+
59+
},
60+
}
61+
62+
func init() {
63+
rootCmd.AddCommand(lintCmd)
64+
}
Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,73 @@
11
namespace MySpace {
2-
Surface {
3-
InBadlands = Biome(
4-
minecraft:badlands,
5-
minecraft:eroded_badlands,
6-
minecraft:wooded_badlands
7-
)
8-
SkyTerracotta = If (AboveSurface()) Block(minecraft:stone)
9-
NonHoleOrangeTerracotta = If(!Hole()) Block(minecraft:orange_terracotta)
10-
TerracottaBands = If(StoneDepth(Floor)) [
11-
If(
12-
Or(
13-
Noise(minecraft:surface).Min(-0.909).Max(-0.5454)
14-
Noise(minecraft:surface).Min(-0.1818).Max(0.1818)
15-
Noise(minecraft:surface).Min(0.5454).Max(0.909)
16-
)
17-
) Block(minecraft:terracotta)
18-
Bandlands()
19-
]
20-
WhiteTerracotta = If (AboveWater().Offset(-6).Mul(-1).Add())
21-
Block(minecraft:white_terracotta)
22-
23-
OrangeTerracotta = If (YAbove(63)) Block(minecraft:orange_terracotta)
24-
StoneAndGravel = [
25-
If (StoneDepth(Ceiling)) Block(minecraft:stone)
26-
Block(minecraft:gravel)
27-
]
28-
SurfaceSands = If (AboveWater().Offset(-1)) [
29-
If (StoneDepth(Ceiling)) Block(minecraft:red_sandstone)
30-
Block(minecraft:red_sand)
31-
]
32-
33-
OrangeTerracottaEdge = If(
34-
And(
35-
YAbove(63)
36-
!YAbove(74).Mul(1).Add()
37-
)
38-
) Block(minecraft:orange_terracotta)
39-
40-
Badlands = If(InBadlands) [
41-
If(YAbove(63)) [
42-
SkyTerracotta
43-
TerracottaBands
44-
SurfaceSands
45-
NonHoleOrangeTerracotta
46-
WhiteTerracotta
47-
StoneAndGravel
48-
]
49-
50-
If(YAbove(63).Mul(-1).Add()) [
51-
OrangeTerracottaEdge
52-
Bandlands()
53-
]
54-
55-
If (StoneDepth(Floor)) [
56-
WhiteTerracotta
57-
]
58-
]
59-
}
2+
Surface {
3+
InBadlands = Biome(
4+
minecraft:badlands,
5+
minecraft:eroded_badlands,
6+
minecraft:wooded_badlands
7+
)
608

9+
SkyTerracotta = If (AboveSurface()) Block(minecraft:stone)
10+
11+
NonHoleOrangeTerracotta = If (!Hole()) Block(minecraft:orange_terracotta)
12+
13+
TerracottaBands =
14+
If (StoneDepth(Floor)) [
15+
If (
16+
Or (
17+
Noise(minecraft:surface).Min(-0.909).Max(-0.5454)
18+
Noise(minecraft:surface).Min(-0.1818).Max(0.1818)
19+
Noise(minecraft:surface).Min(0.5454).Max(0.909)
20+
)
21+
) Block(minecraft:terracotta)
22+
Bandlands()
23+
]
24+
25+
WhiteTerracotta =
26+
If (AboveWater().Offset(-6).Mul(-1).Add())
27+
Block(minecraft:white_terracotta)
28+
29+
OrangeTerracotta =
30+
If (YAbove(63))
31+
Block(minecraft:orange_terracotta)
32+
33+
StoneAndGravel = [
34+
If (StoneDepth(Ceiling))
35+
Block(minecraft:stone)
36+
Block(minecraft:gravel)
37+
]
38+
39+
SurfaceSands =
40+
If (AboveWater().Offset(-1)) [
41+
If (StoneDepth(Ceiling))
42+
Block(minecraft:red_sandstone)
43+
Block(minecraft:red_sand)
44+
]
45+
46+
OrangeTerracottaEdge = If (
47+
And (
48+
YAbove(63)
49+
!YAbove(74).Mul(1).Add()
50+
)
51+
) Block(minecraft:orange_terracotta)
52+
53+
Badlands = If (InBadlands) [
54+
If (YAbove(63)) [
55+
SkyTerracotta
56+
TerracottaBands
57+
SurfaceSands
58+
NonHoleOrangeTerracotta
59+
WhiteTerracotta
60+
StoneAndGravel
61+
]
62+
63+
If (YAbove(63).Mul(-1).Add()) [
64+
OrangeTerracottaEdge
65+
Bandlands()
66+
]
67+
68+
If (StoneDepth(Floor)) [
69+
WhiteTerracotta
70+
]
71+
]
72+
}
6173
}

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
packages.default = pkgs.buildGoModule {
6868
pname = "mms";
69-
version = "0.2.6";
69+
version = "0.3.0";
7070
src = ./.;
7171
vendorHash = null;
7272
# If you use vendoring, run `go mod vendor` and replace null with the hash
@@ -79,7 +79,7 @@
7979

8080
packages.wasm = pkgs.stdenvNoCC.mkDerivation {
8181
pname = "mms-wasm";
82-
version = "0.2.6";
82+
version = "0.3.0";
8383
src = ./.;
8484
buildInputs = [ pkgs.go ];
8585
buildPhase = ''

grammar/Surface.g4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ surface: 'Surface' NL* '{' NL* (surfaceStatement NL*)* NL* '}';
55
surfaceStatement: verticalAnchorDeclaration | surfaceConditionDeclaration | surfaceRuleDeclaration;
66

77
verticalAnchor: ('~'? Int) | Identifier;
8-
verticalAnchorDeclaration: Identifier '=' verticalAnchor;
8+
verticalAnchorDeclaration: Identifier '=' NL* verticalAnchor;
99

1010
sharedBuilder_Offset: '.Offset(' Int ')';
1111
sharedBuilder_Add:'.Add()';
@@ -30,7 +30,7 @@ surfaceCondition:
3030
| surfaceCondition_VerticalGradient
3131
)
3232
;
33-
surfaceConditionDeclaration: Identifier '=' surfaceCondition;
33+
surfaceConditionDeclaration: Identifier '=' NL* surfaceCondition;
3434

3535
surfaceCondition_Not: '!' surfaceCondition;
3636
surfaceCondition_And: 'And' NL* '(' NL* (surfaceCondition NL*)* surfaceCondition NL* ')';
@@ -63,7 +63,7 @@ surfaceCondition_StoneDepthBuilder:
6363
| surfaceCondition_StoneDepthBuilder_SecondaryDepthRange
6464
;
6565

66-
surfaceCondition_StoneDepthBuilder_SecondaryDepthRange:'.secondaryDepthRange(' Int ')';
66+
surfaceCondition_StoneDepthBuilder_SecondaryDepthRange:'.SecondaryDepthRange(' Int ')';
6767

6868
surfaceCondition_VerticalGradient: 'VerticalGradient' '(' String ')' NL* (surfaceCondition_VerticalGradientBuilder NL*)*;
6969
surfaceCondition_VerticalGradientBuilder:
@@ -84,7 +84,7 @@ surfaceCondition_AboveWaterBuilder:
8484
surfaceCondition_YAbove: 'YAbove' '(' verticalAnchor ')' NL* (surfaceCondition_YAboveBuilder NL*)* ;
8585
surfaceCondition_YAboveBuilder: sharedBuilder_MulInt | sharedBuilder_Add;
8686

87-
surfaceRuleDeclaration: Identifier '=' surfaceRule;
87+
surfaceRuleDeclaration: Identifier '=' NL* surfaceRule;
8888
surfaceRule: surfaceRule_Block
8989
| surfaceRule_Sequence
9090
| surfaceRule_Reference

lang/constructs/worldgen/surface_rules/SurfaceConditions.go

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

33
import (
44
"encoding/json"
5-
"fmt"
65
"reflect"
76

87
"github.com/minecraftmetascript/mms/lang/grammar"
@@ -43,9 +42,8 @@ func init() {
4342
traversal.ConstructRegistry.Register(
4443
reflect.TypeFor[grammar.SurfaceConditionDeclarationContext](),
4544
func(ctx antlr.ParserRuleContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
46-
fmt.Println("Hi!")
4745
declarationContext := ctx.(*grammar.SurfaceConditionDeclarationContext)
48-
s := traversal.ProcessDeclaration(declarationContext, declarationContext.SurfaceCondition(), scope)
46+
s := traversal.ProcessDeclaration(declarationContext, declarationContext.SurfaceCondition(), scope, currentNamespace)
4947
return s.GetValue()
5048
})
5149
}
@@ -63,8 +61,3 @@ func exportSurfaceCondition(symbol traversal.Symbol, rootDir *lib.FileTreeLike,
6361

6462
return nil
6563
}
66-
67-
type BaseSurfaceCondition struct {
68-
traversal.Construct
69-
Negate bool
70-
}

lang/constructs/worldgen/surface_rules/SurfaceRules.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package surface_rules
33
import (
44
"encoding/json"
55
"errors"
6-
"fmt"
7-
86
"reflect"
97

108
"github.com/minecraftmetascript/mms/lang/grammar"
@@ -37,9 +35,8 @@ func init() {
3735
traversal.ConstructRegistry.Register(
3836
reflect.TypeFor[grammar.SurfaceRuleDeclarationContext](),
3937
func(ctx antlr.ParserRuleContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
40-
fmt.Println("Hi!")
4138
declarationContext := ctx.(*grammar.SurfaceRuleDeclarationContext)
42-
s := traversal.ProcessDeclaration(declarationContext, declarationContext.SurfaceRule(), scope)
39+
s := traversal.ProcessDeclaration(declarationContext, declarationContext.SurfaceRule(), scope, currentNamespace)
4340
return s.GetValue()
4441
})
4542
}

lang/grammar/MinecraftMetascript.interp

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

lang/grammar/MinecraftMetascript.tokens

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ LineComment=45
6767
'.Max('=22
6868
'Noise'=23
6969
'StoneDepth('=24
70-
'.secondaryDepthRange('=25
70+
'.SecondaryDepthRange('=25
7171
'VerticalGradient'=26
7272
'.Top'=27
7373
'.Bottom'=28

0 commit comments

Comments
 (0)