Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getToken(self):
return QuotedString(self.texStart,
endQuoteChar=self.texEnd,
multiline=True,
convertWhitespaceEscapes=False).setParseAction(self.makeTexEquation)("inlinetex")
def getToken(self):
return QuotedString(CommentToken.start,
endQuoteChar=CommentToken.end,
multiline=True,
convertWhitespaceEscapes=False)("comment")
def generate_visualmin():
visualmin = p.QuotedString(quoteChar="-V/", unquoteResults=True, endQuoteChar="/")
visualmin.setParseAction(lambda x: ["-V", x[0]])
return visualmin
def getToken(self):
return (QuotedString(BoldToken.start_1,
endQuoteChar=BoldToken.end_1,
multiline=True,
convertWhitespaceEscapes=False) |
QuotedString(BoldToken.start_2,
endQuoteChar=BoldToken.end_2,
multiline=True,
convertWhitespaceEscapes=False)).addCondition(self.checkBreaks)("bold")
alphlatinB = pp.pyparsing_unicode.LatinB.alphas
rex = pp.Word(simplerex) |\
pp.Word(alphcyrillic) |\
pp.Word(alphgreek) |\
pp.Word(alphchinese) |\
pp.Word(alpharabic) |\
pp.Word(alphdevanagari) |\
pp.Word(alphhebrew) |\
pp.Word(alphjapanese) |\
pp.Word(alphkorean) |\
pp.Word(alphlatin1) |\
pp.Word(alphlatinA) |\
pp.Word(alphlatinB) |\
pp.QuotedString("\"", escChar='\\') |\
pp.QuotedString("'", escChar='\\')
for klass in filter_rex:
f = pp.Literal("~%s" % klass.code) + pp.WordEnd() + rex.copy()
f.setParseAction(klass.make)
parts.append(f)
for klass in filter_int:
f = pp.Literal("~%s" % klass.code) + pp.WordEnd() + pp.Word(pp.nums)
f.setParseAction(klass.make)
parts.append(f)
# A naked rex is a URL rex:
f = rex.copy()
f.setParseAction(FUrl.make)
parts.append(f)
def _build_tgrep_parser(set_parse_actions=True):
'''
Builds a pyparsing-based parser object for tokenizing and
interpreting tgrep search strings.
'''
tgrep_op = pyparsing.Optional('!') + pyparsing.Regex('[$%,.<>][%,.<>0-9-\':]*')
tgrep_qstring = pyparsing.QuotedString(
quoteChar='"', escChar='\\', unquoteResults=False
)
tgrep_node_regex = pyparsing.QuotedString(
quoteChar='/', escChar='\\', unquoteResults=False
)
tgrep_qstring_icase = pyparsing.Regex('i@\\"(?:[^"\\n\\r\\\\]|(?:\\\\.))*\\"')
tgrep_node_regex_icase = pyparsing.Regex('i@\\/(?:[^/\\n\\r\\\\]|(?:\\\\.))*\\/')
tgrep_node_literal = pyparsing.Regex('[^][ \r\t\n;:.,&|<>()$!@%\'^=]+')
tgrep_expr = pyparsing.Forward()
tgrep_relations = pyparsing.Forward()
tgrep_parens = pyparsing.Literal('(') + tgrep_expr + ')'
tgrep_nltk_tree_pos = (
pyparsing.Literal('N(')
+ pyparsing.Optional(
pyparsing.Word(pyparsing.nums)
+ ','
self.args = args
def __iter__(self):
right = [""] if self.args.right == "" else self.args.right
for middle_part in self.args.middle:
for right_part in right:
yield str(self.args.left) + middle_part + right_part
special_chars = "|&\"'<>{},"
bare_chars = "".join(sorted(set(parse.srange("[a-zA-Z0-9]") +
string.punctuation)
- set(special_chars)))
word = (parse.Word(bare_chars) | parse.QuotedString(quoteChar='"')) \
.setParseAction(lambda text, loc, args: Word(args[0]))
integer = (parse.Optional("-") + parse.Word(parse.nums)) \
.setParseAction(lambda text, loc, args: int("".join(args)))
integer_range = (integer + ".." + integer) \
.setParseAction(lambda text, loc, args: IntegerRange(args))
character_range = (
parse.Word(parse.alphas, max=1) + ".." + parse.Word(parse.alphas, max=1)) \
.setParseAction(lambda text, loc, args: CharacterRange(args))
range_ = integer_range | character_range
brace = parse.Forward()
multiple_operators = (u"and", u"or", u"∧", u"∨")
operator = pyparsing.Regex(u"|".join(binary_operator))
null = pyparsing.Regex("None|none|null").setParseAction(
pyparsing.replaceWith(None))
boolean = "False|True|false|true"
boolean = pyparsing.Regex(boolean).setParseAction(
lambda t: t[0].lower() == "true")
hex_string = lambda n: pyparsing.Word(pyparsing.hexnums, exact=n)
uuid_string = pyparsing.Combine(
hex_string(8) + (pyparsing.Optional("-") + hex_string(4)) * 3 +
pyparsing.Optional("-") + hex_string(12))
number = r"[+-]?\d+(:?\.\d*)?(:?[eE][+-]?\d+)?"
number = pyparsing.Regex(number).setParseAction(lambda t: float(t[0]))
identifier = pyparsing.Word(pyparsing.alphas, pyparsing.alphanums + "_")
quoted_string = pyparsing.QuotedString('"') | pyparsing.QuotedString("'")
comparison_term = pyparsing.Forward()
in_list = pyparsing.Group(
pyparsing.Suppress('[') +
pyparsing.Optional(pyparsing.delimitedList(comparison_term)) +
pyparsing.Suppress(']'))("list")
comparison_term << (null | boolean | uuid_string | identifier | number |
quoted_string | in_list)
condition = pyparsing.Group(comparison_term + operator + comparison_term)
expr = pyparsing.infixNotation(condition, [
("not", 1, pyparsing.opAssoc.RIGHT, ),
("and", 2, pyparsing.opAssoc.LEFT, ),
("∧", 2, pyparsing.opAssoc.LEFT, ),
("or", 2, pyparsing.opAssoc.LEFT, ),
("∨", 2, pyparsing.opAssoc.LEFT, ),
])
quotedIdentifier = pattern('quotedIdentifier', p.QuotedString('`', multiline=False))
# - Must start with an alphascore
# - May contain alphanumericscores and special characters such as : and -
# - Must not end in a special character
identifier = pattern('identifier', parseWithLocation(quotedIdentifier | p.Regex(r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'), Identifier))
# Variable identifier (can't be any of the keywords, which may have lower matching priority)
variable = pattern('variable', ~p.MatchFirst(p.oneOf(keywords)) + pattern('identifier', parseWithLocation(identifier.copy(), Var)))
# Contants
integer = pattern('integer', parseWithLocation(p.Word(p.nums), convertAndMake(int, Literal)))
floating = pattern('floating', parseWithLocation(p.Regex(r'\d*\.\d+'), convertAndMake(float, Literal)))
dq_string = pattern('dq_string', parseWithLocation(p.QuotedString('"', escChar='\\', unquoteResults=False, multiline=True), convertAndMake(unquote, Literal)))
sq_string = pattern('sq_string', parseWithLocation(p.QuotedString("'", escChar='\\', unquoteResults=False, multiline=True), convertAndMake(unquote, Literal)))
boolean = pattern('boolean', parseWithLocation(p.Keyword('true') | p.Keyword('false'), convertAndMake(mkBool, Literal)))
null = pattern('null', parseWithLocation(p.Keyword('null'), Null))
# List
list_ = pattern('list', parseWithLocation(bracketedList('[', ']', ',', expression), List))
# Tuple
inherit = pattern('inherit', (kw('inherit') - p.ZeroOrMore(variable)).setParseAction(inheritNodes))
schema_spec = pattern('schema_spec', parseWithLocation(p.Optional(p.Keyword('private').setParseAction(lambda: True), default=False)
- p.Optional(p.Keyword('required').setParseAction(lambda: True), default=False)
- p.Optional(expression, default=any_schema_expr), MemberSchemaNode))
optional_schema = pattern('optional_schema', p.Optional(p.Suppress(':') - schema_spec, default=no_schema))
expression_value = pattern('expression_value', sym('=') - swallow_errors(expression))
void_value = pattern('void_value', parseWithLocation(p.FollowedBy(sym(';') | sym('}')), lambda loc: Void(loc, 'nonameyet')))
member_value = pattern('member_value', swallow_errors(expression_value | void_value))
except ValueError, e:
raise pp.ParseFatalException(s,l,e.args[0])
return changeScopeAction
### BASE PARSERS
LPAR = pp.Literal("(").suppress()
RPAR = pp.Literal(")").suppress()
self.subparsers["SymbolParser"] = pp.Word("".join([ c for c in string.printable if c not in string.whitespace and c not in "\"'()&?|<~;" ]),
"".join([ c for c in string.printable if c not in string.whitespace and c not in "\"'()&?|<~;" ]))\
.setParseAction(makeInstance(types.Symbol))
self.subparsers["StringParser"] = pp.QuotedString('"', '\\', None, True, True)\
.setParseAction(makeInstance(types.String))
# StringParser alias
self.subparsers["CommentParser"] = self.subparsers["StringParser"]
self.subparsers["IntegerParser"] = pp.Combine(pp.Optional(pp.oneOf('+ -')) + pp.Word(pp.nums))\
.setParseAction(makeInstance(types.Integer))
# try to cast to Integer first, otherwise Float
self.subparsers["FloatParser"] = pp.Regex(r'[+-]?\d+(\.\d*)?([eE]-?\d+)?')\
.setParseAction(tryInstance(types.Integer, types.Float))
self.subparsers["VariableSymbolParser"] = pp.Word(string.letters, "".join([ c for c in string.printable if c not in string.whitespace and c not in "*\"'()&?|<~;" ]))\
.setParseAction(makeInstance(types.Symbol))
self.subparsers["NumberParser"] = (self.getSParser("FloatParser") ^ self.getSParser("IntegerParser"))\
.setParseAction(forwardParsed())