glob.bend checks
raw source on the hub · import bend-osdev-apparmor@0.1.0.0/glob.bend as Glob
bend-osdev-apparmor: AppArmor globs (AARE), as an explicit matcher.
apparmor.d(5), "Globbing (AARE)": * any run of characters except '/', ** any run including '/', ? one character except '/', [abc] [a-c] [^a-c] one character in (or not in) a set, {ab,cd} alternatives. Where the page is silent, the choices follow what apparmor_parser 4.0.1 compiles a pattern to (its --dump=rule-exprs output; see the README, "Experiments"): * a * that is a whole path segment ('/' before it, '/' or the end after it) matches one or more characters, so /tmp/* does not match /tmp/; a ** after a '/' and before a '/', a '*' or the end matches one or more characters, the first not '/'. Both are a ? followed by the star; * a negated class may match '/'; * runs of '/' collapse to one, except a leading "//"; * \c is the character c; a class may not hold '\', start with ']' or end with '-'; a {...} group needs at least two alternatives.
A pattern is brace-expanded when it is parsed: AaGlob holds its alternatives, each a sequence of AaGTok. Three matchers, tied by laws for every sequence and path: AaGSeq.model, the list model: every way to cut the path into one piece per token (AaGCuts.all), each piece checked against its token; AaGSeq.matches, the reference: a backtracking walk over the sequence and the path (exponential in the stars, since Bend evaluates every argument); AaGSeq.run, what AaGlob.matches uses: the set of active positions in the sequence moved along the path a byte at a time, stopping when none is left (linear in the path, times the sequence's length).
2 imports
import Base import ./text.bend as X
Types
type AaGRange source · line 31 · raw
Data
AaGRange@lo:U32 -> @hi:U32 -> AaGRange
type AaGTok source · line 34 · raw
Data
AaGChar@c:U32 -> AaGTok
AaGAnyAaGTok
AaGClass@neg:Bool -> @ranges:List<&2, AaGRange> -> AaGTok
AaGStarAaGTok
AaGStar2AaGTok
type AaGlob source · line 41 · raw
Data
AaGlob@alts:List<&2, List<&2, AaGTok>> -> @literal:Bool -> AaGlob
type AaGFlat source · line 417 · raw
Data
AaGFTok@t:AaGTok -> AaGFlat
AaGFOpenAaGFlat
AaGFSepAaGFlat
AaGFCloseAaGFlat
type AaGMode source · line 423 · raw
Data
AaGMNormAaGMode
AaGMEscAaGMode
AaGMStarAaGMode
AaGMClass@neg:Bool -> @first:Bool -> @rs:List<&2, AaGRange> -> @pend:Maybe<&2, U32> -> @dash:Bool -> AaGMode
type AaGLex source · line 433 · raw
Data
the lexer's state: the mode, the character before the current one, whether the last thing emitted is a '/' that a following '/' collapses into, whether nothing has been emitted yet, the brace depth, the flat tokens (last first), and whether the text is still well formed
AaGLex@mode:AaGMode -> @prev:U32 -> @slash:Bool -> @start:Bool -> @depth:Nat -> @out:List<&2, AaGFlat> -> @ok:Bool -> AaGLex
type AaGCh source · line 520 · raw
Data
what a character means in normal mode
AaGCLitAaGCh
AaGCEscAaGCh
AaGCStarAaGCh
AaGCAnyAaGCh
AaGCClassAaGCh
AaGCOpenAaGCh
AaGCCommaAaGCh
AaGCCloseAaGCh
AaGCBadAaGCh
AaGCSlashAaGCh
type AaGK source · line 559 · raw
Data
Character classes: what a character means inside [...]
AaGKCloseAaGK
AaGKCaretAaGK
AaGKDashAaGK
AaGKBackAaGK
AaGKOtherAaGK
type AaGFrame source · line 691 · raw
Data
AaGFrame@outer:List<&2, List<&2, AaGTok>> -> @done:List<&2, List<&2, AaGTok>> -> @n:Nat -> AaGFrame
type AaGExp source · line 694 · raw
Data
AaGExp@cur:List<&2, List<&2, AaGTok>> -> @frames:List<&2, AaGFrame> -> @ok:Bool -> AaGExp
Definitions
def AaGRange.has source · line 46 · raw
@r:AaGRange -> @+c:U32 -> Bool
def AaGClass.any source · line 51 · raw
@rs:List<&2, AaGRange> -> @+c:U32 -> Bool
def AaGClass.has source · line 58 · raw
@neg:Bool -> @rs:List<&2, AaGRange> -> @+c:U32 -> Bool
def AaGSeq.matches source · line 67 · raw
@+seq:List<&2, AaGTok> -> @s:List<&2, U32> -> Bool
def AaGNfa.hd source · line 109 · raw
@bs:List<&2, Bool> -> Bool
def AaGNfa.tl source · line 116 · raw
@bs:List<&2, Bool> -> List<&2, Bool>
def AaGNfa.stay source · line 124 · raw
@tok:AaGTok -> @+h:U32 -> Bool
a star stays on a byte (* on anything but '/', ** on anything)
def AaGNfa.adv source · line 134 · raw
@tok:AaGTok -> @+h:U32 -> Bool
a single-byte token moves past a byte it takes
def AaGNfa.isstar source · line 146 · raw
@tok:AaGTok -> Bool
a star may match nothing: the position after it is active too
def AaGNfa.next source · line 157 · raw
@+seq:List<&2, AaGTok> -> @+bs:List<&2, Bool> -> @+cin:Bool -> @+ain:Bool -> @+h:U32 -> List<&2, Bool>
the positions active after the byte h: cin, the position is reached without a byte (after a star); ain, the previous position moved here
def AaGNfa.sem source · line 165 · raw
@+seq:List<&2, AaGTok> -> @+bs:List<&2, Bool> -> @+s:List<&2, U32> -> Bool
what a set of positions accepts: some active position's suffix matches s
def AaGNfa.alive source · line 173 · raw
@bs:List<&2, Bool> -> Bool
some position is active
def AaGNfa.run source · line 183 · raw
@s:List<&2, U32> -> @alive:Bool -> @+seq:List<&2, AaGTok> -> @bs:List<&2, Bool> -> Bool
the positions moved along the path; at its end, the active positions whose suffixes match the empty string accept. alive: some position is active (computed by the caller); when none is, the path cannot match.
def AaGNfa.falses source · line 195 · raw
@seq:List<&2, AaGTok> -> List<&2, Bool>
def AaGNfa.start source · line 203 · raw
@seq:List<&2, AaGTok> -> List<&2, Bool>
only the first position (the whole sequence) is active
def AaGSeq.run source · line 211 · raw
@+seq:List<&2, AaGTok> -> @s:List<&2, U32> -> Bool
the matcher evaluation uses
def AaGPiece.no_slash source · line 218 · raw
@p:List<&2, U32> -> Bool
no byte of p is '/'
def AaGPiece.one source · line 226 · raw
@ok:Bool -> @p:List<&2, U32> -> Bool
the piece p is one byte b for which ok holds
def AaGPiece.first source · line 233 · raw
@p:List<&2, U32> -> U32
def AaGTok.piece source · line 241 · raw
@tok:AaGTok -> @+p:List<&2, U32> -> Bool
the piece p matches the token
def AaGCuts.empty_first source · line 255 · raw
@ds:List<&2, List<&2, List<&2, U32>>> -> List<&2, List<&2, List<&2, U32>>>
the cuts with an empty first piece
def AaGCuts.grow source · line 263 · raw
@+h:U32 -> @ds:List<&2, List<&2, List<&2, U32>>> -> List<&2, List<&2, List<&2, U32>>>
the cuts with h put in front of the first piece
def AaGCuts.append source · line 274 · raw
@xs:List<&2, List<&2, List<&2, U32>>> -> @ys:List<&2, List<&2, List<&2, U32>>> -> List<&2, List<&2, List<&2, U32>>>
def AaGCuts.all source · line 282 · raw
@+n:Nat -> @s:List<&2, U32> -> List<&2, List<&2, List<&2, U32>>>
every way to cut s into n pieces
def AaGSeq.fits source · line 298 · raw
@+seq:List<&2, AaGTok> -> @d:List<&2, List<&2, U32>> -> Bool
the pieces d match the tokens one to one
def AaGSeq.fits_any source · line 313 · raw
@+seq:List<&2, AaGTok> -> @ds:List<&2, List<&2, List<&2, U32>>> -> Bool
def AaGSeq.len source · line 320 · raw
@seq:List<&2, AaGTok> -> Nat
def AaGSeq.model source · line 327 · raw
@+seq:List<&2, AaGTok> -> @s:List<&2, U32> -> Bool
def AaGlob.matches.go source · line 332 · raw
@alts:List<&2, List<&2, AaGTok>> -> @+s:List<&2, U32> -> Bool
def AaGlob.matches_ref.go source · line 340 · raw
@alts:List<&2, List<&2, AaGTok>> -> @+s:List<&2, U32> -> Bool
the same with the backtracking matcher (the reference)
def AaGlob.matches_ref source · line 347 · raw
@g:AaGlob -> @+s:List<&2, U32> -> Bool
def AaGlob.matches source · line 352 · raw
@g:AaGlob -> @+s:List<&2, U32> -> Bool
def AaGlob.model.go source · line 357 · raw
@alts:List<&2, List<&2, AaGTok>> -> @+s:List<&2, U32> -> Bool
def AaGlob.model source · line 364 · raw
@g:AaGlob -> @+s:List<&2, U32> -> Bool
def AaGlob.is_literal source · line 369 · raw
@g:AaGlob -> Bool
def AaGSeq.prefix source · line 378 · raw
@seq:List<&2, AaGTok> -> U32
def AaGlob.rank.max source · line 395 · raw
@+a:U32 -> @+b:U32 -> U32
def AaGlob.rank.go source · line 398 · raw
@alts:List<&2, List<&2, AaGTok>> -> @+s:List<&2, U32> -> @+best:U32 -> U32
def AaGlob.rank source · line 406 · raw
@g:AaGlob -> @+s:List<&2, U32> -> U32
0: no match; 1 + prefix length for a pattern; 1000000 for a literal match
def AaGLex.fail source · line 436 · raw
@st:AaGLex -> AaGLex
def AaGLex.emit source · line 441 · raw
@st:AaGLex -> @f:AaGFlat -> @prev:U32 -> AaGLex
def AaGLex.slash.go source · line 446 · raw
@sl:Bool -> @st:AaGLex -> AaGLex
def AaGLex.slash source · line 457 · raw
@st:AaGLex -> AaGLex
def AaGLex.depth source · line 462 · raw
@st:AaGLex -> Nat
def AaGLex.prev source · line 467 · raw
@st:AaGLex -> U32
def AaGLex.set_mode source · line 472 · raw
@st:AaGLex -> @m:AaGMode -> AaGLex
def AaGLex.open source · line 477 · raw
@st:AaGLex -> AaGLex
def AaGLex.close.go source · line 482 · raw
@d:Nat -> @out:List<&2, AaGFlat> -> @ok:Bool -> @p:U32 -> AaGLex
def AaGLex.close source · line 489 · raw
@st:AaGLex -> AaGLex
def AaGLex.comma.go source · line 494 · raw
@d:Nat -> @st:AaGLex -> AaGLex
def AaGLex.comma source · line 501 · raw
@+st:AaGLex -> AaGLex
def AaGLex.star.go source · line 506 · raw
@seg:Bool -> @st:AaGLex -> @t:AaGTok -> AaGLex
a star or double star: after a '/', and before what next says, it stands
for one or more characters (a ? in front of it)
def AaGLex.star source · line 513 · raw
@+st:AaGLex -> @next:Bool -> AaGLex
def AaGLex.star2 source · line 516 · raw
@+st:AaGLex -> @next:Bool -> AaGLex
def AaGCh.of source · line 532 · raw
@+h:U32 -> AaGCh
def AaGLex.norm source · line 535 · raw
@k:AaGCh -> @+h:U32 -> @st:AaGLex -> AaGLex
def AaGK.of source · line 566 · raw
@+h:U32 -> AaGK
def AaGClass.flush source · line 569 · raw
@rs:List<&2, AaGRange> -> @pend:Maybe<&2, U32> -> List<&2, AaGRange>
def AaGClass.range source · line 577 · raw
@pend:Maybe<&2, U32> -> @h:U32 -> @rs:List<&2, AaGRange> -> @st:AaGLex -> @neg:Bool -> AaGLex
a range lo-h, the dash seen: lo is pending
def AaGClass.close.go source · line 584 · raw
@bad:Bool -> @st:AaGLex -> @neg:Bool -> @rs:List<&2, AaGRange> -> AaGLex
def AaGClass.other source · line 591 · raw
@dash:Bool -> @st:AaGLex -> @neg:Bool -> @rs:List<&2, AaGRange> -> @pend:Maybe<&2, U32> -> @h:U32 -> AaGLex
def AaGClass.caret.go source · line 598 · raw
@lit:Bool -> @st:AaGLex -> @neg:Bool -> @rs:List<&2, AaGRange> -> @pend:Maybe<&2, U32> -> @dash:Bool -> AaGLex
def AaGClass.dash.go source · line 606 · raw
@k:Nat -> @st:AaGLex -> @neg:Bool -> @rs:List<&2, AaGRange> -> @pend:Maybe<&2, U32> -> AaGLex
k: 0 a literal '-' (first, or nothing pending), 1 the dash of a range, 2 a second dash
def AaGClass.dash.kind source · line 617 · raw
@first:Bool -> @dash:Bool -> @pend:Maybe<&2, U32> -> Nat
def AaGClass.step source · line 632 · raw
@k:AaGK -> @+h:U32 -> @st:AaGLex -> @+neg:Bool -> @+first:Bool -> @+rs:List<&2, AaGRange> -> @+pend:Maybe<&2, U32> -> @+dash:Bool -> AaGLex
def AaGLex.step.star source · line 645 · raw
@two:Bool -> @st:AaGLex -> @+h:U32 -> @+next:U32 -> AaGLex
def AaGLex.step.mode source · line 653 · raw
@m:AaGMode -> @st:AaGLex -> @+h:U32 -> @+next:U32 -> AaGLex
one character, in the current mode; next is the character after it (0 at the end)
def AaGLex.step source · line 664 · raw
@st:AaGLex -> @+h:U32 -> @+next:U32 -> AaGLex
def AaGLex.finish source · line 669 · raw
@st:AaGLex -> AaGLex
def AaGLex.run source · line 682 · raw
@xs:List<&2, U32> -> @st:AaGLex -> AaGLex
def AaGSeqs.cons source · line 697 · raw
@+t:AaGTok -> @xs:List<&2, List<&2, AaGTok>> -> List<&2, List<&2, AaGTok>>
def AaGSeqs.append source · line 704 · raw
@xs:List<&2, List<&2, AaGTok>> -> @ys:List<&2, List<&2, AaGTok>> -> List<&2, List<&2, AaGTok>>
def AaGSeq.append source · line 711 · raw
@xs:List<&2, AaGTok> -> @ys:List<&2, AaGTok> -> List<&2, AaGTok>
def AaGSeq.rev_onto source · line 718 · raw
@xs:List<&2, AaGTok> -> @acc:List<&2, AaGTok> -> List<&2, AaGTok>
def AaGSeqs.rev source · line 725 · raw
@xs:List<&2, List<&2, AaGTok>> -> List<&2, List<&2, AaGTok>>
def AaGSeqs.after source · line 733 · raw
@+a:List<&2, AaGTok> -> @os:List<&2, List<&2, AaGTok>> -> List<&2, List<&2, AaGTok>>
every a ++ o, a an alternative and o an outer prefix (both last token first)
def AaGSeqs.product source · line 740 · raw
@alts:List<&2, List<&2, AaGTok>> -> @+os:List<&2, List<&2, AaGTok>> -> List<&2, List<&2, AaGTok>>
def AaGExp.sep source · line 747 · raw
@fs:List<&2, AaGFrame> -> @cur:List<&2, List<&2, AaGTok>> -> @ok:Bool -> AaGExp
def AaGExp.close.go source · line 756 · raw
@n:Nat -> @o:List<&2, List<&2, AaGTok>> -> @alts:List<&2, List<&2, AaGTok>> -> @rest:List<&2, AaGFrame> -> @ok:Bool -> AaGExp
def AaGExp.close source · line 763 · raw
@fs:List<&2, AaGFrame> -> @cur:List<&2, List<&2, AaGTok>> -> @ok:Bool -> AaGExp
def AaGExp.step source · line 772 · raw
@e:AaGExp -> @f:AaGFlat -> AaGExp
def AaGExp.run source · line 785 · raw
@xs:List<&2, AaGFlat> -> @e:AaGExp -> AaGExp
def AaGFlat.rev_onto source · line 792 · raw
@xs:List<&2, AaGFlat> -> @acc:List<&2, AaGFlat> -> List<&2, AaGFlat>
def AaGTok.is_char source · line 799 · raw
@t:AaGTok -> Bool
def AaGFlat.literal source · line 813 · raw
@xs:List<&2, AaGFlat> -> Bool
every flat token is a literal character
def AaGlob.of_exp.go source · line 828 · raw
@ok:Bool -> @cur:List<&2, List<&2, AaGTok>> -> @lit:Bool -> Maybe<&2, AaGlob>
def AaGlob.of_exp source · line 835 · raw
@e:AaGExp -> @lit:Bool -> Maybe<&2, AaGlob>
def AaGlob.of_flat source · line 844 · raw
@+flat:List<&2, AaGFlat> -> Maybe<&2, AaGlob>
def AaGlob.of_lex source · line 847 · raw
@st:AaGLex -> Maybe<&2, AaGlob>
def AaGlob.parse source · line 861 · raw
@xs:List<&2, U32> -> Maybe<&2, AaGlob>
the pattern written as the text xs, or None if it is malformed
def AaGSeq.literal source · line 865 · raw
@xs:List<&2, U32> -> List<&2, AaGTok>
a pattern matching exactly the bytes xs (no wildcards)
def AaGlob.literal source · line 872 · raw
@xs:List<&2, U32> -> AaGlob
def AaGlob.all source · line 876 · raw
AaGlob
the pattern that matches every string
def AaGlob.match_text.go source · line 879 · raw
@m:Maybe<&2, AaGlob> -> @+s:List<&2, U32> -> Bool
def AaGlob.match_text source · line 887 · raw
@p:List<&2, U32> -> @+s:List<&2, U32> -> Bool
the pattern written as p (False if it is malformed) matches s