From: Phrogz Date: 2008-05-06T00:15:07+09:00 Subject: Re: How would you design regexps in the integer domain? On May 5, 2:24 am, Andreas Launila wrote: > I'm trying to come up with a clean way to specify regexps in the integer > domain. I.e. instead of describing a pattern of characters (as in normal > regexps) one describes patterns of integers ("17 followed by 3 or 15" > rather than "'a' followed by 'b' or 'c'"). You could specify it as a PEG[1], possibly using Treetop[2] in some way. The benefit of the PEG (re-usable sub-expressions) may not outweigh the multi-line nature. However, you could do something like LPEG[3] does. Instead of using standard PEG syntax come up with a custom syntax via operators that allows you to describe an entire grammar in a single Ruby expression. I'm personally not a fan of the syntax LPEG uses; you could come up with a better one, perhaps using terse method names instead of operators in some cases. (Perhaps "pattern.atleast(5)" instead of LPEG's "pattern^5".) [1] http://en.wikipedia.org/wiki/Parsing_expression_grammar [2] http://treetop.rubyforge.org/ [3] http://www.inf.puc-rio.br/~roberto/lpeg.html