MAJOR=7
MINOR=5
DEVNAME=vcs5
  C   	ˆl–äY>”JeJe@†à¸Û*bÑ¿�þDû.,Ü¡p¬ˆ$‘¦�üÿÈ„lÇ_ŠI|¥�+Wé3ž¯ÇÆ )6    	# filesetlang.py - parser, tokenizer and utility for file set language
#
# Copyright 2010 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.


from .i18n import _
from .pycompat import getattr
from . import (
    error,
    parser,
    pycompat,
)

# common weight constants for static optimization
# (see registrar.filesetpredicate for details)
WEIGHT_CHECK_FILENAME = 0.5
WEIGHT_READ_CONTENTS = 30
WEIGHT_STATUS = 10
WEIGHT_STATUS_THOROUGH = 50

elements = {
    # token-type: binding-strength, primary, prefix, infix, suffix
    b"(": (20, None, (b"group", 1, b")"), (b"func", 1, b")"), None),
    b":": (15, None, None, (b"kindpat", 15), None),
    b"-": (5, None, (b"negate", 19), (b"minus", 5), None),
    b"not": (10, None, (b"not", 10), None, None),
    b"!": (10, None, (b"not", 10), None, None),
    b"and": (5, None, None, (b"and", 5), None),
    b"&": (5, None, None, (b"and", 5), None),
    b"or": (4, None, None, (b"or", 4), None),
    b"|": (4, None, None, (b"or", 4), None),
    b"+": (4, None, None, (b"or", 4), None),
    b",": (2, None, None, (b"list", 2), None),
    b")": (0, None, None, None, None),
    b"symbol": (0, b"symbol", None, None, None),
    b"string": (0, b"string", None, None, None),
    b"end": (0, None, None, None, None),
}

keywords = {b'and', b'or', b'not'}

symbols = {}

globchars = b".*{}[]?/\\_"


def tokenize(program):
    pos, l = 0, len(program)
    program = pycompat.bytestr(program)
    while pos < l:
        c = program[pos]
        if c.isspace():  # skip inter-token whitespace
            pass
        elif c in b"(),-:|&+!":  # handle simple operators
            yield (c, None, pos)
        elif (
            c in b'"\''
            or c == b'r'
            and program[pos : pos + 2] in (b"r'", b'r"')
        ):  # handle quoted strings
            if c == b'r':
                pos += 1
                c = program[pos]
                decode = lambda x: x
            else:
                decode = parser.unescapestr
            pos += 1
            s = pos
            while pos < l:  # find closing quote
                d = program[pos]
                if d == b'\\':  # skip over escaped characters
                    pos += 2
                    continue
                if d == c:
                    yield (b'string', decode(program[s:pos]), s)
                    break
                pos += 1
            else:
                raise error.ParseError(_(b"unterminated string"), s)
        elif c.isalnum() or c in globchars or ord(c) > 127:
            # gather up a symbol/keyword
            s = pos
            pos += 1
            while pos < l:  # find end of symbol
                d = program[pos]
                if not (d.isalnum() or d in globchars or ord(d) > 127):
                    break
                pos += 1
            sym = program[s:pos]
            if sym in keywords:  # operator keywords
                yield (sym, None, s)
            else:
                yield (b'symbol', sym, s)
            pos -= 1
        else:
            raise error.ParseError(_(b"syntax error"), pos)
        pos += 1
    yield (b'end', None, pos)


def parse(expr):
    p = parser.parser(elements)
    tree, pos = p.parse(tokenize(expr))
    if pos != len(expr):
        raise error.ParseError(_(b"invalid token"), pos)
    return parser.simplifyinfixops(tree, {b'list', b'or'})


def getsymbol(x):
    if x and x[0] == b'symbol':
        return x[1]
    raise error.ParseError(_(b'not a symbol'))


def getstring(x, err):
    if x and (x[0] == b'string' or x[0] == b'symbol'):
        return x[1]
    raise error.ParseError(err)


def getkindpat(x, y, allkinds, err):
    kind = getsymbol(x)
    pat = getstring(y, err)
    if kind not in allkinds:
        raise error.ParseError(_(b"invalid pattern kind: %s") % kind)
    return b'%s:%s' % (kind, pat)


def getpattern(x, allk