diff --git a/src/Language.ml b/src/Language.ml index 8472464de..0488f8672 100644 --- a/src/Language.ml +++ b/src/Language.ml @@ -641,15 +641,26 @@ module Expr = primary[def][infix][atr]: s:(s:"-"? {match s with None -> fun x -> x | _ -> fun x -> Binop ("-", Const 0, x)}) - b:base[def][infix][Val] is:( "[" i:parse[def][infix][Val] "]" {`Elem i} - | -"." (%"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} - )+ + b:base[def][infix][Val] is:( "." f:LIDENT args:(-"(" !(Util.list)[parse def infix Val] -")")? {`Post (f, args)} + | "." %"length" {`Len} + | "." %"string" {`Str} + | "[" i:parse[def][infix][Val] "]" {`Elem i} + | "(" args:!(Util.list0)[parse def infix Val] ")" {`Call args} + )+ => {match (List.hd (List.rev is)), atr with | `Elem i, Reff -> true | _, Reff -> false | _, _ -> true} => - { + { + let is = + let rec fix_is = function + | [ ] -> [] + | [x] -> [x] + | `Post (f, None) :: `Call args :: tl when args != [] -> `Post (f, Some args) :: fix_is tl + | x :: tl -> x :: fix_is tl + in + fix_is is + in let lastElem = List.hd (List.rev is) in let is = List.rev (List.tl (List.rev is)) in let b = diff --git a/stdlib/Collection.expr b/stdlib/Collection.expr index ddfbf176f..38e6de5fb 100644 --- a/stdlib/Collection.expr +++ b/stdlib/Collection.expr @@ -59,7 +59,7 @@ fun insert (m, k, v) { esac } - return inner (m, k, v).snd + return m.inner (k, v).snd } fun find (m, k) { @@ -110,15 +110,32 @@ fun validate (t) { fi esac } - + inner (t, fun (x) {return true}) } local tree = {}, i; -for i := 1, i <= 100, i := i+1 do +for i := 100, i >= 1, i := i-1 do validate (tree); tree := insert (tree, i, i); printf ("Inserting: %s\n", i.string); printf ("Result : %s\n", tree.string) -od \ No newline at end of file +od; + +tree := {}; + +for i := 1, i <= 100, i := i+2 do + validate (tree); + tree := insert (tree, i, i); + printf ("Inserting: %s\n", i.string); + printf ("Result : %s\n", tree.string) +od; + +for i := 2, i <= 100, i := i+2 do + validate (tree); + tree := insert (tree, i, i); + printf ("Inserting: %s\n", i.string); + printf ("Result : %s\n", tree.string) +od +