[Ur] Regular expressions DSEL?
Adam Chlipala
adamc at csail.mit.edu
Mon Feb 20 08:25:19 EST 2017
It's definitely not a crazy idea to connect to standard regexp
functionality, say PCRE on the server and built-in JavaScript stuff on
the client, via the FFI, with a richly typed interface. Let me know if
you have any specific questions on how to go about it. Ziv's type
signature examples should be helpful as a starting point.
On 02/20/2017 12:00 AM, Artyom Shalkhakov wrote:
> 2017-02-20 10:47 GMT+06:00 <fold at tuta.io <mailto:fold at tuta.io>>:
>
> Maybe just define another attribute in basis.urs?
>
> It would be much interesting to define a DSEL though. I have not
> seen any attempts to create a DSEL for regular expressions.
>
>
> Indeed! And it seems like it would be a nice exercise as well having
> some practical uses to it.
>
> I envision something along the lines of:
>
> datatype RegExp = ... (* constructors *)
>
> type t (* abstract, not exported outside the module *)
> val compile : RegExp -> t (* the trusted function *)
> val matches : string -> t -> bool (* check if passed-in string matches
> the expression *)
>
> And the implementation might use something unsafe (like a string, or
> an actual regexp object in JS). Then we could offload the
> interpretation of regexps to an off-the-shelf library. The [compile]
> function would print and escape the AST to a regexp string, and the
> Ur/Web compiler might actually optimize all of this away.
>
> If we are to take care of matching subgroups, that would require a
> more complicated type. I guess that should be doable as well, but I
> don't see immediately how to handle this.
>
>
>
> 20. Feb 2017 16:28 by artyom.shalkhakov at gmail.com
> <mailto:artyom.shalkhakov at gmail.com>:
>
>
> Hello all,
>
> 'm doing form validation stuff, following examples on MDN. [1]
>
> It seems like Ur/Web doesn't handle regular expressions?
>
> I guess it should not be too diffcult to define a DSEL in
> Ur/Web (just AST constructors and a few trusted functions:
> e.g. [compile : AST -> regexp], where [regexp] is an abstract
> type, or maybe just a string :-)) and have it work at least in
> the browser.
>
> Could somebody point me in the right direction here?
>
> --
> Cheers,
> Artyom Shalkhakov
>
> [1]
> https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation
> <https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation>
>
>
>
>
> --
> Cheers,
> Artyom Shalkhakov
>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20170220/010453b2/attachment-0001.html>
More information about the Ur
mailing list