adbrown85/edo — Issue #12: Create utility to make parsing easier
Author: adbrown85
Created: 2011-12-11 04:56:40+00:00
State: open

Rewriting the XML parser has been more troublesome than expected. It would be nice to have something like Java's _Scanner_ class that would parse based on patterns, i.e. regular expressions, and that could skip over delimiters automatically.

Obviously implementing a full regular expression library is completely outside of our scope, but restricting ourselves to a character set with a quantifier could prove very useful. Furthermore, if we design our pattern object carefully, we could make it extendable later on. In fact, if we let _Pattern_ do its own matching, a character set could even be determined functionally, e.g. by using the built-in functions like _isspace_ and _ispunct_, or even combinations of them and other techniques.

Here are a few mockups of the core classes:

Pattern
+ matches(istream&) : bool
+ match(istream&) : string

Scanner
+ Scanner(string&)
+ Scanner(Path&)
+ hasNext(Pattern*) : bool
+ next(Pattern*) : string
+ getDelimiter() : Pattern*
+ setDelimiter(Pattern*)

CharacterSet
+ contains(char) : bool

Quantifier
+ ONE
+ ONE_OR_MORE
+ ZERO_OR_ONE
+ ZERO_OR_MORE

It'd also be nice to have some convenience classes that contained commonly used character sets and patterns. They should use the create-on-first-use idiom to avoid the static initialization problem.

CharacterSets
+ alpha() : CharacterSet&
+ alphanumeric() : CharacterSet&
+ digit() : CharacterSet&
+ lower() : CharacterSet&
+ punct() : CharacterSet&
+ space() : CharacterSet&
+ upper() : CharacterSet&
+ word() : CharacterSet&

Pattern
+ punct(): Pattern&
+ whitespace() : Pattern&
+ word() : Pattern&