Hacker News new | ask | show | jobs
by draegtun 4141 days ago
Thought this might be of interest; below shows how the examples provided would look in Rebol:

    digits: digit: charset "0123456789"

    rule: [
        thru "$"
        some digits
        "."
        digit
        digit
    ]

    parse "$10.00" rule    ;; true


    pattern: [
        some "p"
        2 "q" any "q"
    ]

    new-rule: [
        2 pattern
    ]

    parse "pqqpqq" new-rule    ;; true
Rebol doesn't have regular expressions instead it comes with a parse dialect which is a TDPL - http://en.wikipedia.org/wiki/Top-down_parsing_language

Some parse refs: http://en.wikibooks.org/wiki/REBOL_Programming/Language_Feat... | http://www.rebol.net/wiki/Parse_Project | http://www.rebol.com/r3/docs/concepts/parsing-summary.html

3 comments

hey thanks to share!

TIL

    Although Rebol can be used for programming, 
    writing functions, and performing processes, 
    its greatest strength is the ability to 
    easily create domain-specific languages or 
    dialects.
        — Carl Sassenrath [Rebol author]
https://en.wikipedia.org/wiki/Rebol
Mathematica also has its own string pattern sytax

http://reference.wolfram.com/language/ref/StringExpression.h...

Something like that would be

    StringExpression[
        "$",
        Repeated[DigitCharacter],
        ".",
        DigitCharacter,
        DigitCharacter
    ]
or

    StringExpression[
        "$",
        Repeated[DigitCharacter],
        ".",
        Repeated[DigitCharacter, {2}],
    ]
or

    StringExpression[
        "$",
        NumberString
    ]
and the other is

    StringExpression[
        Repeated[
           StringExpression[
               Repeated["p", {1, Infinity}],
               Repeated["q", {2, Infinity}]
           ],
           {2}
        ]
    ]
This can be made more concise since StringExpression has an infix form (~~) and Repeated can sometimes be replaced by postfix ..
> Repeated can sometimes be replaced by postfix ..

Always, not sometimes. ;-)

Perl 6 unifies "regexes" and recursive descent parsing:

  '$10.00' ~~ rx{ \$ \d+ \. \d\d };

  my $pat = rx{ \p+ \q**2..Inf }; 'pqqpqq' ~~ rx{ <$pat>**2 } 
Note that these "regexes" are syntax, not strings, checked and converted in to a hybrid DFA/NFA at compile-time.