UU-ComputerScience / uuagc

3 stars 9 forks source link

Parse infix constructors #16

Open noughtmare opened 1 month ago

noughtmare commented 1 month ago

I've implemented a level oriented breadth first renumbering algorithm, but I didn't like how I had to write the semantic rules for Leaf:

sem Bin
  | Leaf lhs.res = { Leaf @x }
         (loc.x, lhs.xss) = { let ((x:xs):xss) = @lhs.xss in (x, (x+1:xs):xss) }

I would like to write this instead:

sem Bin
  | Leaf lhs.res = { Leaf @x }
         loc.((x : xs) : xss) = @lhs.xss
         lhs.xss = ((@x+1) : @xs) : @xss

But UUAGC doesn't parse infix constructors yet:

Main.ag:23:18: error: parser expecting symbol ) or @ or (symbol , ...)*
pattern  : 
help     : 
action   : deleting: symbol : at line 23, column 18 of file "Main.ag"
noughtmare commented 1 month ago

It's a bit annoying that : is a reserved keyword, but I guess we can work around it. I now have a working prototype. This now compiles properly for me:

sem Bin
  | Leaf loc.((x:xs):xss) = @lhs.xss
         lhs.res = Leaf @x
         lhs.xss = (@x + 1 : @xs) : @xss
  | Bin loc.(xs : xss') = @lhs.xss
        l.xss = @xss'
        +xss = (@xs :)
        lhs.res = Bin @l.res @r.res