matchcompiler: simplify some more code

This commit is contained in:
Matthias Krüger 2016-11-26 16:08:14 +01:00
parent 83d0b42c66
commit 59bbe6cd42
1 changed files with 11 additions and 23 deletions

View File

@ -160,13 +160,11 @@ class MatchCompiler:
# a|b|c # a|b|c
elif tok.find('|') > 0: elif tok.find('|') > 0:
tokens2 = tok.split('|') tokens2 = tok.split('|')
logicalOp = None logicalOp = ' || '
if "" in tokens2: if "" in tokens2:
ret += ' if (tok && (' ret += ' if (tok && ('
logicalOp = ' || '
else: else:
ret += ' if (!tok || !(' ret += ' if (!tok || !('
logicalOp = ' || '
first = True first = True
for tok2 in tokens2: for tok2 in tokens2:
if tok2 == '': if tok2 == '':
@ -176,12 +174,11 @@ class MatchCompiler:
first = False first = False
ret += self._compileCmd(tok2) ret += self._compileCmd(tok2)
ret += '))\n'
if "" in tokens2: if "" in tokens2:
ret += '))\n'
ret += ' tok = tok->next();\n' ret += ' tok = tok->next();\n'
gotoNextToken = '' gotoNextToken = ''
else: else:
ret += '))\n'
ret += ' ' + returnStatement ret += ' ' + returnStatement
# !!a # !!a
@ -261,16 +258,10 @@ class MatchCompiler:
pos = 0 pos = 0
inString = False inString = False
while pos != pos1: while pos != pos1:
if inString: if line[pos] == '\\':
if line[pos] == '\\': pos += 1
pos += 1 elif line[pos] == '"':
elif line[pos] == '"': inString = not inString
inString = False
else:
if line[pos] == '\\':
pos += 1
elif line[pos] == '"':
inString = True
pos += 1 pos += 1
return inString return inString
@ -526,8 +517,8 @@ class MatchCompiler:
break break
assert(len(res) >= 3 or len(res) < 6) assert(len(res) >= 3 or len(res) < 6)
# assert that Token::find(simple)match has either 2, 3 or # assert that Token::find(simple)match has either 2, 3 or 4
# four arguments # arguments
g0 = res[0] g0 = res[0]
tok = res[1] tok = res[1]
@ -549,13 +540,10 @@ class MatchCompiler:
# Token *findmatch(const Token *tok, const char pattern[], const # Token *findmatch(const Token *tok, const char pattern[], const
# Token *end, unsigned int varId = 0); # Token *end, unsigned int varId = 0);
endToken = None endToken = None
if is_findsimplematch is True and len(res) == 4: if ((is_findsimplematch and len(res) == 4) or
(not is_findsimplematch and varId and (len(res) == 5)) or
(not is_findsimplematch and varId is None and len(res) == 4)):
endToken = res[3] endToken = res[3]
elif is_findsimplematch is False:
if varId and len(res) == 5:
endToken = res[3]
elif varId is None and len(res) == 4:
endToken = res[3]
res = re.match(r'\s*"((?:.|\\")*?)"\s*$', pattern) res = re.match(r'\s*"((?:.|\\")*?)"\s*$', pattern)
if res is None: if res is None: