From b602295bee2304ccef098ef6f8d7a152dbf162c6 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 3 Nov 2024 14:36:56 -0500 Subject: [PATCH] Added support for specifying how often a postfixNode is repeated --- postfixNode.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/postfixNode.go b/postfixNode.go index 83c13c9..ca45271 100644 --- a/postfixNode.go +++ b/postfixNode.go @@ -15,15 +15,20 @@ const ( 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 type postfixNode struct { - nodetype NodeType - contents []rune // Contents of the node - the length of this would only be >1 if the node represents a character class + nodetype NodeType + 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 func newEscapedNode(c rune) postfixNode { toReturn := postfixNode{} + toReturn.startReps = 1 + toReturn.endReps = 1 switch c { case 's': // Whitespace toReturn.nodetype = CHARACTER @@ -65,6 +70,8 @@ func newPostfixNode(contents ...rune) postfixNode { panic("Empty node.") } 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 to_return.nodetype = CHARACTER to_return.contents = contents