dfa-regex-engine

module
v0.0.0-...-d9f2893 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2019 License: MIT

README

Go Report Card Follow on Twitter

DFA Regex Engine(in Golang)

This is simple DFA regex engine written in Go.

Description

This engine may not be practical as I just wrote this to learn how the dfa engine works.

Metacharacters

The engine supports the following metacharacters.

Metacharacter Desciption Examples
* Matches 0 or more repetitions of a pattern. a* = a, aaa...
+ Matches 1 or more repetitions of a pattern. (abc)+ = abc, abcabc, abcabcabc...
| Match any of the left and right patterns.(like the Boolean OR) a|b|c = a, b, c

Usage

re := dfaregex.Compile("(a|b)c*")
re.Match("acccc")   // => true

Example

package main

import (
	"fmt"
	"github.com/8ayac/dfa-regex-engine/dfaregex"
)

func main() {
	regex := "piyo(o*)"
	re := dfaregex.Compile(regex)

	for _, s := range []string{"piyo", "piyoooo", "piy0"} {
		if re.Match(s) {
			fmt.Printf("%s\t=> matched.\n", s)
		} else {
			fmt.Printf("%s\t=> NOT matched.\n", s)
		}
	}
}
$ go run main.go
piyo	=> matched.
piyoooo	=> matched.
piy0	=> NOT matched.

How to install

$ go get -u github.com/8ayac/dfa-regex-engine

License

MIT

Author

8ayac

Directories

Path Synopsis
dfa
Package dfa implements Deterministic Finite Automaton(DFA).
Package dfa implements Deterministic Finite Automaton(DFA).
dfadebug
Package dfadebug provides some features to debug a dfa.
Package dfadebug provides some features to debug a dfa.
dfarule
Package dfarule implements the transition function of DFA.
Package dfarule implements the transition function of DFA.
Package dfaregex provides a DFA regex engine(DFA engine).
Package dfaregex provides a DFA regex engine(DFA engine).
Package lexer implements lexer for a simple regular expression.
Package lexer implements lexer for a simple regular expression.
nfa
Package nfa implements Non-Deterministic Finite Automaton(NFA).
Package nfa implements Non-Deterministic Finite Automaton(NFA).
nfabuilder
Package nfabuilder implements some structures and functions to construct NFA.
Package nfabuilder implements some structures and functions to construct NFA.
nfarule
Package nfarule implements the transition function of NFA.
Package nfarule implements the transition function of NFA.
Package nfa2dfa implements function to convert a NFA into a DFA.
Package nfa2dfa implements function to convert a NFA into a DFA.
Package node implements some AST nodes.
Package node implements some AST nodes.
Package parser implements function to parse the regular expressions.
Package parser implements function to parse the regular expressions.
Package token provides tokens for parsing the regular expressions.
Package token provides tokens for parsing the regular expressions.
Package utils contains utility types and functions for dfa-regex-engine.
Package utils contains utility types and functions for dfa-regex-engine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL