Skip to content

Commit b0ead98

Browse files
committed
0.2.0
1 parent c30599b commit b0ead98

Some content is hidden

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

51 files changed

+1524
-1440
lines changed

.idea/mms.iml

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

cmd/build.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/minecraftmetascript/mms/lang"
76
"io/fs"
87
"log"
98
"os"
109

10+
"github.com/minecraftmetascript/mms/lang"
11+
1112
"github.com/spf13/cobra"
1213
)
1314

@@ -68,8 +69,8 @@ var buildCmd = &cobra.Command{
6869
)
6970
}
7071

71-
if len(project.Diagnostics) > 0 {
72-
for _, diag := range project.Diagnostics {
72+
if len(project.Diagnostics()) > 0 {
73+
for _, diag := range project.Diagnostics() {
7374
log.Println(diag)
7475
}
7576
}

examples/overworld-noise-settings/surface-rules/badlands.mms

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
namespace MySpace;
22

3-
InBadlands := SurfaceCondition { Biome [ minecraft:badlands minecraft:eroded_badlands minecraft:wooded_badlands ] }
3+
InBadlands := SurfaceCondition {
4+
Biome [
5+
minecraft:badlands
6+
minecraft:eroded_badlands
7+
minecraft:wooded_badlands
8+
]
9+
}
410

5-
SkyTerracotta := SurfaceRule { If (AboveSurface) Block stone }
11+
SkyTerracotta := SurfaceRule {
12+
If (AboveSurface) Block stone
13+
}
614

715
NonHoleOrangeTerracotta := SurfaceRule { If (!Hole) Block orange_terracotta }
816

@@ -11,7 +19,7 @@ TerracottaBands := SurfaceRule {
1119
Sequence [
1220
If (YAbove Absolute(74) 1 add)
1321
Sequence [
14-
If ( or (
22+
If (or (
1523
Noise minecraft:surface [-0.909, -0.5454]
1624
Noise minecraft:surface [-0.1818, 0.1818]
1725
Noise minecraft:surface [0.5454, 0.909]

grammar/Main_Lexer.g4

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Lang_Lexer;
44

55
Keyword_Namespace: 'namespace';
66

7+
Keyword_Anchor: 'Anchor';
78
Keyword_Absolute: 'Absolute';
89
Keyword_AboveBottom: 'AboveBottom';
910
Keyword_BelowTop: 'BelowTop';
@@ -15,28 +16,6 @@ Keyword_If: 'If';
1516
Keyword_Sequence: 'Sequence';
1617
Keyword_Bandlands: 'Bandlands';
1718

18-
19-
SurfaceRule_Head_Block: Keyword_SurfaceRule Dot Keyword_Block;
20-
SurfaceRule_Head_Bandlands: Keyword_SurfaceRule Dot Keyword_Bandlands;
21-
SurfaceRule_Head_Condition: Keyword_SurfaceRule Dot Keyword_If;
22-
SurfaceRule_Head_Sequence: Keyword_SurfaceRule Dot Keyword_Sequence;
23-
24-
SurfaceCondition_Head_AboveSurface: Keyword_SurfaceCondition Dot Keyword_AboveSurface;
25-
SurfaceCondition_Head_Biome: Keyword_SurfaceCondition Dot Keyword_Biome;
26-
SurfaceCondition_Head_Hole: Keyword_SurfaceCondition Dot Keyword_Hole;
27-
SurfaceCondition_Head_Noise: Keyword_SurfaceCondition Dot Keyword_Noise;
28-
SurfaceCondition_Head_Steep: Keyword_SurfaceCondition Dot Keyword_Steep;
29-
SurfaceCondition_Head_StoneDepth: Keyword_SurfaceCondition Dot Keyword_StoneDepth;
30-
SurfaceCondition_Head_Freezing: Keyword_SurfaceCondition Dot Keyword_Freezing;
31-
SurfaceCondition_Head_Temperature: Keyword_SurfaceCondition Dot Keyword_Temperature;
32-
SurfaceCondition_Head_VerticalGradient: Keyword_SurfaceCondition Dot Keyword_VerticalGradient;
33-
SurfaceCondition_Head_AboveWater: Keyword_SurfaceCondition Dot Keyword_AboveWater;
34-
SurfaceCondition_Head_YAbove: Keyword_SurfaceCondition Dot Keyword_YAbove;
35-
SurfaceCondition_Head_Floor: Keyword_SurfaceCondition Dot Keyword_Floor;
36-
SurfaceCondition_Head_Ceiling: Keyword_SurfaceCondition Dot Keyword_Ceiling;
37-
38-
39-
4019
Keyword_AboveSurface: 'AboveSurface';
4120
Keyword_Biome: 'Biome';
4221
Keyword_Hole: 'Hole';

grammar/SurfaceRules_Parser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ surfaceCondition_StoneDepth:
5656
surfaceCondition_Freezing: Keyword_Freezing;
5757

5858
surfaceCondition_VerticalGradient:
59-
Keyword_VerticalGradient String verticalAnchorDefinition Comma verticalAnchorDefinition;
59+
Keyword_VerticalGradient String verticalAnchor Comma verticalAnchor;
6060

6161
surfaceCondition_AboveWater:
6262
Keyword_AboveWater //
@@ -65,5 +65,5 @@ surfaceCondition_AboveWater:
6565
(Keyword_Add | Keyword_Sub);
6666

6767
surfaceCondition_YAbove:
68-
Keyword_YAbove verticalAnchorDefinition Int (Keyword_Add | Keyword_Sub);
68+
Keyword_YAbove verticalAnchor Int (Keyword_Add | Keyword_Sub);
6969

grammar/VerticalAnchor_Parser.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ options {
55
}
66
import Lang_Parser;
77

8-
verticalAnchorDefinition: verticalAnchor_Absolute | verticalAnchor_AboveBottom | verticalAnchor_BelowTop | verticalAnchor_Reference;
8+
verticalAnchorDefinition: Keyword_Anchor CurlyOpen verticalAnchor CurlyClose;
9+
verticalAnchor: verticalAnchor_Absolute | verticalAnchor_AboveBottom | verticalAnchor_BelowTop | verticalAnchor_Reference;
910
verticalAnchor_Absolute: Keyword_Absolute RoundOpen Int RoundClose;
1011
verticalAnchor_AboveBottom: Keyword_AboveBottom RoundOpen Int RoundClose;
1112
verticalAnchor_BelowTop: Keyword_BelowTop RoundOpen Int RoundClose;

lang/File.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ type File struct {
1111
Diagnostics []traversal.Diagnostic
1212
}
1313

14-
func (f *File) Parse() {
15-
parser := traversal.NewParser(f.Content, f.Project.GlobalScope, &f.Diagnostics)
16-
_ = parser.Parse()
17-
// Aggregate into project-level diagnostics if present
18-
if f.Project != nil {
19-
f.Project.Diagnostics = append(f.Project.Diagnostics, f.Diagnostics...)
14+
func (f *File) Parse() error {
15+
err := f.Project.GlobalScope.PurgeFile(f.Path)
16+
f.Diagnostics = make([]traversal.Diagnostic, 0)
17+
if err != nil {
18+
return err
2019
}
20+
parser := traversal.NewParser(f.Content, f.Path, f.Project.GlobalScope, &f.Diagnostics)
21+
err = parser.Parse()
22+
if err != nil {
23+
return err
24+
}
25+
26+
return nil
2127
}

lang/Project.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,33 @@ import _ "github.com/minecraftmetascript/mms/lang/constructs/worldgen/surface_ru
1111
type Project struct {
1212
Files map[string]*File
1313
GlobalScope *traversal.Scope
14-
Diagnostics []traversal.Diagnostic
14+
}
15+
16+
func (p *Project) Diagnostics() []traversal.Diagnostic {
17+
diagnostics := make([]traversal.Diagnostic, 0)
18+
for _, file := range p.Files {
19+
diagnostics = append(diagnostics, file.Diagnostics...)
20+
}
21+
return diagnostics
1522
}
1623

1724
func NewProject() *Project {
1825
return &Project{
1926
Files: make(map[string]*File),
2027
GlobalScope: traversal.NewScope(),
21-
Diagnostics: []traversal.Diagnostic{},
2228
}
2329
}
2430

2531
func (p *Project) AddFile(path, content string) *File {
26-
p.Files[path] = &File{
27-
Content: content,
28-
Path: path,
29-
Project: p,
32+
if p.Files[path] != nil {
33+
out := p.Files[path]
34+
out.Content = content
35+
} else {
36+
p.Files[path] = &File{
37+
Content: content,
38+
Path: path,
39+
Project: p,
40+
}
3041
}
3142
return p.Files[path]
3243
}

lang/constructs/block_states/BlockState.go

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

33
import (
44
"encoding/json"
5+
56
"github.com/minecraftmetascript/mms/lang/traversal"
67
)
78

lang/constructs/primitives/VerticalAnchor.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,40 @@ import (
1414

1515
func init() {
1616
traversal.ConstructRegistry.Register(
17-
reflect.TypeFor[*grammar.VerticalAnchorDefinitionContext](),
17+
reflect.TypeFor[*grammar.VerticalAnchorContext](),
1818
func(ctx antlr.ParserRuleContext, _ string, _ *traversal.Scope) traversal.Construct {
19-
anchor := ctx.(*grammar.VerticalAnchorDefinitionContext)
19+
anchor := ctx.(*grammar.VerticalAnchorContext)
2020

2121
if rule := anchor.VerticalAnchor_Absolute(); rule != nil {
22-
value, err := strconv.Atoi(rule.Int().GetText())
23-
24-
if err != nil {
25-
return nil
22+
var value int
23+
if i := rule.Int(); i != nil {
24+
if v, err := strconv.Atoi(i.GetText()); err == nil {
25+
value = v
26+
}
2627
}
27-
2828
return &VerticalAnchor{
2929
Type: VerticalAnchorType_Absolute,
3030
Value: value,
3131
}
3232
}
3333
if rule := anchor.VerticalAnchor_AboveBottom(); rule != nil {
34-
value, err := strconv.Atoi(rule.Int().GetText())
35-
fmt.Println("Found above bottom", value)
36-
if err != nil {
37-
return nil
34+
var value int
35+
if i := rule.Int(); i != nil {
36+
if v, err := strconv.Atoi(i.GetText()); err == nil {
37+
value = v
38+
}
3839
}
3940
return &VerticalAnchor{
4041
Type: VerticalAnchorType_AboveBottom,
4142
Value: value,
4243
}
4344
}
4445
if rule := anchor.VerticalAnchor_BelowTop(); rule != nil {
45-
value, err := strconv.Atoi(rule.Int().GetText())
46-
fmt.Println("Found below top", value)
47-
if err != nil {
48-
return nil
46+
var value int
47+
if i := rule.Int(); i != nil {
48+
if v, err := strconv.Atoi(i.GetText()); err == nil {
49+
value = v
50+
}
4951
}
5052
return &VerticalAnchor{
5153
Type: VerticalAnchorType_BelowTop,

0 commit comments

Comments
 (0)