
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
A Python 3 parser for Ruby.
Parse some Python 3 code and walk over the parse tree with a visitor:
require 'python3-parser'
# from https://rosettacode.org/wiki/Roman_numerals/Decode#Python
python_code = <<~END
_rdecode = dict(zip('MDCLXVI', (1000, 500, 100, 50, 10, 5, 1)))
def decode(roman):
result = 0
for r, r1 in zip(roman, roman[1:]):
rd, rd1 = _rdecode[r], _rdecode[r1]
result += -rd if rd < rd1 else rd
return result + _rdecode[roman[-1]]
if __name__ == '__main__':
for r in 'MCMXC MMVIII MDCLXVI'.split():
print(r, decode(r))
END
class MyFuncVisitor < Python3Parser::Visitor
def visit_funcdef(ctx)
puts ctx.NAME.text
visit_children(ctx)
end
end
parser = Python3Parser::Parser.parse(python_code)
parser.visit(MyFuncVisitor.new)
The script above should print "decode"
when executed, since decode
is the only function defined in the Python code snippet.
Want to target Ruby with your own ANTLR grammars? Check out the antlr-gemerator.
See the caveats listed in antlr4-native's README.
See the system requirements listed in antlr4-native's README.
Licensed under the MIT license. See LICENSE.txt for details.
FAQs
Unknown package
We found that python3-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.