OXIESEC PANEL
- Current Dir:
/
/
opt
/
gsutil
/
third_party
/
pyparsing
/
examples
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
12/11/2024 09:39:44 AM
rwxr-xr-x
📄
0README.html
10.75 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
AcManForm.dfm
38.22 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
LAparser.py
20.62 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
Setup.ini
1.41 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
SimpleCalc.py
3.58 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
SingleForm.dfm
42.7 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
TAP.py
7.42 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
__init__.py
0 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
adventureEngine.py
21.59 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
antlr_grammar.py
10.88 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
antlr_grammar_tests.py
2.89 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
apicheck.py
2.2 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
bf.py
4.15 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
bigquery_view_parser.py
62.51 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
booleansearchparser.py
15.26 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
btpyparse.py
4.16 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
builtin_parse_action_demo.py
817 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
cLibHeader.py
853 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
chemical_formulas.py
3.17 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
commasep.py
707 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
configParse.py
2 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
cpp_enum_parser.py
1.35 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
cuneiform_python.py
2.57 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
datetime_parse_actions.py
1.9 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
decaf_parser.py
6.87 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
delta_time.py
21.49 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
dfmparse.py
7.05 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
dhcpd_leases_parser.py
2.98 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
dictExample.py
1.73 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
dictExample2.py
2.1 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
directx_x_file_parser.py
5.54 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
ebnf.py
4.15 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
ebnftest.py
2.35 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
email_address_parser.py
1.18 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
eval_arith.py
6.15 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
excel_expr.py
2.2 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
fourFn.py
10.27 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
gen_ctypes.py
5.28 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
getNTPserversNew.py
1.11 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
greeting.py
518 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
greetingInGreek.py
425 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
greetingInKorean.py
495 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
groupUsingListAllMatches.py
509 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
hola_mundo.py
2.02 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
html_stripper.py
1.68 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
html_table_parser.py
2.16 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
httpServerLogParser.py
3.48 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
idlParse.py
7.53 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
include_preprocessor.py
2.63 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
indentedGrammarExample.py
1022 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
indented_block_example.py
712 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
inv_regex.py
8.08 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
javascript_grammar.g
18.1 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
jsonParser.py
4.7 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
left_recursion.py
1.41 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
lineno_example.py
1.49 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
listAllMatches.py
1.57 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
lua_parser.py
7.96 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
lucene_grammar.py
8.46 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
macro_expander.py
1.77 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
make_diagram.py
1.62 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
matchPreviousDemo.py
586 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
mongodb_query_expression.py
8.46 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
mozilla.ics
752 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
mozillaCalendarParser.py
2.71 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
nested.py
579 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
nested_markup.py
1.85 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
number_words.py
3.77 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
numerics.py
1.34 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
oc.py
4.34 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
one_to_ninety_nine.py
1.88 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
parseTabularData.py
1.68 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
parse_python_value.py
2.5 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
parse_results_sum_example.py
853 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
partial_gene_match.py
2.33 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
pgn.py
3.34 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
position.py
2.17 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
protobuf_parser.py
3.89 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
pythonGrammarParser.py
8.08 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
railroad_diagram_demo.py
1.55 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
range_check.py
2.84 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
readJson.py
120.73 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
removeLineBreaks.py
1.8 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
roman_numerals.py
3.57 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
rosettacode.py
7.43 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
scanExamples.py
2.36 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
searchParserAppDemo.py
962 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
searchparser.py
10.4 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
select_parser.py
8.32 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
sexpParser.py
5.23 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
shapes.py
1.69 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
simpleArith.py
2.42 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
simpleBool.py
3.19 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
simpleSQL.py
3.16 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
simpleWiki.py
1.08 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
snmp_api.h
28.69 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
sql2dot.py
3.07 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
stackish.py
2.71 KB
08/25/2024 02:43:42 PM
rw-r--r--
📁
statemachine
-
08/25/2024 02:43:42 PM
rwxr-xr-x
📄
tag_emitter.py
1.17 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
tag_metadata.py
805 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
test_bibparse.py
8.72 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
unicode_denormalizer.py
5.02 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
urlExtractor.py
1.03 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
urlExtractorNew.py
2.4 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
verilog_parse.py
31.15 KB
08/25/2024 02:43:42 PM
rw-r--r--
📄
withAttribute.py
912 bytes
08/25/2024 02:43:42 PM
rw-r--r--
📄
wordsToNum.py
2.92 KB
08/25/2024 02:43:42 PM
rw-r--r--
Editing: antlr_grammar.py
Close
""" antlr_grammar.py Created on 4 sept. 2010 @author: luca Submitted by Luca DallOlio, September, 2010 (Minor updates by Paul McGuire, June, 2012) (Code idiom updates by Paul McGuire, April, 2019) """ from pyparsing import ( Word, ZeroOrMore, printables, Suppress, OneOrMore, Group, LineEnd, Optional, White, originalTextFor, hexnums, nums, Combine, Literal, Keyword, cStyleComment, Regex, Forward, MatchFirst, And, oneOf, alphas, alphanums, delimitedList, Char, ) # http://www.antlr.org/grammar/ANTLR/ANTLRv3.g ( QUOTE, APOS, EQ, LBRACK, RBRACK, LBRACE, RBRACE, LPAR, RPAR, ROOT, BANG, AT, TIL, SEMI, COLON, VERT, ) = map(Suppress, "\"'=[]{}()^!@~;:|") BSLASH = Literal("\\") keywords = ( SRC_, SCOPE_, OPTIONS_, TOKENS_, FRAGMENT, ID, LEXER, PARSER, GRAMMAR, TREE, CATCH, FINALLY, THROWS, PROTECTED, PUBLIC, PRIVATE, ) = map( Keyword, """src scope options tokens fragment id lexer parser grammar tree catch finally throws protected public private """.split(), ) KEYWORD = MatchFirst(keywords) # Tokens EOL = Suppress(LineEnd()) # $ SGL_PRINTABLE = Char(printables) singleTextString = originalTextFor( ZeroOrMore(~EOL + (White(" \t") | Word(printables))) ).leaveWhitespace() XDIGIT = hexnums INT = Word(nums) ESC = BSLASH + ( oneOf(list(r"nrtbf\">" + "'")) | ("u" + Word(hexnums, exact=4)) | SGL_PRINTABLE ) LITERAL_CHAR = ESC | ~(APOS | BSLASH) + SGL_PRINTABLE CHAR_LITERAL = APOS + LITERAL_CHAR + APOS STRING_LITERAL = APOS + Combine(OneOrMore(LITERAL_CHAR)) + APOS DOUBLE_QUOTE_STRING_LITERAL = '"' + ZeroOrMore(LITERAL_CHAR) + '"' DOUBLE_ANGLE_STRING_LITERAL = "<<" + ZeroOrMore(SGL_PRINTABLE) + ">>" TOKEN_REF = Word(alphas.upper(), alphanums + "_") RULE_REF = Word(alphas.lower(), alphanums + "_") ACTION_ESC = ( BSLASH.suppress() + APOS | BSLASH.suppress() | BSLASH.suppress() + (~(APOS | QUOTE) + SGL_PRINTABLE) ) ACTION_CHAR_LITERAL = APOS + (ACTION_ESC | ~(BSLASH | APOS) + SGL_PRINTABLE) + APOS ACTION_STRING_LITERAL = ( QUOTE + ZeroOrMore(ACTION_ESC | ~(BSLASH | QUOTE) + SGL_PRINTABLE) + QUOTE ) SRC = SRC_.suppress() + ACTION_STRING_LITERAL("file") + INT("line") id = TOKEN_REF | RULE_REF SL_COMMENT = ( Suppress("//") + Suppress("$ANTLR") + SRC | ZeroOrMore(~EOL + Word(printables)) + EOL ) ML_COMMENT = cStyleComment WS = OneOrMore( Suppress(" ") | Suppress("\t") | (Optional(Suppress("\r")) + Literal("\n")) ) WS_LOOP = ZeroOrMore(SL_COMMENT | ML_COMMENT) NESTED_ARG_ACTION = Forward() NESTED_ARG_ACTION << ( LBRACK + ZeroOrMore(NESTED_ARG_ACTION | ACTION_STRING_LITERAL | ACTION_CHAR_LITERAL) + RBRACK ) ARG_ACTION = NESTED_ARG_ACTION NESTED_ACTION = Forward() NESTED_ACTION << ( LBRACE + ZeroOrMore( NESTED_ACTION | SL_COMMENT | ML_COMMENT | ACTION_STRING_LITERAL | ACTION_CHAR_LITERAL ) + RBRACE ) ACTION = NESTED_ACTION + Optional("?") SCOPE = SCOPE_.suppress() OPTIONS = OPTIONS_.suppress() + LBRACE # + WS_LOOP + Suppress('{') TOKENS = TOKENS_.suppress() + LBRACE # + WS_LOOP + Suppress('{') TREE_BEGIN = ROOT + LPAR RANGE = Suppress("..") REWRITE = Suppress("->") # General Parser Definitions # Grammar heading optionValue = id | STRING_LITERAL | CHAR_LITERAL | INT | Literal("*").setName("s") option = Group(id("id") + EQ + optionValue("value"))("option") optionsSpec = OPTIONS + Group(OneOrMore(option + SEMI))("options") + RBRACE tokenSpec = ( Group(TOKEN_REF("token_ref") + (EQ + (STRING_LITERAL | CHAR_LITERAL)("lit")))( "token" ) + SEMI ) tokensSpec = TOKENS + Group(OneOrMore(tokenSpec))("tokens") + RBRACE attrScope = SCOPE_.suppress() + id + ACTION grammarType = LEXER + PARSER + TREE actionScopeName = id | LEXER("l") | PARSER("p") action = AT + Optional(actionScopeName + Suppress("::")) + id + ACTION grammarHeading = ( Optional(ML_COMMENT("ML_COMMENT")) + Optional(grammarType) + GRAMMAR + id("grammarName") + SEMI + Optional(optionsSpec) + Optional(tokensSpec) + ZeroOrMore(attrScope) + ZeroOrMore(action) ) modifier = PROTECTED | PUBLIC | PRIVATE | FRAGMENT ruleAction = AT + id + ACTION throwsSpec = THROWS.suppress() + delimitedList(id) ruleScopeSpec = ( (SCOPE_.suppress() + ACTION) | (SCOPE_.suppress() + delimitedList(id) + SEMI) | (SCOPE_.suppress() + ACTION + SCOPE_.suppress() + delimitedList(id) + SEMI) ) unary_op = oneOf("^ !") notTerminal = CHAR_LITERAL | TOKEN_REF | STRING_LITERAL terminal = ( CHAR_LITERAL | TOKEN_REF + Optional(ARG_ACTION) | STRING_LITERAL | "." ) + Optional(unary_op) block = Forward() notSet = TIL + (notTerminal | block) rangeNotPython = CHAR_LITERAL("c1") + RANGE + CHAR_LITERAL("c2") atom = Group( (rangeNotPython + Optional(unary_op)("op")) | terminal | (notSet + Optional(unary_op)("op")) | (RULE_REF + Optional(ARG_ACTION("arg")) + Optional(unary_op)("op")) ) element = Forward() treeSpec = ROOT + LPAR + element * (2,) + RPAR ebnfSuffix = oneOf("? * +") ebnf = block + Optional(ebnfSuffix("op") | "=>") elementNoOptionSpec = ( (id("result_name") + oneOf("= +=")("labelOp") + atom("atom") + Optional(ebnfSuffix)) | (id("result_name") + oneOf("= +=")("labelOp") + block + Optional(ebnfSuffix)) | atom("atom") + Optional(ebnfSuffix) | ebnf | ACTION | (treeSpec + Optional(ebnfSuffix)) ) # | SEMPRED ( '=>' -> GATED_SEMPRED | -> SEMPRED ) element <<= Group(elementNoOptionSpec)("element") # Do not ask me why group is needed twice... seems like the xml that you see is not always the real structure? alternative = Group(Group(OneOrMore(element))("elements")) rewrite = Optional(Literal("TODO REWRITE RULES TODO")) block <<= ( LPAR + Optional(Optional(optionsSpec("opts")) + COLON) + Group( alternative("a1") + rewrite + Group(ZeroOrMore(VERT + alternative("a2") + rewrite))("alternatives") )("block") + RPAR ) altList = ( alternative("a1") + rewrite + Group(ZeroOrMore(VERT + alternative("a2") + rewrite))("alternatives") ) exceptionHandler = CATCH.suppress() + ARG_ACTION + ACTION finallyClause = FINALLY.suppress() + ACTION exceptionGroup = (OneOrMore(exceptionHandler) + Optional(finallyClause)) | finallyClause ruleHeading = ( Optional(ML_COMMENT)("ruleComment") + Optional(modifier)("modifier") + id("ruleName") + Optional("!") + Optional(ARG_ACTION("arg")) + Optional(Suppress("returns") + ARG_ACTION("rt")) + Optional(throwsSpec) + Optional(optionsSpec) + Optional(ruleScopeSpec) + ZeroOrMore(ruleAction) ) rule = Group(ruleHeading + COLON + altList + SEMI + Optional(exceptionGroup))("rule") grammarDef = grammarHeading + Group(OneOrMore(rule))("rules") def grammar(): return grammarDef def __antlrAlternativesConverter(pyparsingRules, antlrBlock): rule = None if ( hasattr(antlrBlock, "alternatives") and antlrBlock.alternatives != "" and len(antlrBlock.alternatives) > 0 ): alternatives = [] alternatives.append(__antlrAlternativeConverter(pyparsingRules, antlrBlock.a1)) for alternative in antlrBlock.alternatives: alternatives.append( __antlrAlternativeConverter(pyparsingRules, alternative) ) rule = MatchFirst(alternatives)("anonymous_or") elif hasattr(antlrBlock, "a1") and antlrBlock.a1 != "": rule = __antlrAlternativeConverter(pyparsingRules, antlrBlock.a1) else: raise Exception("Not yet implemented") assert rule != None return rule def __antlrAlternativeConverter(pyparsingRules, antlrAlternative): elementList = [] for element in antlrAlternative.elements: rule = None if hasattr(element.atom, "c1") and element.atom.c1 != "": regex = r"[" + str(element.atom.c1[0]) + "-" + str(element.atom.c2[0] + "]") rule = Regex(regex)("anonymous_regex") elif hasattr(element, "block") and element.block != "": rule = __antlrAlternativesConverter(pyparsingRules, element.block) else: ruleRef = element.atom[0] assert ruleRef in pyparsingRules rule = pyparsingRules[ruleRef](ruleRef) if hasattr(element, "op") and element.op != "": if element.op == "+": rule = Group(OneOrMore(rule))("anonymous_one_or_more") elif element.op == "*": rule = Group(ZeroOrMore(rule))("anonymous_zero_or_more") elif element.op == "?": rule = Optional(rule) else: raise Exception("rule operator not yet implemented : " + element.op) rule = rule elementList.append(rule) if len(elementList) > 1: rule = Group(And(elementList))("anonymous_and") else: rule = elementList[0] assert rule is not None return rule def __antlrRuleConverter(pyparsingRules, antlrRule): rule = None rule = __antlrAlternativesConverter(pyparsingRules, antlrRule) assert rule != None rule(antlrRule.ruleName) return rule def antlrConverter(antlrGrammarTree): pyparsingRules = {} antlrTokens = {} for antlrToken in antlrGrammarTree.tokens: antlrTokens[antlrToken.token_ref] = antlrToken.lit for antlrTokenName, antlrToken in list(antlrTokens.items()): pyparsingRules[antlrTokenName] = Literal(antlrToken) antlrRules = {} for antlrRule in antlrGrammarTree.rules: antlrRules[antlrRule.ruleName] = antlrRule pyparsingRules[antlrRule.ruleName] = Forward() # antlr is a top down grammar for antlrRuleName, antlrRule in list(antlrRules.items()): pyparsingRule = __antlrRuleConverter(pyparsingRules, antlrRule) assert pyparsingRule != None pyparsingRules[antlrRuleName] <<= pyparsingRule return pyparsingRules if __name__ == "__main__": text = """\ grammar SimpleCalc; options { language = Python; } tokens { PLUS = '+' ; MINUS = '-' ; MULT = '*' ; DIV = '/' ; } /*------------------------------------------------------------------ * PARSER RULES *------------------------------------------------------------------*/ expr : term ( ( PLUS | MINUS ) term )* ; term : factor ( ( MULT | DIV ) factor )* ; factor : NUMBER ; /*------------------------------------------------------------------ * LEXER RULES *------------------------------------------------------------------*/ NUMBER : (DIGIT)+ ; /* WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ; */ fragment DIGIT : '0'..'9' ; """ grammar().validate() antlrGrammarTree = grammar().parseString(text) print(antlrGrammarTree.dump()) pyparsingRules = antlrConverter(antlrGrammarTree) pyparsingRule = pyparsingRules["expr"] pyparsingTree = pyparsingRule.parseString("2 - 5 * 42 + 7 / 25") print(pyparsingTree.dump())