Skip to content

Commit

Permalink
Use standard tokenizations for variable definitions.
Browse files Browse the repository at this point in the history
This is so that multi-line variable content will be possible one day.
  • Loading branch information
sharat87 committed Mar 24, 2019
1 parent 7bde998 commit 9de5194
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/roast.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ A note about escaping braces in the context of interpolation. Braced should be
doubled to escape. So, if we are defining a variable with a JSON value, the
braces should be doubled so they won't be interpreted as interpolation targets.
<
set payload {{"username": "Sherlock", "password": "Moriarty"}}
set payload '{{"username": "Sherlock", "password": "Moriarty"}}'
>
Here, the variable `payload` would be set to the following text:
<
Expand Down
12 changes: 5 additions & 7 deletions python3/roast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ def build_request(lines, line_num) -> requests.Request:
current_template.append(line)
continue

if line.startswith('set '):
name, value = line[4:].strip().split(None, 1)
# Interpolations in variables are applied when the variable is defined.
variables[name] = value.format(**variables)
continue

parts = tokenize(line)
if len(parts) < 2:
continue

head, *rest = parts

if head == 'alias':
if head == 'set':
# Interpolations in variables are applied when the variable is defined.
variables[rest[0]] = ' '.join(rest[1:]).format(**variables)

elif head == 'alias':
# Interpolations in aliases are applied when the alias is used.
aliases[rest[0]] = ' '.join(rest[1:])

Expand Down
2 changes: 1 addition & 1 deletion python3/test_roast.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_interpolation_in_headers():

def test_variable_with_json_value():
req = ra.build_request([
'set payload {{"username": "Sherlock", "password": "Moriarty"}}',
'set payload \'{{"username": "Sherlock", "password": "Moriarty"}}\'',
'POST /post <<END',
'{payload}',
'END',
Expand Down

0 comments on commit 9de5194

Please sign in to comment.