Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/camertron/python3-parser-rb
A Python 3 parser for Ruby.
https://github.com/camertron/python3-parser-rb
Last synced: 18 days ago
JSON representation
A Python 3 parser for Ruby.
- Host: GitHub
- URL: https://github.com/camertron/python3-parser-rb
- Owner: camertron
- License: mit
- Created: 2020-05-02T20:43:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T08:43:25.000Z (almost 3 years ago)
- Last Synced: 2024-12-04T01:36:58.119Z (about 1 month ago)
- Language: C++
- Size: 530 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# python3-parser-rb
A Python 3 parser for Ruby.
## Usage
Parse some Python 3 code and walk over the parse tree with a visitor:
```ruby
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))
ENDclass MyFuncVisitor < Python3Parser::Visitor
def visit_funcdef(ctx)
puts ctx.NAME.text
visit_children(ctx)
end
endparser = 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.
## Technology
Want to target Ruby with your own ANTLR grammars? Check out the [antlr-gemerator](https://github.com/camertron/antlr-gemerator).
## Caveats
See the caveats listed in [antlr4-native's README](https://github.com/camertron/antlr4-native-rb#caveats).
## System Requirements
See the system requirements listed in [antlr4-native's README](https://github.com/camertron/antlr4-native-rb#system-requirements).
## License
Licensed under the MIT license. See LICENSE.txt for details.
## Authors
* Cameron C. Dutro: http://github.com/camertron