-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
745 lines (731 loc) · 21.7 KB
/
main.go
File metadata and controls
745 lines (731 loc) · 21.7 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
//go:build !wasm && !js
package main
import (
"bufio"
"fmt"
"io/fs"
"math/rand"
"os"
"path/filepath"
"regexp"
"runtime"
"runtime/pprof"
"sort"
"strings"
"sync"
"time"
"github.com/Bedrock-OSS/go-burrito/burrito"
"github.com/MCDevKit/jsonte/jsonte"
"github.com/MCDevKit/jsonte/jsonte/functions"
"github.com/MCDevKit/jsonte/jsonte/json"
"github.com/MCDevKit/jsonte/jsonte/types"
"github.com/MCDevKit/jsonte/jsonte/utils"
"github.com/gammazero/deque"
"github.com/gobwas/glob"
"go.uber.org/multierr"
"go.uber.org/zap"
)
var (
commit string
version = "0.0.0"
date string
buildSource = "DEV"
)
func main() {
types.Init()
functions.Init()
env, b := os.LookupEnv("DEBUG")
isDebug := false
if b && (env == "true" || env == "1") {
isDebug = true
}
silent := false
removeSrc := false
minify := false
scope := make([]string, 0)
out := ""
include := make([]string, 0)
exclude := make([]string, 0)
ipcName := "jsonte"
seed := time.Now().UnixNano()
workers := int64(1)
cacheAll := false
cpuProfile := false
app := NewApp()
app.BoolFlag(Flag{
Name: "debug",
Usage: "Enable debug mode",
}, &isDebug)
app.BoolFlag(Flag{
Name: "safe-mode",
Usage: "Enable safe mode",
}, &functions.SafeMode)
app.BoolFlag(Flag{
Name: "server-mode",
Usage: "Enable server mode",
}, &functions.ServerMode)
app.BoolFlag(Flag{
Name: "silent",
Usage: "Enable silent mode",
}, &silent)
app.BoolFlag(Flag{
Name: "remove-src",
Usage: "Remove source files after compilation",
}, &removeSrc)
app.BoolFlag(Flag{
Name: "minify",
Usage: "Minify the output",
}, &minify)
app.StringSliceFlag(Flag{
Name: "scope",
Usage: "Scope of the output",
}, &scope)
app.StringFlag(Flag{
Name: "out",
Usage: "Output file",
}, &out)
app.StringSliceFlag(Flag{
Name: "include",
Usage: "Include files",
}, &include)
app.StringSliceFlag(Flag{
Name: "exclude",
Usage: "Exclude files",
}, &exclude)
app.StringFlag(Flag{
Name: "cache-dir",
Usage: "Directory for the cache",
}, &json.CacheDir)
app.StringFlag(Flag{
Name: "ipc-name",
Usage: "Name for the IPC named pipe",
}, &ipcName)
app.IntFlag(Flag{
Name: "seed",
Usage: "Seed for the random number generator",
}, &seed)
app.IntFlag(Flag{
Name: "workers",
Usage: "Maximum number of concurrent workers",
}, &workers)
app.BoolFlag(Flag{
Name: "cache-all",
Usage: "Cache all function calls",
}, &cacheAll)
app.BoolFlag(Flag{
Name: "cpu-profile",
Usage: "Creates a CPU profile file",
}, &cpuProfile)
app.Action(Action{
Name: "compile",
Function: func(args []string) error {
var cpuFile *os.File
if cpuProfile {
var err error
fullPath, err := filepath.Abs("./cpu.prof")
if err != nil {
return burrito.WrapError(err, "An error occurred while creating the CPU profile file path")
}
cpuFile, err = os.Create(fullPath)
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while creating the CPU profile file %s", fullPath)
}
if err := pprof.StartCPUProfile(cpuFile); err != nil {
return burrito.WrapErrorf(err, "An error occurred while starting the CPU profile")
}
defer func() {
pprof.StopCPUProfile()
_ = cpuFile.Close()
utils.Logger.Infof("CPU profile saved to %s", fullPath)
}()
}
functions.SetCacheAll(cacheAll)
outFile := ""
if out != "" {
stat, err := os.Stat(out)
if err != nil {
if os.IsNotExist(err) {
err := os.MkdirAll(out, 0755)
if err != nil {
return burrito.WrapError(err, "An error occurred while creating the output directory")
}
} else {
return burrito.WrapError(err, "An error occurred while reading the output file")
}
} else if !stat.IsDir() {
return burrito.WrappedErrorf("The output file '%s' is not a directory", out)
}
outFile, err = filepath.Abs(out)
}
object, err := getScope(scope, -1)
if err != nil {
return burrito.WrapError(err, "An error occurred while reading the scope")
}
fileSets, err := getFileList(args, include, exclude)
if err != nil {
return err
}
w := int(workers)
if w <= 0 {
w = runtime.NumCPU()
}
utils.Logger.Debugf("Using %d workers", w)
sem := make(chan struct{}, w)
var errMu, moduleMu sync.Mutex
var errs error
appendErr := func(e error) {
errMu.Lock()
defer errMu.Unlock()
errs = multierr.Append(errs, e)
}
modules := map[string]jsonte.JsonModule{}
var wg sync.WaitGroup
for base, files := range fileSets {
for _, file := range files {
if strings.HasSuffix(file, ".modl") {
wg.Add(1)
go func(base, file string) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
bytes, err := os.ReadFile(file)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while reading the module file %s", file))
return
}
module, err := jsonte.LoadModule(string(bytes), object, -1)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while loading the module file %s", file))
return
}
moduleMu.Lock()
modules[module.Name.StringValue()] = module
moduleMu.Unlock()
rel, err := filepath.Rel(base, file)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while relativizing the output file name"))
return
}
utils.Logger.Infof("Loaded module %s", rel)
if removeSrc {
if err := os.Remove(file); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while removing the module file %s", file))
}
}
}(base, file)
}
}
}
wg.Wait()
if errs != nil {
return errs
}
type templRes struct {
base string
file string
template utils.NavigableMap[string, types.JsonType]
}
templCh := make(chan templRes)
wg = sync.WaitGroup{}
for base, files := range fileSets {
for _, file := range files {
if strings.HasSuffix(file, ".templ") {
wg.Add(1)
go func(base, file string) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
utils.Logger.Infof("Templating file %s", file)
bytes, err := os.ReadFile(file)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while reading the template file %s", file))
return
}
template, err := jsonte.Process(strings.TrimSuffix(filepath.Base(file), filepath.Ext(file)), string(bytes), object, modules, -1)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while processing the template file %s", file))
return
}
templCh <- templRes{base: base, file: file, template: template}
if removeSrc {
if err := os.Remove(file); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while removing the template file %s", file))
}
}
}(base, file)
}
}
}
go func() {
wg.Wait()
close(templCh)
}()
templates := make([]templRes, 0)
for t := range templCh {
templates = append(templates, t)
}
sort.SliceStable(templates, func(i, j int) bool {
if templates[i].base == templates[j].base {
return templates[i].file < templates[j].file
}
return templates[i].base < templates[j].base
})
toString := types.ToPrettyString
if minify {
toString = types.ToString
}
for _, t := range templates {
for _, fileName := range t.template.Keys() {
content := t.template.Get(fileName)
filename := filepath.Dir(t.file) + "/" + fileName + ".json"
if outFile != "" {
var err error
filename, err = filepath.Rel(t.base, filename)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while creating the output file name"))
continue
}
filename = filepath.Join(outFile, t.base, filename)
rel, err := filepath.Rel(outFile, filename)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while relativizing the output file name"))
continue
}
utils.Logger.Infof("Writing file %s", filepath.Clean(rel))
} else {
utils.Logger.Infof("Writing file %s", filepath.Clean(filename))
}
if err := os.MkdirAll(filepath.Dir(filename), 0755); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while creating the output directory %s", filepath.Dir(filename)))
continue
}
if err := os.WriteFile(filename, []byte(toString(content)), 0644); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while writing the output file %s", filename))
}
}
}
if errs != nil {
return errs
}
type fnRes struct {
base string
file string
out string
data string
}
fnCh := make(chan fnRes)
wg = sync.WaitGroup{}
for base, files := range fileSets {
for _, file := range files {
if strings.HasSuffix(file, ".mcfunction") {
wg.Add(1)
go func(base, file string) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
bytes, err := os.ReadFile(file)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while reading the mcfunction file %s", file))
return
}
output, err := jsonte.ProcessMCFunction(string(bytes), object)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while processing the mcfunction file %s", file))
return
}
fileName := strings.TrimSuffix(filepath.Base(file), filepath.Ext(file))
filename := filepath.Dir(file) + "/" + fileName + ".mcfunction"
fnCh <- fnRes{base: base, file: filename, data: output}
if removeSrc {
if err := os.Remove(file); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while removing the mcfunction file %s", file))
}
}
}(base, file)
}
}
}
go func() {
wg.Wait()
close(fnCh)
}()
fnResults := make([]fnRes, 0)
for r := range fnCh {
fnResults = append(fnResults, r)
}
sort.SliceStable(fnResults, func(i, j int) bool {
if fnResults[i].base == fnResults[j].base {
return fnResults[i].file < fnResults[j].file
}
return fnResults[i].base < fnResults[j].base
})
for _, r := range fnResults {
filename := r.file
if outFile != "" {
var err error
filename, err = filepath.Rel(r.base, filename)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while creating the output file name"))
continue
}
filename = filepath.Join(outFile, r.base, filename)
rel, err := filepath.Rel(outFile, filename)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while relativizing the output file name"))
continue
}
utils.Logger.Infof("Writing file %s", filepath.Clean(rel))
} else {
utils.Logger.Infof("Writing file %s", filepath.Clean(filename))
}
if err := os.MkdirAll(filepath.Dir(filename), 0755); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while creating the output directory %s", filepath.Dir(filename)))
continue
}
if err := os.WriteFile(filename, []byte(r.data), 0644); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while writing the output file %s", filename))
}
}
if errs != nil {
return errs
}
type langRes struct {
base string
file string
data string
}
langCh := make(chan langRes)
wg = sync.WaitGroup{}
for base, files := range fileSets {
for _, file := range files {
if strings.HasSuffix(file, ".lang") {
wg.Add(1)
go func(base, file string) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
bytes, err := os.ReadFile(file)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while reading the mcfunction file %s", file))
return
}
output, err := jsonte.ProcessLangFile(string(bytes), object)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while processing the mcfunction file %s", file))
return
}
fileName := strings.TrimSuffix(filepath.Base(file), filepath.Ext(file))
filename := filepath.Dir(file) + "/" + fileName + ".lang"
langCh <- langRes{base: base, file: filename, data: output}
if removeSrc {
if err := os.Remove(file); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while removing the mcfunction file %s", file))
}
}
}(base, file)
}
}
}
go func() {
wg.Wait()
close(langCh)
}()
langResults := make([]langRes, 0)
for r := range langCh {
langResults = append(langResults, r)
}
sort.SliceStable(langResults, func(i, j int) bool {
if langResults[i].base == langResults[j].base {
return langResults[i].file < langResults[j].file
}
return langResults[i].base < langResults[j].base
})
for _, r := range langResults {
filename := r.file
if outFile != "" {
var err error
filename, err = filepath.Rel(r.base, filename)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while creating the output file name"))
continue
}
filename = filepath.Join(outFile, r.base, filename)
rel, err := filepath.Rel(outFile, filename)
if err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while relativizing the output file name"))
continue
}
utils.Logger.Infof("Writing file %s", filepath.Clean(rel))
} else {
utils.Logger.Infof("Writing file %s", filepath.Clean(filename))
}
if err := os.MkdirAll(filepath.Dir(filename), 0755); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while creating the output directory %s", filepath.Dir(filename)))
continue
}
if err := os.WriteFile(filename, []byte(r.data), 0644); err != nil {
appendErr(burrito.WrapErrorf(err, "An error occurred while writing the output file %s", filename))
}
}
if errs != nil {
return errs
}
return nil
},
})
app.Action(Action{
Name: "eval",
Usage: "Evaluate a JSON expression or run a REPL",
Function: func(args []string) error {
functions.SetCacheAll(cacheAll)
object, err := getScope(scope, -1)
if err != nil {
return burrito.WrapError(err, "An error occurred while reading the scope")
}
if len(args) == 0 {
repl(object)
} else {
expression := strings.Join(args, " ")
s := deque.Deque[*types.JsonObject]{}
s.PushBack(object)
value, err := jsonte.Eval(expression, s, "#")
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while evaluating the expression")
}
fmt.Println(types.ToPrettyString(value.Value))
}
return nil
},
})
app.Action(Action{
Name: "script",
Usage: "Evaluate a JSON expression or run a REPL",
Function: func(args []string) error {
functions.SetCacheAll(cacheAll)
object, err := getScope(scope, -1)
if err != nil {
return burrito.WrapError(err, "An error occurred while reading the scope")
}
if len(args) == 0 {
return burrito.WrapErrorf(err, "No script file specified")
} else {
file, err := os.ReadFile(args[0])
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while reading the script file")
}
file, err = json.ConvertToUTF8(file)
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while reading the script file")
}
s := deque.Deque[*types.JsonObject]{}
s.PushBack(object)
value, err := jsonte.EvalScript(string(file), s, "#")
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while running the script")
}
fmt.Println(types.ToPrettyString(value.Value))
}
return nil
},
})
app.Action(Action{
Name: "version",
Usage: "Print the version info",
Function: func(args []string) error {
fmt.Println("jsonte version " + version)
if buildSource == "DEV" {
fmt.Println("Development build")
}
if commit != "" {
fmt.Println("Commit: " + commit)
}
if date != "" {
fmt.Println("Built at " + date)
}
return nil
},
})
app.Action(Action{
Name: "ipc",
Usage: "Start an IPC server",
Function: func(args []string) error {
functions.SetCacheAll(cacheAll)
object, err := getScope(scope, -1)
if err != nil {
return burrito.WrapError(err, "An error occurred while reading the scope")
}
return StartIPC(ipcName, object)
},
})
app.Action(Action{
Name: "docgen",
Hidden: true,
Usage: "Generate documentation",
Function: func(args []string) error {
return functions.GenerateDocs()
},
})
err := app.Run(os.Args, func() {
if isDebug && silent {
utils.InitLogging(zap.DebugLevel)
utils.Logger.Warn("--debug and --silent are mutually exclusive")
} else if isDebug {
utils.InitLogging(zap.DebugLevel)
} else if silent {
utils.InitLogging(zap.WarnLevel)
} else {
utils.InitLogging(zap.InfoLevel)
}
rand.Seed(seed)
})
if err != nil {
if utils.Logger == nil {
utils.InitLogging(zap.DebugLevel)
}
utils.Logger.Error(err)
os.Exit(1)
}
}
func getScope(scope []string, timeout int64) (*types.JsonObject, error) {
assertionFiles := map[string]string{}
result := types.NewJsonObject()
for _, path := range scope {
if strings.HasPrefix(path, "{") {
json, err := types.ParseJsonObject([]byte(path))
if err != nil {
return types.NewJsonObject(), burrito.WrapErrorf(err, "An error occurred while parsing inline scope '%s'", path)
}
result = types.MergeObject(result, json, false, "#")
continue
}
err := utils.WalkDirFollowSymlinks(path, func(path string, d fs.DirEntry, err error) error {
if err != nil {
if os.IsNotExist(err) {
utils.Logger.Warnf("Skipping non-existent scope file '%s'", path)
return nil
}
return burrito.WrapErrorf(err, "An error occurred while reading the scope file '%s'", path)
}
if !d.IsDir() {
if strings.HasSuffix(path, ".json") {
file, err := os.ReadFile(path)
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while reading the scope file '%s'", path)
}
json, err := types.ParseJsonObject(file)
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while parsing the scope file '%s'", path)
}
err = jsonte.VerifyReservedNames(json, path+"#/")
result = types.MergeObject(result, json, false, "#")
} else if strings.HasSuffix(path, ".assert") {
file, err := os.ReadFile(path)
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while reading the assertion file '%s'", path)
}
assertionFiles[path] = string(file)
} else {
utils.Logger.Debugf("Skipping non-scope file '%s'", path)
}
}
return nil
})
if err != nil {
return types.NewJsonObject(), burrito.WrapError(err, "An error occurred while reading the scope files")
}
}
for path, file := range assertionFiles {
err := jsonte.ProcessAssertionsFile(path, file, result, timeout)
if err != nil {
return types.NewJsonObject(), burrito.PassError(err)
}
}
return result, nil
}
func getFileList(paths, include, exclude []string) (map[string][]string, error) {
result := map[string][]string{}
includes := make([]glob.Glob, 0)
excludes := make([]glob.Glob, 0)
pathRegex, err := regexp.Compile("[/\\\\]")
if err != nil {
// Should never happen as it's constant
return nil, burrito.WrapError(err, "An error occurred while compiling the path separator regex")
}
for _, i := range include {
g, err := glob.Compile(pathRegex.ReplaceAllString(i, "/"))
if err != nil {
return nil, burrito.WrapErrorf(err, "An error occurred while compiling the include pattern %s", i)
}
includes = append(includes, g)
}
for _, e := range exclude {
g, err := glob.Compile(pathRegex.ReplaceAllString(e, "/"))
if err != nil {
return nil, burrito.WrapErrorf(err, "An error occurred while compiling the exclude pattern %s", e)
}
excludes = append(excludes, g)
}
for _, p := range paths {
files := make([]string, 0)
_, err := os.Stat(p)
if err != nil {
if os.IsNotExist(err) {
return nil, burrito.WrappedErrorf("The path '%s' does not exist", p)
}
return nil, burrito.WrapErrorf(err, "An error occurred while reading the path %s", p)
}
err = utils.WalkDirFollowSymlinks(p, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return burrito.WrapErrorf(err, "An error occurred while reading the path %s", p)
}
if !d.IsDir() {
if !strings.HasSuffix(path, ".templ") && !strings.HasSuffix(path, ".modl") && !strings.HasSuffix(path, ".mcfunction") && !strings.HasSuffix(path, ".lang") {
return nil
}
for _, g := range includes {
if g.Match(pathRegex.ReplaceAllString(path, "/")) {
files = append(files, path)
return nil
}
}
for _, g := range excludes {
if g.Match(pathRegex.ReplaceAllString(path, "/")) {
return nil
}
}
if len(include) == 0 {
files = append(files, path)
}
}
return nil
})
if err != nil {
return nil, burrito.WrapErrorf(err, "An error occurred while reading input files from %s", p)
}
result[p] = files
}
return result, nil
}
func repl(scope *types.JsonObject) {
reader := bufio.NewReader(os.Stdin)
fmt.Print("> ")
s := deque.Deque[*types.JsonObject]{}
s.PushBack(scope)
for {
read, _ := reader.ReadString('\n')
text := strings.TrimRight(read, "\n\r")
if text == "exit" {
break
}
eval, err := jsonte.Eval(text, s, "#/")
if err != nil {
fmt.Println(err)
} else {
fmt.Println(types.ToString(eval.Value))
if !eval.VariableScope.IsEmpty() {
s.PushBack(eval.VariableScope)
}
}
fmt.Print("> ")
}
}