Better dot notation

This commit is contained in:
Dmitry Boulytchev 2019-12-21 18:04:39 +03:00
parent b6daf3910f
commit 5258b95712

View file

@ -635,7 +635,7 @@ module Expr =
primary[def][infix][atr]:
b:base[def][infix][Val] is:( "[" i:parse[def][infix][Val] "]" {`Elem i}
| -"." (%"length" {`Len} | %"string" {`Str} | f:LIDENT {`Post f})
| -"." (%"length" {`Len} | %"string" {`Str} | f:LIDENT args:(-"(" !(Util.list)[parse def infix Val] -")")? {`Post (f, args)})
| "(" args:!(Util.list0)[parse def infix Val] ")" {`Call args}
)+
=> {match (List.hd (List.rev is)), atr with
@ -652,19 +652,19 @@ module Expr =
| `Elem i -> Elem (b, i)
| `Len -> Length b
| `Str -> StringVal b
| `Post f -> Call (Var f, [b])
| `Post (f, args) -> Call (Var f, b :: match args with None -> [] | Some args -> args)
| `Call args -> (match b with Sexp _ -> invalid_arg "retry!" | _ -> Call (b, args))
)
b
is
in
let res = match lastElem, atr with
| `Elem i, Reff -> ElemRef (b, i)
| `Elem i, _ -> Elem (b, i)
| `Len, _ -> Length b
| `Str, _ -> StringVal b
| `Post f, _ -> Call (Var f, [b])
| `Call args, _ -> (match b with Sexp _ -> invalid_arg "retry!" | _ -> Call (b, args))
| `Elem i , Reff -> ElemRef (b, i)
| `Elem i , _ -> Elem (b, i)
| `Len , _ -> Length b
| `Str , _ -> StringVal b
| `Post (f, args), _ -> Call (Var f, b :: match args with None -> [] | Some args -> args)
| `Call args , _ -> (match b with Sexp _ -> invalid_arg "retry!" | _ -> Call (b, args))
in
ignore atr res
}