Skip to content

Commit

Permalink
improved lexer's regular expressions
Browse files Browse the repository at this point in the history
- made them mutually exclusive, such that we don't face the keyword args ordering issue anymore
- fixed some unhandled corner cases (added appropriate test cases as well)
  - handle $$( additionally to $${
  - handle text in front of $$ or single $
  • Loading branch information
rhaschke committed Sep 15, 2017
1 parent fb41970 commit ff574c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sudo: enabled
language: python
python:
- "2.7"
- "3.5"
- "3.6"

# command to install dependencies
Expand Down
11 changes: 4 additions & 7 deletions src/xacro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,10 @@ def grab_properties(elt, table):
elt = next


# TODO: The order of arguments here is relevant!
# However, python 3.0 - 3.5 doesn't preserve order of keyword arguments
# This is only fixed with https://www.python.org/dev/peps/pep-0468 in 3.6
LEXER = QuickLexer(DOLLAR_DOLLAR_BRACE=r"\$\$+\{",
EXPR=r"\$\{[^\}]*\}",
EXTENSION=r"\$\([^\)]*\)",
TEXT=r"([^\$]|\$[^{(]|\$$)+")
LEXER = QuickLexer(DOLLAR_DOLLAR_BRACE=r"^\$\$+(\{|\()", # multiple $ in a row, followed by { or (
EXPR=r"^\$\{[^\}]*\}", # stuff starting with ${
EXTENSION=r"^\$\([^\)]*\)", # stuff starting with $(
TEXT=r"[^$]+|\$[^{($]+|\$$") # any text w/o $ or $ following any chars except {($ or single $


# evaluate text and return typed value
Expand Down
8 changes: 4 additions & 4 deletions test/test_xacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,13 @@ def test_substitution_args_arg(self):

def test_escaping_dollar_braces(self):
self.assert_matches(
self.quick_xacro('''<a b="$${foo}" c="$$${foo}" />'''),
'''<a b="${foo}" c="$${foo}" />''')
self.quick_xacro('''<a b="$${foo}" c="$$${foo}" d="text $${foo}" e="text $$${foo}" f="$$(pwd)" />'''),
'''<a b="${foo}" c="$${foo}" d="text ${foo}" e="text $${foo}" f="$(pwd)" />''')

def test_just_a_dollar_sign(self):
self.assert_matches(
self.quick_xacro('''<a b="$" />'''),
'''<a b="$" />''')
self.quick_xacro('''<a b="$" c="text $" d="text $ text"/>'''),
'''<a b="$" c="text $" d="text $ text"/>''')

def test_multiple_insert_blocks(self):
self.assert_matches(
Expand Down

0 comments on commit ff574c9

Please sign in to comment.