Skip to content

Commit 796e711

Browse files
committed
Hide feature behind flag, more testing
1 parent 2d466b1 commit 796e711

File tree

21 files changed

+88
-31
lines changed

21 files changed

+88
-31
lines changed

src/driver/Entry.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ let set_model_name model_name =
3131

3232
let reset_mutable_states model_name (flags : Flags.t) =
3333
Common.Gensym.reset_danger_use_cautiously ();
34+
Unicode.allow_unicode := flags.allow_unicode;
3435
Include_files.include_provider := flags.include_source;
3536
set_model_name model_name;
3637
Typechecker.check_that_all_functions_have_definition :=

src/driver/Flags.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type t =
77
; standalone_functions: bool
88
; use_opencl: bool
99
; include_source: Frontend.Include_files.t
10+
; allow_unicode: bool
1011
; info: bool
1112
; version: bool
1213
; auto_format: bool
@@ -49,6 +50,7 @@ let default =
4950
; standalone_functions= false
5051
; use_opencl= false
5152
; include_source= Frontend.Include_files.FileSystemPaths []
53+
; allow_unicode= false
5254
; info= false
5355
; version= false
5456
; auto_format= false

src/driver/Flags.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type t =
99
; standalone_functions: bool
1010
; use_opencl: bool
1111
; include_source: Frontend.Include_files.t
12+
; allow_unicode: bool
1213
(* ------------------------- *)
1314
(* flags which switch compiler "modes" *)
1415
; info: bool

src/frontend/Unicode.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
let allow_unicode = ref false
2+
13
let error ~loc msg =
24
raise
35
(Errors.SyntaxError
@@ -30,6 +32,10 @@ let validate_ascii_id ~loc id =
3032
https://www.unicode.org/reports/tr31 *)
3133

3234
let validate_utf8_id ~loc id =
35+
if not !allow_unicode then
36+
error ~loc
37+
"Unicode identifiers are not supported without the (experimental) \
38+
allow-unicode flag";
3339
if not (String.is_valid_utf_8 id) then
3440
error ~loc "Identifier is not valid UTF-8 string";
3541
Debugging.lexer_logger ("unicode id: " ^ id);

src/stanc/CLI.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ module Options = struct
3939
means the definition will be provided later as a C++ function." in
4040
Arg.(value & flag & info ["allow-undefined"] ~doc)
4141

42+
let allow_unicode =
43+
let doc =
44+
"$(i,(Experimental)) Allow unicode characters in the names of functions \
45+
and variables" in
46+
Arg.(value & flag & info ["allow-unicode"] ~doc)
47+
4248
let auto_format =
4349
let doc =
4450
"Output a formatted version of the Stan program. The output can be \
@@ -359,6 +365,7 @@ module Conversion = struct
359365
let open Options in
360366
let+ optimization_level = optimization_level
361367
and+ allow_undefined = allow_undefined
368+
and+ allow_unicode = allow_unicode
362369
and+ standalone_functions = standalone_functions
363370
and+ use_opencl = use_opencl
364371
and+ include_source = include_paths
@@ -374,6 +381,7 @@ module Conversion = struct
374381
Driver.Flags.
375382
{ optimization_level
376383
; allow_undefined
384+
; allow_unicode
377385
; functions_only= false
378386
; standalone_functions
379387
; use_opencl

src/stancjs/stancjs.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ let process_flags (flags : 'a Js.opt) includes : (Driver.Flags.t, string) result
140140
else if is_flag_set "Oexperimental" then Optimize.Oexperimental
141141
else Optimize.O0)
142142
; allow_undefined= is_flag_set "allow-undefined"
143+
; allow_unicode= is_flag_set "allow-unicode"
143144
; functions_only= is_flag_set "functions-only"
144145
; standalone_functions= is_flag_set "standalone-functions"
145146
; use_opencl= is_flag_set "use-opencl"

test/integration/bad/lang/stanc.expected

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -533,18 +533,6 @@ Semantic error in 'tparam_tuple_int.stan', line 2, column 2 to column 21:
533533
-------------------------------------------------
534534

535535
(Transformed) Parameters cannot be integers.
536-
[exit 1]
537-
$ ../../../../../install/default/bin/stanc unicode_normalization.stan
538-
Semantic error in 'unicode_normalization.stan', line 4, column 7 to column 13:
539-
-------------------------------------------------
540-
2: real ñabc;
541-
3: // this is a different encoding than above, should be prevented still!
542-
4: real ñabc;
543-
^
544-
5: }
545-
-------------------------------------------------
546-
547-
Identifier 'ñabc' is already in use.
548536
[exit 1]
549537
$ ../../../../../install/default/bin/stanc unterminated_comment.stan
550538
Syntax error in 'unterminated_comment.stan', line 4, column -1, lexing error:

test/integration/bad/new/stanc.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ Syntax error in 'lexing_error.stan', line 1, column 6, lexing error:
14501450
^
14511451
-------------------------------------------------
14521452

1453-
Invalid character: '1'
1453+
Unicode identifiers are not supported without the (experimental) allow-unicode flag
14541454
[exit 1]
14551455
$ ../../../../../install/default/bin/stanc location-scale-bad1.stan
14561456
Syntax error in 'location-scale-bad1.stan', line 1, column 27 to column 32, parsing error:

test/integration/bad/unicode/dune

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(rule
2+
(targets stanc.output)
3+
(deps
4+
(package stanc)
5+
(:stanfiles
6+
(glob_files *.stan)))
7+
(action
8+
(with-stdout-to
9+
%{targets}
10+
(run %{bin:run_bin_on_args} "%{bin:stanc} --allow-unicode" %{stanfiles}))))
11+
12+
(rule
13+
(alias runtest)
14+
(action
15+
(diff stanc.expected stanc.output)))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data {
2+
int �(;
3+
}

0 commit comments

Comments
 (0)