My Fellow Monks,

I am attempting to create a mini-language to allow users to set when certain events are marked on a calendar. (This is primarally used for repeated events... eg every thursday kinda things). I have come up with the base concept for what I want the language to look like, but I'm having difficulty coming up with something and then parsing it.

Samples:

I'm attempting to parse this with Parse::RecDescent, and I think I'm on the right track, but it's behaving funny (or I don't know how to use it properly.)

The following is my test code (variable grammar is incomplete, everything is compared to 'h'):

use Parse::RecDescent; use strict; use warnings; my $grammar = qq~ RecTest: ExpSet(s) ( Expression | SubExp ) | Expression | SubExp | <error> Expression: ELEMENT COMPARE ELEMENT ExpSet: ( Expression | SubExp ) JOIN SubExp: '(' (ExpSet(s) Expression | Expression) ')' ELEMENT: 'h' COMPARE: /(?:=(?![><]=))?[><]=?/ | '!=' | '=' JOIN: /and/i | /or/i | /xor/i ~; my $parser = new Parse::RecDescent($grammar) or die; print $parser->RecTest('(h = h and h != h) and ((h > h or h < h') or d +ie;

When I run this, it prints out ')', which is not entirely useful but implies that it is succeeding, I think... The problem is, it should NOT be succeeding with those arguments because the parentheses are unbalanced, so I assume I made some mistake, but I don't really understand the syntax well enough to know where. Also, I'm having a hard time figuring out how to do anything with what it attempts to parse (so I can actually evaluate what they want and determine if it occurs on any given day).

Perhaps I'm going about this wrong, if so, I'm open to other ideas. Thanks for any help or advice you can give.

Note: This is my first time even seriously looking at Parse::RecDescent.



My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)


In reply to Parse::RecDescent and mini-language parsing by Flame

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.