zig-regex
所属分类:collect
开发工具:Zig
文件大小:0KB
下载次数:0
上传日期:2023-06-05 14:38:58
上 传 者:
sh-1993
说明: zig编程语言的正则表达式实现,
(A regex implementation for the zig programming language,)
文件列表:
LICENSE (1079, 2023-06-02)
build.zig (1390, 2023-06-02)
example/ (0, 2023-06-02)
example/example.c (247, 2023-06-02)
include/ (0, 2023-06-02)
include/regex.h (853, 2023-06-02)
src/ (0, 2023-06-02)
src/all_test.zig (151, 2023-06-02)
src/c_regex.zig (2341, 2023-06-02)
src/compile.zig (19357, 2023-06-02)
src/debug.zig (4154, 2023-06-02)
src/exec.zig (723, 2023-06-02)
src/input.zig (4051, 2023-06-02)
src/parse.zig (30069, 2023-06-02)
src/parse_test.zig (15592, 2023-06-02)
src/range_set.zig (10172, 2023-06-02)
src/regex.zig (4083, 2023-06-02)
src/regex_test.zig (6623, 2023-06-02)
src/vm_backtrack.zig (6343, 2023-06-02)
src/vm_pike.zig (6741, 2023-06-02)
src/vm_test.zig (6439, 2023-06-02)
An automaton-based regex implementation for [zig](http://ziglang.org/).
Note: This is still a work in progress and many things still need to be done.
- [x] Capture group support
- [ ] UTF-8 support
- [ ] More tests (plus some automated tests/fuzzing)
- [x] Add a PikeVM implementation
- [ ] Literal optimizations and just general performance improvements.
## Usage
```zig
const debug = @import("std").debug;
const Regex = @import("regex").Regex;
test "example" {
var re = try Regex.compile(debug.global_allocator, "\\w+");
debug.assert(try re.match("hej") == true);
}
```
## Api
### Regex
```zig
fn compile(a: Allocator, re: []const u8) !Regex
```
Compiles a regex string, returning any errors during parsing/compiling.
---
```zig
pub fn match(re: *Regex, input: []const u8) !bool
```
Match a compiled regex against some input. The input must be matched in its
entirety and from the first index.
---
```zig
pub fn partialMatch(re: *Regex, input: []const u8) !bool
```
Match a compiled regex against some input. Unlike `match`, this matches the
leftmost and does not have to be anchored to the start of `input`.
---
```zig
pub fn captures(re: *Regex, input: []const u8) !?Captures
```
Match a compiled regex against some input. Returns a list of all matching
slices in the regex with the first (0-index) being the entire regex.
If no match was found, null is returned.
### Captures
```zig
pub fn sliceAt(captures: *const Captures, n: usize) ?[]const u8
```
Return the sub-slice for the numbered capture group. 0 refers to the entire
match.
```zig
pub fn boundsAt(captures: *const Captures, n: usize) ?Span
```
Return the lower and upper byte positions for the specified capture group.
We can retrieve the sub-slice using this function:
```zig
const span = caps.boundsAt(0)
debug.assert(mem.eql(u8, caps.sliceAt(0), input[span.lower..span.upper]));
```
---
## References
See the following useful sources:
- https://swtch.com/~rsc/regexp/
- [Rust Regex Library](https://github.com/rust-lang/regex)
- [Go Regex Library](https://github.com/golang/go/tree/master/src/regexp)
近期下载者:
相关文件:
收藏者: