View previous topic :: View next topic |
Author |
Message |
pragma
Joined: 28 May 2004 Posts: 607 Location: Washington, DC
|
Posted: Wed Jun 14, 2006 9:46 am Post subject: |
|
|
rko wrote: | nonsense i meant
ident ::= {'_'}('A'..'Z','a'..'z') {('A'..'Z','a'..'z','0'..'9')}255; |
I plan on doing value ranges and iteration limits at some point in the future. I'll take your syntax examples under advisement - I might do something different though.
For now, you might want to provide those kinds of expressions as hard-coded parse functions similar to what I provided in BaseParser.d. In practice I've come to understand that range-based terminals are difficult to do optimally via a code generator - as such rules are so simple, manually coding them in is almost always the most efficent approach.
Also, you can use regular expressions too by delimiting your expression using the back-tick (`).
Quote: | is there any way to sync to some rule or rulepart on error? |
No. Enki's error reporting leaves much to be desired. I'm open to suggestions on how to improve it though. Any thoughts? _________________ -- !Eric.t.Anderton at gmail |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Wed Jun 14, 2006 2:35 pm Post subject: |
|
|
Doesn't Enki support using regexp in a rule? If you need ranges of that sort, you might try writing the 'ident' rule as a simple regexp instead, the entire result of which could then be stored in an annotation pretty easily, I'd imagine. Can't recall the syntax for regexp in Enki though... I think its wrapped in backquotes. So something like:
Code: |
ident = new Identifier(sym) ::= `^(_*[a-zA-Z][a-zA-Z0-9]*){0,255}`:sym ;
|
If it doesn't support this and I just saw it in a dream... then I dunno. ^__^
Keep in mind I'm no regexp wizard... so its surely far from perfect. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
pragma
Joined: 28 May 2004 Posts: 607 Location: Washington, DC
|
Posted: Wed Jun 14, 2006 4:12 pm Post subject: |
|
|
csauls wrote: | Doesn't Enki support using regexp in a rule? If you need ranges of that sort, you might try writing the 'ident' rule as a simple regexp instead, the entire result of which could then be stored in an annotation pretty easily, I'd imagine. Can't recall the syntax for regexp in Enki though... I think its wrapped in backquotes. So something like:
Code: |
ident = new Identifier(sym) ::= `^(_*[a-zA-Z][a-zA-Z0-9]*){0,255}`:sym ;
|
If it doesn't support this and I just saw it in a dream... then I dunno. ^__^
Keep in mind I'm no regexp wizard... so its surely far from perfect. |
It supports them alright!
Edit: I think the correct expression is actually `([_a-zA-Z]+[_a-zA-Z0-9]*)`, but I'm not sure how you would use regex to calculate the length of the span/length of the outermost expression. I don't think this is possible outside of a hand-coded approach, or on a semantic pass after parsing. However, I do want Enki to be able to handle binary files in the future, so having a way to do such things in the grammar will become important.
Granted, I'm not a regex wizard either - and Walter's implementation in D, whlie useful, is really *bad* for getting single conservative matches out of an input. I whittled it down to as few lines as possible, but its anything but succinct.
(Straight from BaseParser.d
Code: | public ResultString regexp(String str){
if (auto m = std.regexp.search(data[pos..$],str))
{
if(m.pre.length == 0){
auto result = m.match(0);
pos += result.length;
return ResultString(result);
}
}
return ResultString();
} |
One of these days I may have the courage to throw my/Don's template Regex at the problem, or even an Enki-generated regex engine - but not today. _________________ -- !Eric.t.Anderton at gmail |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Wed Jun 14, 2006 5:45 pm Post subject: |
|
|
Quote: | or even an Enki-generated regex engine |
Don't give me ideas! _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|