Documentation
¶
Overview ¶
Package tre is a Go port of TRE, the POSIX regular expression engine by Ville Laurikari that R uses for its default (perl=FALSE, fixed=FALSE) patterns. It ports tre-parse.c, tre-compile.c, tre-match-parallel.c, tre-match-backtrack.c and regexec.c from upstream TRE; the licence notice of TRE is in the file NOTICE.
Not ported: approximate matching (tre-match-approx.c, the {~n} bound syntax); a pattern that uses it is rejected with ErrBadPat. The wide character, system wctype and multibyte-string front ends of the C library are replaced by one engine over []rune code units.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrCode ¶
type ErrCode int
ErrCode is a TRE error code; the zero value, RegOK, is success. ErrCode implements error. The messages are those of TRE's regerror.c.
const ( RegOK ErrCode = iota ErrNoMatch ErrBadPat ErrECollate ErrECType ErrEEscape ErrESubReg ErrEBrack ErrEParen ErrEBrace ErrBadBR ErrERange ErrESpace ErrBadRpt ErrBadMax // ErrSteps is not a TRE code: the match exceeded Limits.MaxSteps. ErrSteps // ErrApprox is not a TRE code: the pattern uses TRE's approximate // matching syntax ({~n}, {+n}, {1i+1d<2}), which is not ported. ErrApprox )
The error codes, in the order of tre.h's reg_errcode_t.
type Flags ¶
type Flags int
Flags are the tre_regcomp() flags, with the values of tre.h.
const ( Extended Flags = 1 // REG_EXTENDED ICase Flags = 2 // REG_ICASE Newline Flags = 4 // REG_NEWLINE NoSub Flags = 8 // REG_NOSUB Literal Flags = 16 // REG_LITERAL: the pattern is a literal string RightAssoc Flags = 32 // REG_RIGHT_ASSOC Ungreedy Flags = 64 // REG_UNGREEDY // UseBytes is R's REG_USEBYTES: the pattern and the subject are // sequences of bytes (code units below 256), not characters; character // classes are expanded over 0..255 as TRE does in a single-byte locale. UseBytes Flags = 128 )
type Limits ¶
type Limits struct {
// MaxPattern is the longest pattern in code units (default 65536, TRE's
// TRE_MAX_RE).
MaxPattern int
// MaxNodes bounds the AST nodes, including those created by expanding
// bounded repetition (default 1<<20).
MaxNodes int
// MaxStates bounds the positions (NFA states) (default 1<<19).
MaxStates int
// MaxTransitions bounds the NFA transitions (default 1<<23).
MaxTransitions int
// MaxSetItems bounds the entries of all firstpos/lastpos sets, whose
// size can be quadratic in the pattern (default 1<<23).
MaxSetItems int
// MaxSteps bounds the work of one match: transitions examined by the
// parallel matcher, loop iterations and transitions by the backtracking
// matcher (default 1<<28; negative means unlimited).
MaxSteps int
}
Limits bound the resources of one compilation and one match; the zero value of a field selects its default. They make hostile patterns and inputs fail with an error instead of exhausting memory or time.
type Match ¶
type Match struct{ So, Eo int }
Match is one submatch: the offsets are in code units of the matched input (characters, or bytes in byte mode); -1 means the group did not take part.
type Options ¶
type Options struct {
Flags Flags
// RCompat selects the behaviours of R's modified copy of TRE where they
// differ from upstream TRE: {,n} keeps a minimum of -1 (so it matches
// n+1 repetitions), a bound that overflows an int is "unbounded or 1",
// a bound above 255 is "Invalid contents of {}" (never "Maximum
// repetition"), {m,n} is expanded as (|x(|x...)) rather than (x(x...)?)?,
// and an empty REG_LITERAL pattern matches "".
RCompat bool
Limits Limits
}
Options configure Compile.
type Regexp ¶
type Regexp struct {
// contains filtered or unexported fields
}
Regexp is a compiled pattern. It is safe for concurrent use.
func Compile ¶
Compile compiles pattern, a UTF-8 string, with default options. With the UseBytes flag each byte of the pattern is one code unit.
func CompileOptions ¶
CompileOptions compiles pattern with the given options.
func CompileRunes ¶
CompileRunes compiles a pattern given as code units.
func (*Regexp) Exec ¶
Exec matches the subject s, given as code units, and returns nmatch submatches (the first is the whole match). The error is ErrNoMatch when the subject does not match, ErrSteps when the step limit was exceeded.
func (*Regexp) ExecString ¶
ExecString matches the string s. In byte mode every byte is a code unit and the offsets are byte offsets; otherwise s is decoded as UTF-8 and the offsets are in characters. A subject that is not valid UTF-8 does not match (TRE's mbrtowc failure).
func (*Regexp) HaveBackrefs ¶
HaveBackrefs reports whether the pattern has back references (and so is matched by the backtracking matcher).
func (*Regexp) MatchString ¶
MatchString reports whether s matches (no submatches are computed).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
crefbuild
command
Command crefbuild builds the C oracle (upstream TRE with the differential harness and the retest recorder) and, with -record, writes the recordings of TRE's own tests to testdata.
|
Command crefbuild builds the C oracle (upstream TRE with the differential harness and the retest recorder) and, with -record, writes the recordings of TRE's own tests to testdata. |
|
internal
|
|
|
cref
Package cref builds upstream TRE (C) with the harness and recorder of this directory and drives the harness: it is the engine-level oracle of the Go port's tests.
|
Package cref builds upstream TRE (C) with the harness and recorder of this directory and drives the harness: it is the engine-level oracle of the Go port's tests. |