|
|
@ -15,15 +15,20 @@ const (
|
|
|
|
ASSERTION
|
|
|
|
ASSERTION
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var INFINITE_REPS int = -1 // Represents infinite reps eg. the end range in {5,}
|
|
|
|
// This represents a node in the postfix representation of the expression
|
|
|
|
// This represents a node in the postfix representation of the expression
|
|
|
|
type postfixNode struct {
|
|
|
|
type postfixNode struct {
|
|
|
|
nodetype NodeType
|
|
|
|
nodetype NodeType
|
|
|
|
contents []rune // Contents of the node - the length of this would only be >1 if the node represents a character class
|
|
|
|
contents []rune // Contents of the node - the length of this would only be >1 if the node represents a character class
|
|
|
|
|
|
|
|
startReps int // How many times the node should be repeated - used with numeric specifiers
|
|
|
|
|
|
|
|
endReps int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Creates a new escaped node - the given character is assumed to have been preceded by a backslash
|
|
|
|
// Creates a new escaped node - the given character is assumed to have been preceded by a backslash
|
|
|
|
func newEscapedNode(c rune) postfixNode {
|
|
|
|
func newEscapedNode(c rune) postfixNode {
|
|
|
|
toReturn := postfixNode{}
|
|
|
|
toReturn := postfixNode{}
|
|
|
|
|
|
|
|
toReturn.startReps = 1
|
|
|
|
|
|
|
|
toReturn.endReps = 1
|
|
|
|
switch c {
|
|
|
|
switch c {
|
|
|
|
case 's': // Whitespace
|
|
|
|
case 's': // Whitespace
|
|
|
|
toReturn.nodetype = CHARACTER
|
|
|
|
toReturn.nodetype = CHARACTER
|
|
|
@ -65,6 +70,8 @@ func newPostfixNode(contents ...rune) postfixNode {
|
|
|
|
panic("Empty node.")
|
|
|
|
panic("Empty node.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
to_return := postfixNode{}
|
|
|
|
to_return := postfixNode{}
|
|
|
|
|
|
|
|
to_return.startReps = 1
|
|
|
|
|
|
|
|
to_return.endReps = 1
|
|
|
|
if len(contents) > 1 { // If the node has more than element, it must be a character class - the type must be CHARACTER
|
|
|
|
if len(contents) > 1 { // If the node has more than element, it must be a character class - the type must be CHARACTER
|
|
|
|
to_return.nodetype = CHARACTER
|
|
|
|
to_return.nodetype = CHARACTER
|
|
|
|
to_return.contents = contents
|
|
|
|
to_return.contents = contents
|
|
|
|