Summary
When using pynescript to parse Pine Script with User-Defined Types (UDT), the AST correctly captures TypeDef nodes. However, there's no built-in way to convert these to usable Python code. The unparser.py only converts back to Pine Script syntax.
Pine Script Example
//@version=5
indicator("UDT Test")
type PathTracker
float entry
float target
float stop
bool is_long
bool is_top
type VolData
float buy
float sell
float total
float delta
bool is_valid
// Usage
tracker = PathTracker.new(na, na, na, true, false)
vol = VolData.new(100.0, 50.0, 150.0, 50.0, true)
Current Behavior
pynescript correctly parses this and creates:
TypeDef nodes in the AST with field definitions
- When using
unparser.py, it correctly regenerates Pine Script
However, when trying to use the AST to generate Python code (for transpilation purposes), there's no facility to:
- Generate Python class definitions from
TypeDef nodes
- Convert
.new() constructor calls to Python class instantiation
Feature Request
Would it be possible to add a Python code generator (similar to unparser.py but targeting Python instead of Pine Script)?
This could generate:
class PathTracker:
def __init__(self, entry=None, target=None, stop=None, is_long=None, is_top=None):
self.entry = entry
self.target = target
self.stop = stop
self.is_long = is_long
self.is_top = is_top
tracker = PathTracker(float('nan'), float('nan'), float('nan'), True, False)
Environment
- pynescript version: 0.3.0
- Python version: 3.11
- Platform: Windows
Additional Context
I'm working on a Pine Script to Backtrader converter and pynescript is excellent for parsing. The main gap is converting UDT constructs to Python equivalents. Currently I have to implement custom handling for TypeDef nodes in my own transformer.
Thank you for this great library!
Summary
When using pynescript to parse Pine Script with User-Defined Types (UDT), the AST correctly captures
TypeDefnodes. However, there's no built-in way to convert these to usable Python code. Theunparser.pyonly converts back to Pine Script syntax.Pine Script Example
Current Behavior
pynescript correctly parses this and creates:
TypeDefnodes in the AST with field definitionsunparser.py, it correctly regenerates Pine ScriptHowever, when trying to use the AST to generate Python code (for transpilation purposes), there's no facility to:
TypeDefnodes.new()constructor calls to Python class instantiationFeature Request
Would it be possible to add a Python code generator (similar to
unparser.pybut targeting Python instead of Pine Script)?This could generate:
Environment
Additional Context
I'm working on a Pine Script to Backtrader converter and pynescript is excellent for parsing. The main gap is converting UDT constructs to Python equivalents. Currently I have to implement custom handling for
TypeDefnodes in my own transformer.Thank you for this great library!