| "(" + Optional(ParamList("part", PathOneInPropertySet) + ZeroOrMore("|" + ParamList("part", PathOneInPropertySet))) + ")", ) # [94] PathPrimary ::= iri | A | '!' PathNegatedPropertySet | '(' Path ')' | 'DISTINCT' '(' Path ')' PathPrimary = ( iri | A | Suppress("!") + PathNegatedPropertySet | Suppress("(") + Path + Suppress(")") | Comp("DistinctPath", Keyword("DISTINCT") + "(" + Param("part", Path) + ")") ) # [91] PathElt ::= PathPrimary Optional(PathMod) PathElt = Comp("PathElt", Param("part", PathPrimary) + Optional(Param("mod", PathMod.leaveWhitespace()))) # [92] PathEltOrInverse ::= PathElt | '^' PathElt PathEltOrInverse = PathElt | Suppress("^") + Comp("PathEltOrInverse", Param("part", PathElt)) # [90] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )* PathSequence = Comp( "PathSequence", ParamList("part", PathEltOrInverse) + ZeroOrMore("/" + ParamList("part", PathEltOrInverse)) ) # [89] PathAlternative ::= PathSequence ( '|' PathSequence )* PathAlternative = Comp( "PathAlternative", ParamList("part", PathSequence) + ZeroOrMore("|" + ParamList("part", PathSequence)) )
# [96] PathOneInPropertySet ::= iri | A | '^' ( iri | A ) PathOneInPropertySet = iri | A | Comp('InversePath', '^' + (iri | A)) Path = Forward() # [95] PathNegatedPropertySet ::= PathOneInPropertySet | '(' ( PathOneInPropertySet ( '|' PathOneInPropertySet )* )? ')' PathNegatedPropertySet = Comp('PathNegatedPropertySet', ParamList('part', PathOneInPropertySet) | '(' + Optional( ParamList('part', PathOneInPropertySet) + ZeroOrMore('|' + ParamList('part', PathOneInPropertySet))) + ')') # [94] PathPrimary ::= iri | A | '!' PathNegatedPropertySet | '(' Path ')' | 'DISTINCT' '(' Path ')' PathPrimary = iri | A | Suppress('!') + PathNegatedPropertySet | Suppress('(') + Path + Suppress( ')') | Comp('DistinctPath', Keyword('DISTINCT') + '(' + Param('part', Path) + ')') # [91] PathElt ::= PathPrimary Optional(PathMod) PathElt = Comp('PathElt', Param( 'part', PathPrimary) + Optional(Param('mod', PathMod.leaveWhitespace()))) # [92] PathEltOrInverse ::= PathElt | '^' PathElt PathEltOrInverse = PathElt | Suppress( '^') + Comp('PathEltOrInverse', Param('part', PathElt)) # [90] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )* PathSequence = Comp('PathSequence', ParamList('part', PathEltOrInverse) + ZeroOrMore('/' + ParamList('part', PathEltOrInverse))) # [89] PathAlternative ::= PathSequence ( '|' PathSequence )* PathAlternative = Comp('PathAlternative', ParamList('part', PathSequence) + ZeroOrMore('|' + ParamList('part', PathSequence))) # [88] Path ::= PathAlternative
'PathNegatedPropertySet', ParamList('part', PathOneInPropertySet) | '(' + Optional( ParamList('part', PathOneInPropertySet) + ZeroOrMore('|' + ParamList('part', PathOneInPropertySet))) + ')') # [94] PathPrimary ::= iri | A | '!' PathNegatedPropertySet | '(' Path ')' | 'DISTINCT' '(' Path ')' PathPrimary = iri | A | Suppress('!') + PathNegatedPropertySet | Suppress( '(') + Path + Suppress(')') | Comp( 'DistinctPath', Keyword('DISTINCT') + '(' + Param('part', Path) + ')') # [91] PathElt ::= PathPrimary Optional(PathMod) PathElt = Comp( 'PathElt', Param('part', PathPrimary) + Optional(Param('mod', PathMod.leaveWhitespace()))) # [92] PathEltOrInverse ::= PathElt | '^' PathElt PathEltOrInverse = PathElt | Suppress('^') + Comp('PathEltOrInverse', Param('part', PathElt)) # [90] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )* PathSequence = Comp( 'PathSequence', ParamList('part', PathEltOrInverse) + ZeroOrMore('/' + ParamList('part', PathEltOrInverse))) # [89] PathAlternative ::= PathSequence ( '|' PathSequence )* PathAlternative = Comp( 'PathAlternative', ParamList('part', PathSequence) +
argValueQuotes = (Quote('"""') | Quote('"') | Quote("'") | Quote('/')) stringBitNoSpaces = Combine( OneOrMore(escapedSymbol | Regex('[^{}\s]', re.S)))('stringBit').leaveWhitespace() argValueNoSpace = OneOrMore( Group(item.leaveWhitespace() | source.leaveWhitespace() | stringBitNoSpaces))('value') argValue = argValueQuotes | argValueNoSpace ###### ARG ASSIGNMENTS explicitArg = Group( identifier('paramName') + eq.leaveWhitespace() + argValue.leaveWhitespace()) implicitStringBit = Combine( ZeroOrMore(White()) + OneOrMore(escapedSymbol | Regex('[^{}\s]', re.S)) | OneOrMore(White()))('stringBit').leaveWhitespace() implicitArg = Group( OneOrMore(~explicitArg + Group(item.leaveWhitespace() | source.leaveWhitespace() | implicitStringBit))('implicitArg')) argumentList = Optional( White()).suppress() + ZeroOrMore(explicitArg | implicitArg) #### ITEM item <<= Group(lBrace + Optional(Word('^'))('carrots') +
# [96] PathOneInPropertySet ::= iri | A | '^' ( iri | A ) PathOneInPropertySet = iri | A | Comp('InversePath', '^' + (iri | A)) Path = Forward() # [95] PathNegatedPropertySet ::= PathOneInPropertySet | '(' ( PathOneInPropertySet ( '|' PathOneInPropertySet )* )? ')' PathNegatedPropertySet = Comp('PathNegatedPropertySet', ParamList('part', PathOneInPropertySet) | '(' + Optional( ParamList('part', PathOneInPropertySet) + ZeroOrMore('|' + ParamList('part', PathOneInPropertySet))) + ')') # [94] PathPrimary ::= iri | A | '!' PathNegatedPropertySet | '(' Path ')' | 'DISTINCT' '(' Path ')' PathPrimary = iri | A | Suppress('!') + PathNegatedPropertySet | Suppress('(') + Path + Suppress( ')') | Comp('DistinctPath', Keyword('DISTINCT') + '(' + Param('part', Path) + ')') # [91] PathElt ::= PathPrimary Optional(PathMod) PathElt = Comp('PathElt', Param( 'part', PathPrimary) + Optional(Param('mod', PathMod.leaveWhitespace()))) # [92] PathEltOrInverse ::= PathElt | '^' PathElt PathEltOrInverse = PathElt | Suppress( '^') + Comp('PathEltOrInverse', Param('part', PathElt)) # [90] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )* PathSequence = Comp('PathSequence', ParamList('part', PathEltOrInverse) + ZeroOrMore('/' + ParamList('part', PathEltOrInverse))) # [89] PathAlternative ::= PathSequence ( '|' PathSequence )* PathAlternative = Comp('PathAlternative', ParamList('part', PathSequence) + ZeroOrMore('|' + ParamList('part', PathSequence))) # [88] Path ::= PathAlternative
cond_in_rule.leaveWhitespace() cond_regex_rule = variable + ' ~ ' + delimitedList(Word(printables), delim=' ', combine=True) cond_regex_rule.setParseAction(lambda t: [RegexCondition(t[0], t[2])]) cond_regex_rule.leaveWhitespace() cond_regex_neg_rule = variable + ' !~ ' + delimitedList(Word(printables), delim=' ', combine=True) cond_regex_neg_rule.setParseAction(lambda t: [RegexNegatedCondition(t[0], t[2])]) cond_regex_neg_rule.leaveWhitespace() closed_rule = condition_rule ^ unequal_condition_rule ^ cond_gt_rule ^ cond_ge_rule ^ cond_lt_rule ^ \ cond_le_rule ^ cond_in_rule ^ cond_regex_rule ^ cond_regex_neg_rule ^ ('(' + rule + ')') closed_rule.setParseAction(lambda t: [t[1]] if len(t) == 3 else t) not_rule = Literal('not ') + closed_rule not_rule.leaveWhitespace() not_rule.setParseAction(lambda t: [NotRule(t[1])]) equivalence_rule = closed_rule + splitter + '<==>' + splitter + closed_rule equivalence_rule.leaveWhitespace() equivalence_rule.setParseAction(lambda t: [EquivalenceRule(t[0], t[4])]) implication_rule = closed_rule + splitter + '==>' + splitter + closed_rule implication_rule.leaveWhitespace() implication_rule.setParseAction(lambda t: [ImplicationRule(t[0], t[4])]) and_rule = closed_rule + ZeroOrMore(splitter + 'and' + splitter + closed_rule) and_rule.setParseAction(lambda t: [AndRule([t[i] for i in range(len(t)) if i % 4 == 0])]) and_rule.leaveWhitespace() or_rule = closed_rule + ZeroOrMore(splitter + 'or' + splitter + closed_rule)
+ ")", ) # [94] PathPrimary ::= iri | A | '!' PathNegatedPropertySet | '(' Path ')' | 'DISTINCT' '(' Path ')' PathPrimary = ( iri | A | Suppress("!") + PathNegatedPropertySet | Suppress("(") + Path + Suppress(")") | Comp("DistinctPath", Keyword("DISTINCT") + "(" + Param("part", Path) + ")") ) # [91] PathElt ::= PathPrimary Optional(PathMod) PathElt = Comp( "PathElt", Param("part", PathPrimary) + Optional(Param("mod", PathMod.leaveWhitespace())), ) # [92] PathEltOrInverse ::= PathElt | '^' PathElt PathEltOrInverse = PathElt | Suppress("^") + Comp( "PathEltOrInverse", Param("part", PathElt) ) # [90] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )* PathSequence = Comp( "PathSequence", ParamList("part", PathEltOrInverse) + ZeroOrMore("/" + ParamList("part", PathEltOrInverse)), )
Token, White, Word, ZeroOrMore, \ alphas, alphas8bit, alphanums, hexnums, nums, printables from testbin.parser import parseurl octet = [chr(i) for i in range(0, 256)] OCTET = oneOf(octet) ctl = [chr(i) for i in range(0, 32)] ctl.append(chr(127)) CTL = oneOf(ctl) CR = "\r" LF = "\n" CRLF = CR + LF SP = ' ' HTAB = '\t' WSP = Literal(HTAB) ^ Literal(SP) WSP.leaveWhitespace() LWS = Optional(ZeroOrMore(WSP) + CRLF) + OneOrMore(WSP) LWS.leaveWhitespace() SWS = Optional(LWS) SWS.leaveWhitespace() ICAP_Version = Literal("ICAP/1.0") Token = Word(alphas) Extension_Method = Token Method = Literal("REQMOD") ^ Literal("RESPMOD") ^ Literal("OPTIONS") ^ \ Extension_Method Scheme = Literal("icap") Host = parseurl.host Port = parseurl.port User_Info = parseurl.user + Optional(Literal(":") + parseurl.password) Authority = Optional(User_Info + "@") + Host + Optional(":" + Port)