[Ur] Functional infix operators ?

Gabriel Riba griba2001 at gmail.com
Sat Feb 21 11:25:43 EST 2015


Sergey Mironov <grrwlf <at> gmail.com> writes:

> 
> I'd be happy to have a feature of calling 2-arg function [func a b]
> using (a`func`b) infix notation. I suppose, adding this syntax would
> be easier than full-scale infix operators support suggested by Ziv,
> and could be a starter point for the larger-scale work.
> 

In urweb.lex add a backtick detector for the state INITIAL as

<INITIAL> "`" => (Tokens.BACKTICK (pos yypos, pos yypos + size yytext));

In urweb.grm 

* add BACKTICK to the list of terminals at the end of the list that starts
at %term

  | BACKTICK

* at the eexp production (eexp : ....) add the following case

       | eexp BACKTICK path BACKTICK eapps (let

                        val e = (EVar (#1 path, #2 path, Infer)
                                , s (pathleft, pathright))

                        val e = (EApp (e, eexp), s (eexpleft, pathright))
                      in
                        (EApp (e, eapps), s (eexpleft, etermright))
                      end)

  This admits a path name between backticks like `String.append` and applies
the operation to the left operand and then to the rest of operands on the
right. (The s parameter pair is the source location range to be signalled in
case of error)

(* --- *)

In case of multiple bacticked verbs it works left to right

val test = (1 `plus` 2 `times` 3) = (1 `plus` 2) `times` 3 






More information about the Ur mailing list