rex icon indicating copy to clipboard operation
rex copied to clipboard

Support flags

Open hedhyw opened this issue 2 years ago • 0 comments

Definition

(?flags)       set flags within current group; non-capturing
(?flags:re)    set flags during re; non-capturing

Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:

i              case-insensitive (default false)
m              multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
s              let . match \n (default false)
U              ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)

Example methods

rex.Group.Flags(...dialect.GroupFlag) GroupToken // `(?flags)`
type GroupToken struct {
   prefix   string
   tokens ...dialect.Token
}

GroupToken.WithFlags(...base.GroupFlag) dialect.Token // prefix -> `?flags:`

Flag structure

// ab-cd
// means to set `a` and `b`, reset `c` and `d`.
//
// -abc
// reset `a`, `b` and `c`
//
// abc
// set `a`, `b` and `c`

type base.GroupFlag struct {
    val rune      // i, m, s or U
    reset bool
}

rex.Group.FlagCaseInsensitive()
rex.Group.FlagMultiLineMode()
rex.Group.FlagAnyMatchEndLine()
rex.Group.FlagUngreedy()
// WithReset() can be used for any flag.
rex.Group.FlagUngreedy().WithReset()

hedhyw avatar Jun 17 '22 15:06 hedhyw