Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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)`
Expand Down
1 change: 1 addition & 0 deletions src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
3 changes: 2 additions & 1 deletion src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> DOT_NUM
%token<string> NAT
%token<string> FLOAT
%token<Value.unicode> CHAR
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAT was probably a bug, as we don't want .0x3 to be a projection, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

| e=exp_post s=DOT_NUM
{ ProjE (e, int_of_string s) @? at $sloc }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is motivated by how tests/run/tuples.as counts the projections from .0, which is consistent with list/array indexing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit undecided on this one, but seems fine for now.

| e=exp_post DOT x=id
{ DotE(e, dummy_obj_sort(), {x with it = Name x.it}) @? at $sloc }
Expand Down
29 changes: 29 additions & 0 deletions test/fail/issue36.as
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions test/fail/ok/issue36.wasm-run.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_out/issue36.wasm:0x___: runtime trap: unreachable executed
5 changes: 5 additions & 0 deletions test/fail/ok/issue36.wasm.stderr.ok
Original file line number Diff line number Diff line change
@@ -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)