Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
g(resolved_type_specifier) + identifier | \
g(resolved_type_specifier) + lit('*') + identifier
fielddocumentation = \
s("{") + (P.Optional(g(kw("key") + identifier + s(";"))) & \
P.Optional(g(kw("name") + P.QuotedString('"') + s(";"))) & \
P.Optional(g(kw("unit") + P.QuotedString('"') + s(";"))) & \
P.Optional(g(kw("offset") + decimal_constant + s(";"))) & \
P.Optional(g(kw("divisor") + decimal_constant + s(";"))) & \
P.Optional(g(kw("description") + P.QuotedString('"') + s(";"))) \
) + s("}")
const_expr_value = constant | scopedidentifier
constant_expr = (const_expr_value + (kw('+') | kw('-')) + const_expr_value) | const_expr_value
enum_body = s("{") + g(P.delimitedList(g(enumValueIdentifier + s('=') + constant_expr))) + s("}")
struct_body << s("{") + P.OneOrMore(g(declaration + g(P.Optional(fielddocumentation)) + s(";"))) + s("}")
constant_def = kw("const") - scopedUpperIdentifier - s("=") - constant - s(";")
namespace_def = kw("namespace") - identifier - s(";")
namespace_def.setParseAction(self.namespaceParse)
struct_def = kw("struct") - newscopedidentifier - g(struct_body) + P.Optional(s('=') - type_name) - s(";")
struct_def.setParseAction(self.newStruct)
command_options = \
P.Optional(g(kw("summary") + P.QuotedString('"') + s(";"))) & \
P.Optional(g(kw("param") + type_name + s(";"))) & \
P.Optional(g(kw("types") + s("=") + g(type_name + P.ZeroOrMore(s(',') + type_name)) + s(";"))) & \
P.Optional(g(kw("response") + g(type_name + P.ZeroOrMore(s(',') + type_name)) + s(";")))
if broadcast == "enable":
si.traffic_control_broadcast = True
if multicast == "enable":
si.traffic_control_multicast = True
if unicast == "enable":
si.traffic_control_unicast = True
# Port expression parser
DIGITS = Word(nums)
PORT = Combine(DIGITS + Optional(Literal(":") + DIGITS))
# 1:(2,3,10-20)
PORT_RANGE_PT = Group(
DIGITS
+ Literal(":(")
+ delimitedList(Group(DIGITS + Suppress(Literal("-")) + DIGITS) | DIGITS, delim=",")
+ Suppress(Literal(")"))
)
# 1:2-1:5
PORT_RANGE = Group(PORT + Suppress(Literal("-")) + PORT)
# Port expression
PORT_EXPR = delimitedList(PORT_RANGE_PT | PORT_RANGE | PORT, delim=",")
)
)
ordered_sql << Group(
Group(Group(
unordered_sql +
ZeroOrMore((UNION_ALL | UNION) + unordered_sql)
)("union"))("from") +
Optional(ORDER_BY.suppress().setDebugActions(*debug) + delimitedList(Group(sortColumn))("orderby").setName("orderby")) +
Optional(LIMIT.suppress().setDebugActions(*debug) + expr("limit")) +
Optional(OFFSET.suppress().setDebugActions(*debug) + expr("offset"))
).addParseAction(to_union_call)
statement = Group(Group(Optional(
WITH.suppress().setDebugActions(*debug) +
delimitedList(
Group(
ident("name").setDebugActions(*debug) +
AS.suppress().setDebugActions(*debug) +
Literal("(").suppress().setDebugActions(*debug) +
ordered_sql("value").setDebugActions(*debug) +
Literal(")").suppress().setDebugActions(*debug)
)
)
))("with") + ordered_sql("query")).addParseAction(to_with_clause)
SQLParser = statement
# IGNORE SOME COMMENTS
oracleSqlComment = Literal("--") + restOfLine
mySqlComment = Literal("#") + restOfLine
SQLParser.ignore(oracleSqlComment | mySqlComment)
x||=
x||=
x||=
x||=
x||=
x||=
x||=
x||=
x||=
"""
portRef = subscrIdentifier
portExpr = portRef | Group( "{" + delimitedList( portRef ) + "}" )
port = portExpr | Group( ( "." + identifier + "(" + portExpr + ")" ) )
moduleHdr = Group ( oneOf("module macromodule") + identifier("moduleName").setParseAction(parseModule) +
Optional( "(" + Group( Optional( delimitedList(
Group(oneOf("input output") +
(netDecl1Arg | netDecl2Arg | netDecl3Arg) ) |
port ) ) ) +
")" ) + semi ).setName("moduleHdr")
module = Group( moduleHdr +
Group( ZeroOrMore( moduleItem ) ) +
"endmodule" ).setName("module")#.setDebug()
udpDecl = outputDecl | inputDecl | regDecl
#~ udpInitVal = oneOf("1'b0 1'b1 1'bx 1'bX 1'B0 1'B1 1'Bx 1'BX 1 0 x X")
udpInitVal = (Regex("1'[bB][01xX]") | Regex("[01xX]")).setName("udpInitVal")
udpInitialStmt = Group( "initial" +
identifier + "=" + udpInitVal + semi ).setName("udpInitialStmt")
levelSymbol = oneOf("0 1 x X ? b B")
LPAR = pparse.Literal("(")
RPAR = pparse.Literal(")")
LIT_ARRAY_START = pparse.Literal("[") | pparse.Literal("(/")
LIT_ARRAY_END = pparse.Literal("]") | pparse.Literal("/)")
EXPR = pparse.Forward()
# Array slicing
COLON = pparse.Literal(":")
SLICING = pparse.Optional(EXPR) + COLON + pparse.Optional(EXPR) + \
pparse.Optional(COLON+pparse.Optional(EXPR))
SLICING.setParseAction(lambda strg, loc, toks: [Slicing(toks)])
VAR_OR_FUNCTION = (DERIVED_TYPE_COMPONENT | NAME) + pparse.Optional(
LPAR + pparse.Optional(pparse.delimitedList(SLICING | EXPR)) + RPAR)
VAR_OR_FUNCTION.setParseAction(lambda strg, loc, toks: [FunctionVar(toks)])
LITERAL_ARRAY = LIT_ARRAY_START + pparse.delimitedList(EXPR) + LIT_ARRAY_END
LITERAL_ARRAY.setParseAction(lambda strg, loc, toks: [LiteralArray(toks)])
# An optional/named argument. We use QuotedString here to avoid versioning
# problems with the interface to {sgl,dbl}QuotedString in pyparsing.
OPTIONAL_VAR = VAR_NAME + "=" + ((NAME | REAL | INTEGER) |
pparse.QuotedString("'",
unquoteResults=False) |
pparse.QuotedString('"',
unquoteResults=False))
# lambda creates a temporary function which, in this case, takes three
# arguments and creates a NamedArg object.
OPTIONAL_VAR.setParseAction(lambda strg, loc, toks: [NamedArg(toks)])
def split_by_commas(value):
"""Split values by commas and quotes according to api-wg
:param value: value to be split
.. versionadded:: 3.17
"""
word = (pp.QuotedString(quoteChar='"', escChar='\\')
| pp.Word(pp.printables, excludeChars='",'))
grammar = pp.stringStart + pp.delimitedList(word) + pp.stringEnd
try:
return list(grammar.parseString(value))
except pp.ParseException:
raise ValueError("Invalid value: %s" % value)
def braced_list(element_rule):
return Suppress('{') + Group(delimitedList(element_rule)) + Suppress('}')
udTypeName = delimitedList( identifier, "::", combine=True ).setName("udType")
# have to use longest match for type, in case a user-defined type name starts with a keyword type, like "stringSeq" or "longArray"
typeName = ( any_ ^ boolean_ ^ char_ ^ double_ ^ fixed_ ^
float_ ^ long_ ^ octet_ ^ short_ ^ string_ ^
wchar_ ^ wstring_ ^ udTypeName ).setName("type")
sequenceDef = Forward().setName("seq")
sequenceDef << Group( sequence_ + langle + ( sequenceDef | typeName ) + rangle )
typeDef = sequenceDef | ( typeName + Optional( lbrack + integer + rbrack ) )
typedefDef = Group( typedef_ + typeDef + identifier + semi ).setName("typedef")
moduleDef = Forward()
constDef = Group( const_ + typeDef + identifier + equals + ( real | integer | quotedString ) + semi ) #| quotedString )
exceptionItem = Group( typeDef + identifier + semi )
exceptionDef = ( exception_ + identifier + lbrace + ZeroOrMore( exceptionItem ) + rbrace + semi )
attributeDef = Optional( readonly_ ) + attribute_ + typeDef + identifier + semi
paramlist = delimitedList( Group( ( inout_ | in_ | out_ ) + typeName + identifier ) ).setName( "paramlist" )
operationDef = ( ( void_ ^ typeDef ) + identifier + lparen + Optional( paramlist ) + rparen + \
Optional( raises_ + lparen + Group( delimitedList( typeName ) ) + rparen ) + semi )
interfaceItem = ( constDef | exceptionDef | attributeDef | operationDef )
interfaceDef = Group( interface_ + identifier + Optional( colon + delimitedList( typeName ) ) + lbrace + \
ZeroOrMore( interfaceItem ) + rbrace + semi ).setName("opnDef")
moduleItem = ( interfaceDef | exceptionDef | constDef | typedefDef | moduleDef )
moduleDef << module_ + identifier + lbrace + ZeroOrMore( moduleItem ) + rbrace + semi
bnf = ( moduleDef | OneOrMore( moduleItem ) )
singleLineComment = "//" + restOfLine
bnf.ignore( singleLineComment )
bnf.ignore( cStyleComment )
return bnf
#The '=QString()' or '=false' bit in (int foo = 4, bool bar = false)
default_value = Literal('=') + OneOrMore(number | quotedString | input_type | parentheses_pair | angle_bracket_pair | square_bracket_pair | Word('|&^'))
#A combination building up the interesting bit -- the argument type, e.g. 'const QString &', 'int' or 'char*'
argument_type = Optional(qualifier, default='')("qualifier") + \
input_type("input_type") + \
Optional(pointer_or_reference, default='')("pointer_or_reference1") + \
Optional('const')('const_pointer_or_reference') + \
Optional(pointer_or_reference, default='')("pointer_or_reference2")
#Argument + variable name + default
argument = Group(argument_type('argument_type') + Optional(input_name) + Optional(default_value))
#List of arguments in parentheses with an optional 'const' on the end
arglist = LPAR + delimitedList(argument)('arg_list') + Optional(COMMA + '...')('var_args') + RPAR
def normalise(symbol):
"""
Takes a c++ symbol or function and splits it into symbol and a normalised argument list.
:Parameters:
symbol : string
A C++ symbol or function definition like ``PolyVox::Volume``, ``Volume::printAll() const``
:return:
a tuple consisting of two strings: ``(qualified function name or symbol, normalised argument list)``
"""
try:
bracket_location = symbol.index('(')
#Split the input string into everything before the opening bracket and everything else
def getLogLineBNF():
global logLineBNF
if logLineBNF is None:
integer = Word( nums )
ipAddress = delimitedList( integer, ".", combine=True )
timeZoneOffset = Word("+-",nums)
month = Word(string.uppercase, string.lowercase, exact=3)
serverDateTime = Group( Suppress("[") + Combine( integer + "/" + month + "/" + integer + ":" + integer + ":" + integer + ":" + integer ) + timeZoneOffset + Suppress("]") )
logLineBNF = ( ipAddress.setResultsName("ipAddr") +
Suppress("-") +
("-" | Word( alphas+nums+"@._" )).setResultsName("auth") +
serverDateTime.setResultsName("timestamp") +
dblQuotedString.setResultsName("cmd").setParseAction(getCmdFields) +
(integer | "-").setResultsName("statusCode") +
(integer | "-").setResultsName("numBytesSent") +
dblQuotedString.setResultsName("referer").setParseAction(removeQuotes) +
dblQuotedString.setResultsName("userAgent").setParseAction(removeQuotes) +
(integer | "-").setResultsName("numDurationTime"))
return logLineBNF