diff --git a/README.md b/README.md index a13106b7fa2..4fc9be21bf6 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,9 @@ and open the path printed on the last line of that command. - `[T]` - `[var T]` +* Tuple types: heterogeneous aggregates of fixed size + - `(Bool, Float, Text)` + * Option types: ML/Haskell-style option/maybe type, other types do not include null! - `? T` @@ -231,6 +234,7 @@ and open the path printed on the last line of that command. - `[3, 4]` - `o.x` - `a[i]` + - `tuple.0` * Function calls, short-cut return - `f(x, y)` diff --git a/src/lexer.mll b/src/lexer.mll index 60d73a13047..b64030fe1a6 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -163,6 +163,7 @@ rule token mode = parse | "->" { ARROW } | "_" { UNDERSCORE } + | '.' (num as s) { DOT_NUM s } | nat as s { NAT s } | float as s { FLOAT s } | char as s { CHAR (char lexbuf s) } diff --git a/src/parser.mly b/src/parser.mly index 3d205e2c8c3..455ee25c18f 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -107,6 +107,7 @@ let share_expfield (ef : exp_field) = %token PLUSASSIGN MINUSASSIGN MULASSIGN DIVASSIGN MODASSIGN POWASSIGN CATASSIGN %token ANDASSIGN ORASSIGN XORASSIGN SHLASSIGN SHRASSIGN ROTLASSIGN ROTRASSIGN %token NULL +%token DOT_NUM %token NAT %token FLOAT %token CHAR @@ -348,7 +349,7 @@ exp_post : { ArrayE(m, es) @? at $sloc } | e1=exp_post LBRACKET e2=exp RBRACKET { IdxE(e1, e2) @? at $sloc } - | e=exp_post DOT s=NAT + | e=exp_post s=DOT_NUM { ProjE (e, int_of_string s) @? at $sloc } | e=exp_post DOT x=id { DotE(e, dummy_obj_sort(), {x with it = Name x.it}) @? at $sloc } diff --git a/test/fail/issue36.as b/test/fail/issue36.as new file mode 100644 index 00000000000..ffb96a4a4aa --- /dev/null +++ b/test/fail/issue36.as @@ -0,0 +1,29 @@ +// AST-36: foo.bar.1.zap won't parse + +type Z = { zap : Nat }; +type B = { bar : (Int, Z) }; + +let inner : Z = new { zap = 42 }; +let foo : B = new { bar = (25, inner) }; + +assert(foo.bar.0 == 25); + +assert(foo.bar.1.zap == 42); + +assert((0,((1,1,2), (3,5), 8), 12).1.1.1 == 5); + +// Slight imbalance: between DOT and ID we can have whitespace... + +assert(foo. bar .1 . zap == 42); + +// but not between DOT and NUM: + +// assert(foo.bar. 2.zap == 42) // Error + +// N.B.: We did not change the FLOAT syntax: + +let (f, g, h) : (Float, Float, Float) = (1., 1.7, 1.8e-4); + +// N.B. these fail in wasm (AST-40) + +let (k, l) : (Float, Float) = (0x644., 0x644.5P-1) \ No newline at end of file diff --git a/test/fail/ok/issue36.wasm-run.ok b/test/fail/ok/issue36.wasm-run.ok new file mode 100644 index 00000000000..1f1f72b3800 --- /dev/null +++ b/test/fail/ok/issue36.wasm-run.ok @@ -0,0 +1 @@ +_out/issue36.wasm:0x___: runtime trap: unreachable executed diff --git a/test/fail/ok/issue36.wasm.stderr.ok b/test/fail/ok/issue36.wasm.stderr.ok new file mode 100644 index 00000000000..06889a31a60 --- /dev/null +++ b/test/fail/ok/issue36.wasm.stderr.ok @@ -0,0 +1,5 @@ +compile_lit: (FloatLit 1.) +compile_lit: (FloatLit 1.7) +compile_lit: (FloatLit 0.000_18) +compile_lit: (FloatLit 1_604.) +compile_lit: (FloatLit 802.156_25)