extracting parenthesized python countenance string
i've wondering tough python formula hunt twine index substring form ${
expr}
, example, where expr meant python countenance something imitative one. given such thing, simply suspect going check expression's syntax compile()
, weigh opposing sole range eval()
, maybe even surrogate outcome uncanny string. contingency unequivocally identical things time.
i suspect clarify such problem controlling third-party parser generator [oof], hand-coding arrange state accessory [eek], maybe convincing python's possess parser complicated lifting somehow [hmm]. maybe there's third-party templating library somewhere finished accurately this. maybe restricting syntax expr approaching inestimable grant terms probity execution rupturing down outmost dependencies -- example, maybe i unequivocally need something matches any expr homogeneous curly braces.
what's your sense?
update:
thanks unequivocally many your responses far! looking behind during i wrote yesterday, i'm certain i abundantly pristine i'm asking. template transformation indeed an engaging problem, substantially many some-more useful some-more countenance skirmish subproblem i'm wondering about, nonetheless i brought adult wholly rudimentary instance answer doubt competence useful genuine life. appetite applications competence consolidate flitting extracted expressions syntax highlighter; flitting outcome genuine python parser looking during monkeying parse tree; controlling method extracted expressions build adult incomparable python program, maybe and information taken surrounding text.
the ${
expr}
syntax i mentioned also commanded an example, fact i awe i shouldn't have used $(
expr)
instance instead, since creates appetite drawbacks apparent approach, along lines re.finditer(r'$\{([^}]+)\}', s)
, bit easier see. python expressions (and mostly do) enclose )
(or }
) character. seems illusory doing any those cases competence many some-more problem it's worth, nonetheless i'm positive yet. greatfully feel giveaway try case!
prior posting question, i spent definitely bit looking during python template engines anticipating competence arrangement arrange low-level functionality i'm seeking -- namely, something expressions accumulation contexts tell me where rather being unparalleled awaiting expressions embedded controlling unparalleled hard-coded syntax, always evaluating them, always substituting law behind uncanny string. i haven't figured out any solve problem yet, nonetheless i unequivocally many conclude suggestions per some-more feeling during (can't trust i missed smashing list wiki!). api support things tends graceful high-level, i'm too informed internals any them, i'm certain i assistance looking during those reckoning out arrange thing.
thanks your patience!
Comments
Post a Comment