PATH: //opt/alt/python311/share/doc/alt-python311-pyparsing-doc/examples
FILE_BARU
CREATE
FOLDER_BARU
MKDIR
UPLOAD_FILE
GO
[ .. KEMBALI ]
๐ 0README.html
โ
X
๐ AcManForm.dfm
โ
X
๐ LAparser.py
โ
X
๐ Setup.ini
โ
X
๐ SimpleCalc.py
โ
X
๐ SingleForm.dfm
โ
X
๐ TAP.py
โ
X
๐ __init__.py
โ
X
๐ __pycache__/
X
๐ adventureEngine.py
โ
X
๐ antlr_grammar.py
โ
X
๐ antlr_grammar_tests.py
โ
X
๐ apicheck.py
โ
X
๐ bigquery_view_parser.py
โ
X
๐ booleansearchparser.py
โ
X
๐ btpyparse.py
โ
X
๐ builtin_parse_action_demo.py
โ
X
๐ cLibHeader.py
โ
X
๐ chemicalFormulas.py
โ
X
๐ commasep.py
โ
X
๐ configParse.py
โ
X
๐ cpp_enum_parser.py
โ
X
๐ cuneiform_python.py
โ
X
๐ datetimeParseActions.py
โ
X
๐ decaf_parser.py
โ
X
๐ delta_time.py
โ
X
๐ dfmparse.py
โ
X
๐ dhcpd_leases_parser.py
โ
X
๐ dictExample.py
โ
X
๐ dictExample2.py
โ
X
๐ ebnf.py
โ
X
๐ ebnftest.py
โ
X
๐ eval_arith.py
โ
X
๐ excelExpr.py
โ
X
๐ fourFn.py
โ
X
๐ gen_ctypes.py
โ
X
๐ getNTPserversNew.py
โ
X
๐ greeting.py
โ
X
๐ greetingInGreek.py
โ
X
๐ greetingInKorean.py
โ
X
๐ groupUsingListAllMatches.py
โ
X
๐ holaMundo.py
โ
X
๐ htmlStripper.py
โ
X
๐ htmlTableParser.py
โ
X
๐ httpServerLogParser.py
โ
X
๐ idlParse.py
โ
X
๐ include_preprocessor.py
โ
X
๐ indentedGrammarExample.py
โ
X
๐ indented_block_example.py
โ
X
๐ invRegex.py
โ
X
๐ javascript_grammar.g
โ
X
๐ jsonParser.py
โ
X
๐ left_recursion.py
โ
X
๐ linenoExample.py
โ
X
๐ listAllMatches.py
โ
X
๐ lua_parser.py
โ
X
๐ lucene_grammar.py
โ
X
๐ macroExpander.py
โ
X
๐ make_diagram.py
โ
X
๐ matchPreviousDemo.py
โ
X
๐ mozilla.ics
โ
X
๐ mozillaCalendarParser.py
โ
X
๐ nested.py
โ
X
๐ nested_markup.py
โ
X
๐ number_words.py
โ
X
๐ numerics.py
โ
X
๐ oc.py
โ
X
๐ one_to_ninety_nine.py
โ
X
๐ parsePythonValue.py
โ
X
๐ parseResultsSumExample.py
โ
X
๐ parseTabularData.py
โ
X
๐ partial_gene_match.py
โ
X
๐ pgn.py
โ
X
๐ position.py
โ
X
๐ protobuf_parser.py
โ
X
๐ pymicko.py
โ
X
๐ pythonGrammarParser.py
โ
X
๐ railroad_diagram_demo.py
โ
X
๐ rangeCheck.py
โ
X
๐ readJson.py
โ
X
๐ removeLineBreaks.py
โ
X
๐ romanNumerals.py
โ
X
๐ rosettacode.py
โ
X
๐ scanExamples.py
โ
X
๐ searchParserAppDemo.py
โ
X
๐ searchparser.py
โ
X
๐ select_parser.py
โ
X
๐ sexpParser.py
โ
X
๐ shapes.py
โ
X
๐ simpleArith.py
โ
X
๐ simpleBool.py
โ
X
๐ simpleSQL.py
โ
X
๐ simpleWiki.py
โ
X
๐ snmp_api.h
โ
X
๐ sparser.py
โ
X
๐ sql2dot.py
โ
X
๐ stackish.py
โ
X
๐ statemachine/
X
๐ test_bibparse.py
โ
X
๐ unicode_denormalizer.py
โ
X
๐ urlExtractor.py
โ
X
๐ urlExtractorNew.py
โ
X
๐ verilog/
X
๐ verilogParse.py
โ
X
๐ withAttribute.py
โ
X
๐ wordsToNum.py
โ
X
SAVING...
BERHASIL DIUBAH!
EDITING: unicode_denormalizer.py
# unicode_denormalizer.py # # Demonstration of the pyparsing's transform_string() method, to # convert identifiers in Python source code to equivalent Unicode # characters. Python's compiler automatically normalizes Unicode # characters back to their ASCII equivalents, so that identifiers may # be rewritten using other Unicode characters, and normalize back to # the same identifier. For instance, Python treats "print" and "๐ก๐ปแตข๐๐" # and "๐๐๐๐แต" all as the same identifier. # # The converter must take care to *only* transform identifiers - # Python keywords must always be represented in base ASCII form. To # skip over keywords, they are added to the parser/transformer, but # contain no transforming parse action. # # The converter also detects identifiers in placeholders within f-strings. # # Copyright 2022, by Paul McGuire # import keyword import random import unicodedata import pyparsing as pp ppu = pp.pyparsing_unicode ident_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789ยท" ident_char_map = {}.fromkeys(ident_chars, "") for ch in ppu.identbodychars: normal = unicodedata.normalize("NFKC", ch) if normal in ident_char_map: ident_char_map[normal] += ch ligature_map = { 'ffl': '๏ฌ ๏ฌ ๏ฌl f๏ฌ ffl', 'ffi': '๏ฌ ๏ฌ ๏ฌi f๏ฌ ffi', 'ff': '๏ฌ ff', 'fi': '๏ฌ fi', 'fl': '๏ฌ fl', 'ij': 'ij ฤณ', 'lj': 'lj ว', 'nj': 'nj ว', 'dz': 'dz วณ', 'ii': 'ii โ ฑ', 'iv': 'iv โ ณ', 'vi': 'vi โ ต', 'ix': 'ix โ ธ', 'xi': 'xi โ บ', } ligature_transformer = pp.oneOf(ligature_map).add_parse_action(lambda t: random.choice(ligature_map[t[0]].split())) def make_mixed_font(t): t_0 = t[0][0] ret = ['_' if t_0 == '_' else random.choice(ident_char_map.get(t_0, t_0))] t_rest = ligature_transformer.transform_string(t[0][1:]) ret.extend(random.choice(ident_char_map.get(c, c)) for c in t_rest) return ''.join(ret) identifier = pp.pyparsing_common.identifier identifier.add_parse_action(make_mixed_font) python_quoted_string = pp.Opt(pp.Char("fF")("f_string_prefix")) + ( pp.quotedString | pp.QuotedString('"""', multiline=True, unquoteResults=False) | pp.QuotedString("'''", multiline=True, unquoteResults=False) )("quoted_string_body") def mix_fstring_expressions(t): if not t.f_string_prefix: return fstring_arg = pp.QuotedString("{", end_quote_char="}") fstring_arg.add_parse_action(lambda tt: "{" + transformer.transform_string(tt[0]) + "}") ret = t.f_string_prefix + fstring_arg.transform_string(t.quoted_string_body) return ret python_quoted_string.add_parse_action(mix_fstring_expressions) any_keyword = pp.MatchFirst(map(pp.Keyword, list(keyword.kwlist) + getattr(keyword, "softkwlist", []))) # quoted strings and keywords will be parsed, but left untransformed transformer = python_quoted_string | any_keyword | identifier def demo(): import textwrap hello_source = textwrap.dedent(""" def hello(): try: hello_ = "Hello" world_ = "World" print(f"{hello_}, {world_}!") except TypeError as exc: print("failed: {}".format(exc)) if __name__ == "__main__": hello() """) source = hello_source transformed = transformer.transform_string(source) print(transformed) # does it really work? code = compile(transformed, source, mode="exec") exec(code) if 0: # pick some code from the stdlib import unittest.util as lib_module import inspect source = inspect.getsource(lib_module) transformed = transformer.transform_string(source) print() print(transformed) if __name__ == '__main__': demo()
SIMPAN PERUBAHAN