Comments (3)
Here's a demo of what I'm trying to do. Not quite happy yet...
package main
import (
"fmt"
"regexp"
)
func main() {
input := "aaa aaa"
// Porting FindStringIndex() to fsm
r := regexp.MustCompile(`a{2,3}`)
match := r.FindStringIndex(input)
fmt.Printf("regexp: r.FindStringIndex returns %d, %d\n", match[0], match[1])
start, end := Match(input)
fmt.Printf("fsm: Match returns %d, %d\n", start, end)
// Porting ReplaceAll to fsm
out := r.ReplaceAllString(input, "b")
fmt.Printf("regexp: ReplaceAllString returns %s\n", out)
out = myReplaceAll(input, "b")
fmt.Printf("fsm: myReplaceAll returns %s\n", out)
}
// myReplaceAll finds all sequences in value that Match, and replaces them with repl.
// Any matches that might result from the replacement are ignored.
func myReplaceAll(value, repl string) string {
remaining := value
out := ""
for remaining != "" {
start, end := Match(remaining)
if start == -1 {
out = out + remaining
remaining = ""
} else {
println("match", remaining[start:end], "start", start, "end", end)
out = out + remaining[0:start] + repl
remaining = remaining[end:]
}
}
return out
}
Save that as main.go, then create match.go with something like
re -k str -l go -r pcre 'a{2,3}' | sed 's/fsm_fsm/main/' > match.go
and run with
go run main.go match.go
Currently, it outputs
regexp: r.FindStringIndex returns 0, 3
fsm: Match returns 0, 2
regexp: ReplaceAllString returns b b
match aa start 0 end 2
match aa start 2 end 4
fsm: myReplaceAll returns ba ba
Examining the generated code, fsm expands the quantifier a{2,3} to return immediately after the 2nd a, without even trying to consume a 3rd one.
(I filed #358 for that earlier, but may not have provided enough context.)
This is a fine optimization for detecting a match, so evidently my hack to return the end offset of the match is breaking an assumption libfsm made, and/or I'm misusing libfsm in some other way.
from libfsm.
from libfsm.
Thanks. I updated the problem description to address your last suggestion about induced matches.
I'm not worried about the inefficiency of using string for the moment.
I am very interested in suggestions for coaxing libfsm into actually finishing the match of a{2,3} instead
of calling it a day after aa.
from libfsm.
Related Issues (20)
- Build failure on freebsd HOT 5
- Clarification needed README instructions re: pmake/bmake on mac HOT 2
- Build failure on MacOS HOT 4
- Small syntax bug in `lx` man page HOT 1
- Unhandled `TOK_ERROR` for incompletely parsed unsupported backtracking control flags HOT 1
- Completion of error handling HOT 4
- The IR tests are currently disabled
- Attempt to build for Windows HOT 7
- bug: non-minimal DFA produced by fsm_minimise HOT 3
- CI fails for documentation build HOT 2
- lexing for pcre comments is slightly incorrect HOT 2
- retest: goasm backend is bizarrely flaky HOT 1
- Seg Fault when Using libre as Shared Library due to reg_comp Name Conflict HOT 5
- re_is_literal() is ambigious for \Z, \z, $
- We accidentally lost the ability to detect ambiguities HOT 4
- Allow escaped closing square bracket in character range
- CI fuzzing corpus "resource not accessible by integration" for PRs from external clones
- Case-insensitive regexps erroneously identified as literals
- lx: Bus error/Segmentation Fault on malformed input HOT 2
- libfsm fails to build with newer versions of bmake (versions after 2022) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libfsm.