'Import PyParsing and define the syntax for filter expressions'

def _parser(self):

    try:
        import pyparsing as pp
    except ImportError:
        current.log.error('Advanced    filter    syntax    requires    pyparsing,    $filter    ignored')
        return False
    context = (lambda s, l, t: t[0].replace('[', '(').replace(']', ')'))
    selector = pp.Word((pp.alphas + '[]~'), (pp.alphanums + '_.$:[]'))
    selector.setParseAction(context)
    keyword = (lambda x, y: ((x | pp.Keyword(y)) if x else pp.Keyword(y)))
    function = reduce(keyword, S3FieldSelector.OPERATORS)
    expression = (((function + pp.Literal('(').suppress()) + selector) + pp.Literal(')').suppress())
    comparison = reduce(keyword, S3ResourceQuery.COMPARISON)
    number = pp.Regex('[+-]?\\d+(:?\\.\\d*)?(:?[eE][+-]?\\d+)?')
    value = (((number | pp.Keyword('NONE')) | pp.quotedString) | pp.Word((pp.alphanums + pp.printables)))
    qe = pp.Group(((pp.Group((expression | selector)) + comparison) + pp.originalTextFor(pp.delimitedList(value, combine=True))))
    parser = pp.operatorPrecedence(qe, [('not', 1, pp.opAssoc.RIGHT), ('and', 2, pp.opAssoc.LEFT), ('or', 2, pp.opAssoc.LEFT)])
    self.parser = parser
    self.ParseResults = pp.ParseResults
    self.ParseException = pp.ParseException
    return True
