Skip to content

Commit 95e2665

Browse files
committed
fix unicode support and import of repl
1 parent a0abde6 commit 95e2665

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

csbuild/ecs_bootstrap.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"Name": "ecs_bootstrap",
44
"Info": "Extended CovScript(ECS Lang) Bootstrap",
55
"Author": "Michael Lee",
6-
"Version": "1.5.3",
6+
"Version": "1.5.4",
77
"Target": "imports/ecs_bootstrap.csp",
88
"Dependencies": [
99
"parsergen",
1010
"ecs_parser",
1111
"ecs_generator",
12+
"sdk_extension",
1213
"codec",
1314
"regex"
1415
]

csbuild/ecs_parser.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"Name": "ecs_parser",
44
"Info": "Extended CovScript(ECS Lang) Parser",
55
"Author": "Michael Lee",
6-
"Version": "1.2.8",
6+
"Version": "1.3.0",
77
"Target": "imports/ecs_parser.csp",
88
"Dependencies": [
99
"parsergen",

imports/ecs_bootstrap.csp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Bootstrap of Extended Covariant Script Generator v1.5.3
1+
# Bootstrap of Extended Covariant Script Generator v1.5.4
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ package ecs_bootstrap
2323
import parsergen, ecs_parser, ecs_generator, codec, regex
2424
import sdk_extension as sdk
2525

26-
var wrapper_ver = "1.5.3"
26+
var wrapper_ver = "1.5.4"
2727

2828
function show_version_simple()
2929
@begin
@@ -71,7 +71,6 @@ class repl_instance
7171
line += "\n"
7272
var lexer = null
7373
if unicode_cvt != null
74-
system.out.println("Unicode Enabled")
7574
lexer = new parsergen.unicode_lexer_type
7675
lexer.cvt = unicode_cvt
7776
else
@@ -165,8 +164,8 @@ function show_help()
165164
" -h Show help information\n" +
166165
" -v Show version infomation\n" +
167166
" -u <CHARSET> Set unicode charset\n" +
168-
" CHARSET = {\"UTF8\", \"GBK\"}\n" +
169-
" -i <PATH> Set import path\n"
167+
" CHARSET = {\"AUTO\", \"UTF8\", \"GBK\"}\n" +
168+
" -i <PATH> Append import path\n"
170169
)
171170
@end
172171
system.exit(0)
@@ -239,7 +238,10 @@ function process_args(cmd_args)
239238
system.out.println("Error: Option \"-u\" not completed. Usage: \"ecs -u <CHARSET>\"")
240239
system.exit(0)
241240
end
242-
unicode = cmd_args[++index]
241+
unicode = cmd_args[++index].toupper()
242+
if unicode == "AUTO"
243+
unicode = system.is_platform_windows()?"GBK":"UTF8"
244+
end
243245
end
244246
case "-i"
245247
if index == cmd_args.size - 1
@@ -319,14 +321,18 @@ function main(cmd_args)
319321
system.exit(0)
320322
end
321323
var cvt_name = unicode.toupper()
324+
if cvt_name == "AUTO"
325+
cvt_name = system.is_platform_windows()?"GBK":"UTF8"
326+
end
322327
if !codecvt_map.exist(cvt_name)
323328
system.out.println("Error: unknown unicode charset \"" + cvt_name + "\".")
324329
system.exit(0)
325330
end
326331
instance.unicode_cvt = codecvt_map.at(cvt_name)(unicode_ext)
327-
ecs_parser.grammar.lex = ecs_parser.get_lexical([](str)->unicode_ext.build_wregex(instance.unicode_cvt.local2wide(str)))
332+
ecs_parser.grammar.lex = ecs_parser.get_lexical([](str)->unicode_ext.build_wregex(instance.unicode_cvt.local2wide(str)), cvt_name)
328333
end
329334
if csx_path != null
335+
sdk.set_import_path(runtime.get_import_path() + system.path.delimiter + csx_path)
330336
instance.codegen.ecsx_path = csx_path.split({system.path.delimiter})
331337
end
332338
instance.run(args_arr...)
@@ -366,7 +372,7 @@ function main(cmd_args)
366372
system.exit(0)
367373
end
368374
parser.unicode_cvt = codecvt_map.at(cvt_name)(unicode_ext)
369-
ecs_parser.grammar.lex = ecs_parser.get_lexical([](str)->unicode_ext.build_wregex(parser.unicode_cvt.local2wide(str)))
375+
ecs_parser.grammar.lex = ecs_parser.get_lexical([](str)->unicode_ext.build_wregex(parser.unicode_cvt.local2wide(str)), cvt_name)
370376
end
371377
parser.add_grammar("ecs-lang", ecs_parser.grammar)
372378
parser.from_file(file_name)

imports/ecs_parser.csp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Covariant Script Parser Generator: Grammar of Extended CovScript(ECS Lang) v1.2.8
1+
# Covariant Script Parser Generator: Grammar of Extended CovScript(ECS Lang) v1.3.0
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -24,11 +24,19 @@ import parsergen, regex
2424

2525
constant syntax = parsergen.syntax
2626

27-
function get_lexical(reg_builder)
27+
@begin
28+
var id_lexcicals = {
29+
"ASCII" : "^[A-Za-z_]\\w*$",
30+
"UTF8" : "^[A-Za-z_\\u4E00-\\u9FA5\\u9FA6-\\u9FEF\\u3007](\\w|[\\u4E00-\\u9FA5\\u9FA6-\\u9FEF\\u3007])*$",
31+
"GBK" : "^[A-Za-z_\\uB0A1-\\uF7FE\\u8140-\\uA0FE\\uAA40-\\uFEA0\\uA996](\\w|[\\uB0A1-\\uF7FE\\u8140-\\uA0FE\\uAA40-\\uFEA0\\uA996])*$"
32+
}.to_hash_map()
33+
@end
34+
35+
function get_lexical(reg_builder, cvt_name)
2836
@begin
2937
return {
3038
"endl" : reg_builder("^\\n+$"),
31-
"id" : reg_builder("^[A-Za-z_]\\w*$"),
39+
"id" : reg_builder(id_lexcicals.at(cvt_name)),
3240
"num" : reg_builder("^[0-9]+\\.?([0-9]+)?$"),
3341
"str" : reg_builder("^(\"|\"([^\"]|\\\\\")*\"?)$"),
3442
"char" : reg_builder("^(\'|\'([^\']|\\\\(0|\\\\|\'|\"|\\w))\'?)$"),
@@ -345,5 +353,5 @@ var covscript_syntax = {
345353

346354
var grammar = new parsergen.grammar
347355
grammar.ext = ".*\\.(csp|csc|ecs|ecsx)"
348-
grammar.lex = get_lexical(regex.build)
356+
grammar.lex = get_lexical(regex.build, "ASCII")
349357
grammar.stx := covscript_syntax

0 commit comments

Comments
 (0)