1
- # Bootstrap of Extended Covariant Script Generator v1.4.3
1
+ # Bootstrap of Extended Covariant Script Generator v1.5.2
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ package ecs_bootstrap
23
23
import parsergen, ecs_parser, ecs_generator, codec, regex
24
24
import sdk_extension as sdk
25
25
26
- var wrapper_ver = "1.5.1 "
26
+ var wrapper_ver = "1.5.2 "
27
27
28
28
function show_version_simple()
29
29
@begin
@@ -36,61 +36,29 @@ function show_version_simple()
36
36
end
37
37
38
38
class repl_instance
39
- var syntax_stages = {"ignore", "nlook", "repeat", "optional", "cond_or"}.to_hash_set()
40
39
var codegen = new ecs_generator.generator
41
- var parser = new parsergen.repl_parser_type
40
+ var parser = new parsergen.partial_parser_type
42
41
var unicode_cvt = null
43
- var repl_impl = null
44
42
var code_buff = new array
45
- var stages = new array
43
+ var repl_impl = null
46
44
var silent = false
47
- function find_first_stage(parser)
48
- foreach it in parser.stack
49
- link name = it.product.root
50
- if !syntax_stages.exist(name)
51
- return name
52
- end
53
- end
54
- end
55
- function repl_hook(parser)
56
- if !parser.eof()
57
- return parsergen.parse_state.accept
58
- end
59
- if stages.size > 0
60
- var tokens = null
61
- loop
62
- tokens = this.readline()
63
- until tokens != null
64
- foreach it in tokens do parser.lex.push_back(it)
65
- end
66
- return parsergen.parse_state.accept
67
- end
68
45
function on_eof_hook(parser)
69
- stages.push_front(find_first_stage(parser))
70
46
var tokens = null
71
47
loop
72
- tokens = this.readline()
48
+ tokens = this.readline("..> " )
73
49
until tokens != null
74
50
foreach it in tokens do parser.lex.push_back(it)
75
51
return true
76
52
end
77
- function accept_hook(parser)
78
- if !stages.empty() && find_first_stage(parser) == stages.front
79
- stages.pop_front()
80
- end
81
- end
82
53
function initialize()
83
- ecs_parser.grammar.stx.stmts = ecs_parser.grammar.stx.stmts_repl
84
- ecs_parser.repl_hook = repl_hook
85
54
parser.on_eof_hook = on_eof_hook
86
- parser.accept_hook = accept_hook
55
+ codegen.code_buff := code_buff
87
56
codegen.file_name = "<REPL_ENV>"
88
57
codegen.minmal = true
89
58
end
90
- function readline()
59
+ function readline(prompt )
91
60
if !silent
92
- foreach i in range(stages.size*2) do system.out.print(".")
93
- system.out.print("> ")
61
+ system.out.print(prompt)
94
62
end
95
63
var line = repl_impl.readline()
96
64
code_buff.push_back(line)
@@ -106,10 +74,10 @@ class repl_instance
106
74
else
107
75
lexer = new parsergen.lexer_type
108
76
end
77
+ lexer.pos[1] = code_buff.size - 1
109
78
var tokens = lexer.run(ecs_parser.grammar.lex, line)
110
79
if !lexer.error_log.empty()
111
80
parsergen.print_error("<REPL_ENV>", code_buff, lexer.error_log)
112
- code_buff = new array
113
81
return new array
114
82
else
115
83
return tokens
@@ -128,12 +96,11 @@ class repl_instance
128
96
loop
129
97
var tokens = null
130
98
loop
131
- tokens = this.readline()
99
+ tokens = this.readline("> " )
132
100
until tokens != null
133
101
if parser.run(ecs_parser.grammar.stx, tokens)
134
102
var ast = parser.production()
135
103
if ast != null
136
- codegen.code_buff = code_buff
137
104
var code = codegen.repl_run(ast)
138
105
if code != null
139
106
code = code.split({'\n'})
@@ -145,17 +112,13 @@ class repl_instance
145
112
end
146
113
catch e
147
114
system.out.println(e.what)
148
- stages = new array
149
115
repl_impl.reset()
150
116
end
151
117
end
152
- code_buff = new array
153
118
end
154
119
else
155
120
var err = parser.get_log(0)
156
121
parsergen.print_error("<REPL_ENV>", {code_buff..., ""}, err)
157
- code_buff = new array
158
- stages = new array
159
122
repl_impl.reset()
160
123
end
161
124
end
0 commit comments