Skip to content

Passing parameters containing commas #36

Description

@psychemedia

If I pass a sentence containing commas in to a modifier, the params are split on simple commas:

rules={
    'origin': '''here's my sentence: #test.uppercase.echo(this is, my sentence, "with a comma, ok?")#''',
    'test': 'Ping'
}

def myecho(*params):
    return '::'.join(params)

grammar_test= {
    'echo': myecho
}

grammar = tracery.Grammar(rules)
grammar.add_modifiers(base_english)
grammar.add_modifiers(grammar_test)
print(grammar.flatten("#origin#"))

here's my sentence: PING::this is:: my sentence:: "with a comma:: ok?"

It would be useful to be able to pass in strings containing commas:

e.g.

import shlex

line='This is, a line, "with a comma, ok?"'
shlex.split(line)
['This', 'is,', 'a', 'line,', 'with a comma, ok?']

rather than:

line.split(',')
['This is', ' a line', ' "with a comma', ' ok?"']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions