-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrayon.go
60 lines (53 loc) · 1.47 KB
/
crayon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"os"
engine "github.com/NekoMaru76/Crayon/engine"
parser "github.com/NekoMaru76/Crayon/parser/grammars"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
)
func main() {
input, _ := antlr.NewFileStream(os.Args[1])
lexer := parser.NewCrayonLexer(input)
stream := antlr.NewCommonTokenStream(lexer, 0)
p := parser.NewCrayonParser(stream)
p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))
p.BuildParseTrees = true
ch := make(chan interface{})
eng := engine.NewEngine(ch)
eng.AddCommands(
engine.WriteCommand,
engine.ByeCommand,
engine.DefineVariableCommand,
engine.AssignVariableCommand,
engine.GlobalVariableCommand,
engine.DeleteVariableCommand,
engine.IfCommand,
engine.IsEqualCommand,
engine.IsNotEqualCommand,
engine.NotCommand,
engine.AndCommand,
engine.OrCommand,
engine.IsLessThanCommand,
engine.IsLessThanOrEqualCommand,
engine.IsMoreThanCommand,
engine.IsMoreThanOrEqualCommand,
engine.SubCommand,
engine.SumCommand,
engine.DivideCommand,
engine.MultiplyCommand,
engine.CallCustomTagCommand,
engine.GetPropCommand,
engine.SetPropCommand,
engine.GetTypeofCommand,
engine.RunScopeCommand,
)
script := p.Script().(*parser.ScriptContext)
parentScope := engine.NewScope(nil)
v := engine.NewCrayonVisitor(eng, engine.NewScope(parentScope), make(map[string]*engine.CustomTag))
tags := v.VisitScript(script)
v.RunAllAvailableTags(tags, make([][]any, len(tags)))
defer func() {
for range ch {
}
}()
}