vm-regex-engine

command module
v0.0.0-...-2c802aa Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 4 Imported by: 0

README

Go Report Card Follow on Twitter

VM Regex Engine(in Golang)

This is simple VM 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 any characters. . = a, b, c
* Matches 0 or more repetitions of a pattern. a* = a, aaa...
+ Matches 1 or more repetitions of a pattern. (abc)+ = abc, abcabc, abcabcabc...
? Matches 0 or 1 repetitions of a pattern. Apple? = Appl, Apple
| Match any of the left and right patterns.(like the Boolean OR) a|b|c = a, b, c

Usage

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

Example

package main

import (
	"fmt"
	"github.com/8ayac/vm-regex-engine/vmregex"
)

func main() {
	regex := "piyo(o*)"
	re := vmregex.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/vm-regex-engine

License

MIT

Author

8ayac

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package bytecode provides the bytecode structure and some utilities for convenient use of bytecodes.
Package bytecode provides the bytecode structure and some utilities for convenient use of bytecodes.
Package lexer implements lexer for a simple regular expression.
Package lexer implements lexer for a simple regular expression.
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.
vm
Package vm provides a Virtual Machine to execute regular expression matching.
Package vm provides a Virtual Machine to execute regular expression matching.
instruction
Package instruction provides the instruction structure and some its methods.
Package instruction provides the instruction structure and some its methods.
opcode
Package opcode provides the type Opcode to identify the type of operation code.
Package opcode provides the type Opcode to identify the type of operation code.
Package vmregex provides a VM regex engine(VM engine).
Package vmregex provides a VM regex engine(VM engine).

Jump to

Keyboard shortcuts

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