Package easyIO
Class Regex
- java.lang.Object
-
- easyIO.Regex
-
public class Regex extends java.lang.Object
Regular expression support foreasyIO.Scanner
- See Also:
easyIO.Scanner
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
advanceToPattern(BacktrackScanner sc, Recognizer r)
Advance the scanner position to the point where the pattern recognized byr
is found, or all the way to the end of the input if it is not found.static Recognizer
alt(Recognizer a, Recognizer b)
Recognizes either a or b (regular expression a|b)static Recognizer
anyChar(java.lang.String c)
Recognizer that matches any single character in the stringc
static Recognizer
concat(Recognizer a, Recognizer b)
Recognizes a followed by b (regular expression ab)static Recognizer
constant(java.lang.String c)
Recognizes all of the characters in c, in sequence.static boolean
hasPattern(BacktrackScanner sc, Recognizer r)
Whether the next characters on the input can be matched by r.static Recognizer
notChar(java.lang.String c)
Recognizer that matches any single character not in the stringc
.static Recognizer
oneOrMore(Recognizer a)
Recognizes 1 or more instances of a (a+)static Recognizer
opt(Recognizer a)
Recognizes 0 or 1 instance of a (regular expression a?)static java.lang.String
parsePattern(BacktrackScanner sc, Recognizer r)
Match the input characters starting at the current position against the pattern r and return the characters matched.static java.lang.String
parseToDelimiter(BacktrackScanner sc, Recognizer delim)
Return all the characters from the current scanner position up to the first occurrence of the delimiter patterndelim
, leaving the scanner position either immediately after that delimiter pattern or at the end of the string if the delimiter pattern was never found.static java.lang.String
parseToPattern(BacktrackScanner sc, Recognizer r)
Return all the text between the current scanner position and the first occurrence of the pattern recognized by r.static Recognizer
repeat(Recognizer a)
Recognizes 0 or more instances of a (regular expression a*)static void
scanPattern(BacktrackScanner sc, Recognizer r)
Match the input characters starting at the current position against the pattern r and advance the scanner position beyond the matched characters.static Recognizer
whitespace()
Recognizer that matches a single whitespace character.
-
-
-
Method Detail
-
scanPattern
public static void scanPattern(BacktrackScanner sc, Recognizer r) throws UnexpectedInput
Match the input characters starting at the current position against the pattern r and advance the scanner position beyond the matched characters. ThrowUnexpectedInput
if there is no way to match the input characters against the pattern, and leave the scanner position unchanged.- Throws:
UnexpectedInput
-
parsePattern
public static java.lang.String parsePattern(BacktrackScanner sc, Recognizer r) throws UnexpectedInput
Match the input characters starting at the current position against the pattern r and return the characters matched. Throw UnexpectedInput if there is no way to match the input characters against the pattern, and leave the scanner position unchanged.- Throws:
UnexpectedInput
-
parseToDelimiter
public static java.lang.String parseToDelimiter(BacktrackScanner sc, Recognizer delim)
Return all the characters from the current scanner position up to the first occurrence of the delimiter patterndelim
, leaving the scanner position either immediately after that delimiter pattern or at the end of the string if the delimiter pattern was never found.
-
hasPattern
public static boolean hasPattern(BacktrackScanner sc, Recognizer r)
Whether the next characters on the input can be matched by r.
-
advanceToPattern
public static void advanceToPattern(BacktrackScanner sc, Recognizer r)
Advance the scanner position to the point where the pattern recognized byr
is found, or all the way to the end of the input if it is not found.
-
parseToPattern
public static java.lang.String parseToPattern(BacktrackScanner sc, Recognizer r)
Return all the text between the current scanner position and the first occurrence of the pattern recognized by r.
-
concat
public static Recognizer concat(Recognizer a, Recognizer b)
Recognizes a followed by b (regular expression ab)
-
alt
public static Recognizer alt(Recognizer a, Recognizer b)
Recognizes either a or b (regular expression a|b)
-
opt
public static Recognizer opt(Recognizer a)
Recognizes 0 or 1 instance of a (regular expression a?)
-
repeat
public static Recognizer repeat(Recognizer a)
Recognizes 0 or more instances of a (regular expression a*)
-
oneOrMore
public static Recognizer oneOrMore(Recognizer a)
Recognizes 1 or more instances of a (a+)
-
constant
public static Recognizer constant(java.lang.String c)
Recognizes all of the characters in c, in sequence.
-
anyChar
public static Recognizer anyChar(java.lang.String c)
Recognizer that matches any single character in the stringc
-
notChar
public static Recognizer notChar(java.lang.String c)
Recognizer that matches any single character not in the stringc
.
-
whitespace
public static Recognizer whitespace()
Recognizer that matches a single whitespace character.
-
-