[erlang-questions] some language changes

andrew cooke andrew@REDACTED
Wed May 23 13:18:57 CEST 2007


any combinator library (not sure from the context if this is what you are
referring to or not - i would expect a regexp library to compile state
machines and so be more efficient than a typical combinator lib) should be
able to do this - here's the equivalent based on code at
https://acooke.dyndns.org:4443/repos/default/src/erlang/lib/trunk/

test_torbjorn() ->
    io:fwrite("torbjorn~n"),
    T = either(string("now"),
               all_([either(string("plus"), string("minus")),
                     all_([digit(), optional(digit())]),
                     ignore(string("hours"))])),
    assert_equals({ok, ["plus", "42"], ""}, T("plus42hours")),
    assert_equals({fail, equal}, T("plus100hours")).

i wouldn't suggest people use this code (i change it regularly and it has
no documentation!), but if this is unusual and useful i can make something
more "polished".

andrew

ps the "_" in "all_" implies string list contents are concatenated rather
than appended (so the "words" remain separate; digit() matches characters
not strings).

> Darius Bacon wrote:
>> ok <ok@REDACTED> wrote:
>>> So here's how I would like to write that:
>>>
>>>      X = seq(any(".?!"), span("\"')]}"),
>>>               alt("\n", "\t", seq(" ",any(" \t\n"))),
>>>               span(" \t\n"))
>>
>> I would, too -- the regexp code I posted the other day exported
>> constructor functions along these lines (even named seq and alt), with
>> the regexp syntax exiled to a separate parser module. It'd be nice if
>> the standard regexp module did this.
>>
>> Darius
>
> Very nice!
> However, it would be even nicer with some included examples on how to
> run the code... :-)
>
> Let's say I have the following regexp:
>
>  "^now/(plus|minus)(\d{1,2})hours/$"
>
> then:
>
>  In: "now/plus42hours/"
>  Out: ["plus, "42"]        (or something like that)
>
>  In: "now/plus100hours/"
>  Out: nomatch
>
> Can I do it with 'ergex' ?
> Can I do it with any other of the various regexp modules that are
> floating around ?
>
> Cheers, Tobbe
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>





More information about the erlang-questions mailing list