Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Grammars are invented in Perl6 just for that. Perl5 has module[0] for that implemented using recursive regex's.

Example of LaTeX parser:

    use Regexp::Grammars;
    $parser = qr{
        <File>
        <rule: File>       <[Element]>*
        <rule: Element>    <Command> | <Literal>
        <rule: Command>    \\  <Literal> <Options>? <Args>?
        <rule: Options>    \[  <[Option]>+ % (,)  \]
        <rule: Args>       \{  <[Element]>*  \}
        <rule: Option>     [^][\$&%#_{}~^\s,]+
        <rule: Literal>    [^][\$&%#_{}~^\s]+
    }xms
[0] http://search.cpan.org/~dconway/Regexp-Grammars-1.041/lib/Re...


Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: