Added node types for left and right parentheses

master
Aadhavan Srinivasan 2 months ago
parent 7d265495f5
commit 9a073aa514

@ -1,6 +1,8 @@
package main package main
import "slices" import (
"slices"
)
type NodeType int type NodeType int
@ -13,6 +15,8 @@ const (
QUESTION QUESTION
PLUS PLUS
ASSERTION ASSERTION
LPAREN
RPAREN
) )
var INFINITE_REPS int = -1 // Represents infinite reps eg. the end range in {5,} var INFINITE_REPS int = -1 // Represents infinite reps eg. the end range in {5,}
@ -20,8 +24,8 @@ var INFINITE_REPS int = -1 // Represents infinite reps eg. the end range in {5,}
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 startReps int // Minimum number of times the node should be repeated - used with numeric specifiers
endReps int endReps int // Maximum number of times the node should be repeated - used with numeric specifiers
} }
// 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
@ -89,6 +93,10 @@ func newPostfixNode(contents ...rune) postfixNode {
to_return.nodetype = CONCATENATE to_return.nodetype = CONCATENATE
case '^', '$': case '^', '$':
to_return.nodetype = ASSERTION to_return.nodetype = ASSERTION
case '(':
to_return.nodetype = LPAREN
case ')':
to_return.nodetype = RPAREN
default: default:
to_return.nodetype = CHARACTER to_return.nodetype = CHARACTER
} }

Loading…
Cancel
Save