Moved case-insensitive stuff to thompson(); fixed case-insensitivity in character classes and ranges
This commit is contained in:
		
							
								
								
									
										32
									
								
								compile.go
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								compile.go
									
									
									
									
									
								
							@@ -812,18 +812,36 @@ func thompson(re []postfixNode) (Reg, error) {
 | 
				
			|||||||
							// and them to the state's _content_. As mentioned above, if the exception has exceptions, then we can match
 | 
												// and them to the state's _content_. As mentioned above, if the exception has exceptions, then we can match
 | 
				
			||||||
							// those.
 | 
												// those.
 | 
				
			||||||
							nodeExceptChars := slices.Concat(Map(node.except, func(node postfixNode) []rune {
 | 
												nodeExceptChars := slices.Concat(Map(node.except, func(node postfixNode) []rune {
 | 
				
			||||||
								return node.contents
 | 
													nodeContents := node.contents
 | 
				
			||||||
 | 
													if caseInsensitive {
 | 
				
			||||||
 | 
														nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune {
 | 
				
			||||||
 | 
															return allCases(r, caseInsensitive)
 | 
				
			||||||
 | 
														})...)
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
													return nodeContents
 | 
				
			||||||
							})...)
 | 
												})...)
 | 
				
			||||||
							state.content = rune2Contents(nodeExceptChars)
 | 
												state.content = rune2Contents(nodeExceptChars)
 | 
				
			||||||
						} else {
 | 
											} else {
 | 
				
			||||||
							state.except = append(state.except, node.contents...)
 | 
												charsToAdd := node.contents
 | 
				
			||||||
 | 
												if caseInsensitive {
 | 
				
			||||||
 | 
													charsToAdd = slices.Concat(Map(charsToAdd, func(r rune) []rune {
 | 
				
			||||||
 | 
														return allCases(r, caseInsensitive)
 | 
				
			||||||
 | 
													})...)
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
												state.except = append(state.except, charsToAdd...)
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// Convert the current contents to []int, convert the result of rune2contents to []int, append then
 | 
								// Convert the current contents to []int, convert the result of rune2contents to []int, append then
 | 
				
			||||||
			// convert back to stateContents.
 | 
								// convert back to stateContents.
 | 
				
			||||||
			state.content = stateContents(append([]int(state.content), []int(rune2Contents(c.contents))...))
 | 
								runesToAdd := c.contents
 | 
				
			||||||
 | 
								if caseInsensitive {
 | 
				
			||||||
 | 
									runesToAdd = slices.Concat(Map(runesToAdd, func(r rune) []rune {
 | 
				
			||||||
 | 
										return allCases(r, caseInsensitive)
 | 
				
			||||||
 | 
									})...)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								state.content = stateContents(append([]int(state.content), []int(rune2Contents(runesToAdd))...))
 | 
				
			||||||
			state.output = make([]*State, 0)
 | 
								state.output = make([]*State, 0)
 | 
				
			||||||
			state.output = append(state.output, &state)
 | 
								state.output = append(state.output, &state)
 | 
				
			||||||
			state.isEmpty = false
 | 
								state.isEmpty = false
 | 
				
			||||||
@@ -935,7 +953,13 @@ func thompson(re []postfixNode) (Reg, error) {
 | 
				
			|||||||
			// Map the list of nodes to a list of states, each state containing the contents of a specific node
 | 
								// Map the list of nodes to a list of states, each state containing the contents of a specific node
 | 
				
			||||||
			states := Map(c.nodeContents, func(node postfixNode) *State {
 | 
								states := Map(c.nodeContents, func(node postfixNode) *State {
 | 
				
			||||||
				s := newState()
 | 
									s := newState()
 | 
				
			||||||
				s.content = rune2Contents(node.contents)
 | 
									nodeContents := node.contents
 | 
				
			||||||
 | 
									if caseInsensitive {
 | 
				
			||||||
 | 
										nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune {
 | 
				
			||||||
 | 
											return allCases(r, caseInsensitive)
 | 
				
			||||||
 | 
										})...)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									s.content = rune2Contents(nodeContents)
 | 
				
			||||||
				return &s
 | 
									return &s
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			// Reduce the list of states down to a single state by alternating them
 | 
								// Reduce the list of states down to a single state by alternating them
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user