Thanks, Gabriel!
I've followed your instructions (see both patches in attach, ready to
`hg import`). Test program seems to work with both of them. I'll test
your second approach more intensively soon.

Regards,
Sergey

2015-02-22 19:08 GMT+03:00 Gabriel Riba <[email protected]>:
> Gabriel Riba <griba2001 <at> gmail.com> writes:
>
>>
>> *** To the operators associativity commands, before (%left ANDALSO)
>>
>>   %left BACKTICK_PATH
>>
>
> Doubts about the precedence.
>
> Maybe we should place the precedence for BACKTICK_PATH, application and
> composition operators after the logical ones, after ORELSE or even after the
> following COLON (operator for signature annotation of expressions).
>
> The boss should decide it.
>
>
>
>
> _______________________________________________
> Ur mailing list
> [email protected]
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
# HG changeset patch
# User Sergey Mironov <[email protected]>
# Date 1424807992 0
#      Tue Feb 24 19:59:52 2015 +0000
# Node ID 3d8d385cb213692ae994c8dd67fd2dc83f84ebf3
# Parent  e3a79066380dab664965d9183c45a857c0b7823a
Add support for [a`func`b] infix notation

Original implementation was designed by Gabriel Riba

diff --git a/src/urweb.grm b/src/urweb.grm
--- a/src/urweb.grm
+++ b/src/urweb.grm
@@ -395,6 +395,7 @@
  | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
  | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
  | CIF | CTHEN | CELSE
+ | BACKTICK
 
 %nonterm
    file of decl list
@@ -1232,6 +1233,13 @@
                                                                ((CName "2", loc),
                                                                 eexp)], false), loc)), loc)
                                          end)
+	     | 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, eappsright))
+                                         end)
 
 bind   : eapps LARROW eapps             (patternOut eapps1, NONE, eapps2)
        | eapps                          (let
diff --git a/src/urweb.lex b/src/urweb.lex
--- a/src/urweb.lex
+++ b/src/urweb.lex
@@ -406,6 +406,7 @@
 <INITIAL> "/"         => (Tokens.DIVIDE (yypos, yypos + size yytext));
 <INITIAL> "%"         => (Tokens.MOD (pos yypos, pos yypos + size yytext));
 <INITIAL> "@"         => (Tokens.AT (pos yypos, pos yypos + size yytext));
+<INITIAL> "`"         => (Tokens.BACKTICK (pos yypos, pos yypos + size yytext));
 
 <INITIAL> "con"       => (Tokens.CON (pos yypos, pos yypos + size yytext));
 <INITIAL> "type"      => (Tokens.LTYPE (pos yypos, pos yypos + size yytext));
# HG changeset patch
# User Sergey Mironov <[email protected]>
# Date 1424811062 0
#      Tue Feb 24 20:51:02 2015 +0000
# Node ID 0171a7745c7cd640b9144d65a59e30d63cbe3a57
# Parent  e3a79066380dab664965d9183c45a857c0b7823a
Add support for [a`func`b] infix notation (Ver 2)

Designed by Gabriel Riba <[email protected]>

diff --git a/src/urweb.grm b/src/urweb.grm
--- a/src/urweb.grm
+++ b/src/urweb.grm
@@ -394,7 +394,7 @@
  | NE | LT | LE | GT | GE
  | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
  | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
- | CIF | CTHEN | CELSE
+ | CIF | CTHEN | CELSE | BACKTICK_PATH of string
 
 %nonterm
    file of decl list
@@ -554,6 +554,7 @@
 %nonassoc LARROW
 %nonassoc IF THEN ELSE
 %nonassoc DARROW
+%left BACKTICK_PATH
 %left ANDALSO
 %left ORELSE
 %nonassoc COLON
@@ -1201,6 +1202,16 @@
        | eexp LE eexp                   (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
        | eexp GT eexp                   (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
        | eexp GE eexp                   (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
+       | eexp BACKTICK_PATH eexp        (let
+                                         val path = String.tokens (fn ch => ch = #".") BACKTICK_PATH
+                                         val pathModules = List.take (path, (length path -1))
+                                         val pathOp = List.last path
+                                         val e = (EVar (pathModules, pathOp, Infer)
+                                                 , s (BACKTICK_PATHleft, BACKTICK_PATHright))
+                                         val e = (EApp (e, eexp1), s (eexp1left, BACKTICK_PATHright))
+                                         in
+                                            (EApp (e, eexp2), s (eexp1left, eexp2right))
+                                         end)
 
        | eexp ANDALSO eexp              (let
                                              val loc = s (eexp1left, eexp2right)
diff --git a/src/urweb.lex b/src/urweb.lex
--- a/src/urweb.lex
+++ b/src/urweb.lex
@@ -186,6 +186,7 @@
 xcom = ([^\-]|(-[^\-]))+;
 oint = [0-9][0-9][0-9];
 xint = x[0-9a-fA-F][0-9a-fA-F];
+backtick_path = `([A-Z][A-Za-z0-9_]*\.)*[a-z_][A-Za-z0-9_']*`;
 
 %%
 
@@ -542,7 +543,9 @@
                           | NONE   => (ErrorMsg.errorAt' (pos yypos, pos yypos)
                                        ("Expected float, received: " ^ yytext);
                                        continue ()));
-
+<INITIAL> {backtick_path}  => (Tokens.BACKTICK_PATH (
+                               substring (yytext, 1, size yytext -2),
+                               pos yypos, pos yypos + size yytext));
 <COMMENT> .           => (continue());
 
 <INITIAL> .           => (ErrorMsg.errorAt' (pos yypos, pos yypos)
_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to