Skip to content

Commit

Permalink
Merge pull request mavlink#127 from johnboiles/johnb_template_bug
Browse files Browse the repository at this point in the history
Fix template bug that occurs when variable is used at the end of a repetition
  • Loading branch information
LorenzMeier committed Oct 14, 2013
2 parents a7f4d1d + 104890c commit 8a5ae44
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pymavlink/generator/mavtemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self,
self.trim_leading_lf = trim_leading_lf
self.checkmissing = checkmissing

def find_end(self, text, start_token, end_token):
def find_end(self, text, start_token, end_token, ignore_end_token=None):
'''find the of a token.
Returns the offset in the string immediately after the matching end_token'''
if not text.startswith(start_token):
Expand All @@ -34,6 +34,12 @@ def find_end(self, text, start_token, end_token):
while nesting > 0:
idx1 = text[offset:].find(start_token)
idx2 = text[offset:].find(end_token)
# Check for false positives due to another similar token
# For example, make sure idx2 points to the second '}' in ${{field: ${name}}}
if ignore_end_token:
combined_token = ignore_end_token + end_token
if text[offset+idx2:offset+idx2+len(combined_token)] == combined_token:
idx2 += len(ignore_end_token)
if idx1 == -1 and idx2 == -1:
raise MAVParseError("token nesting error")
if idx1 == -1 or idx1 > idx2:
Expand All @@ -50,7 +56,7 @@ def find_var_end(self, text):

def find_rep_end(self, text):
'''find the of a repitition'''
return self.find_end(text, self.start_rep_token, self.end_rep_token)
return self.find_end(text, self.start_rep_token, self.end_rep_token, ignore_end_token=self.end_var_token)

def substitute(self, text, subvars={},
trim_leading_lf=None, checkmissing=None):
Expand Down

0 comments on commit 8a5ae44

Please sign in to comment.