Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Little fix...

  • Loading branch information...
commit 979a52b0525464601c4fac39e3bc52213732a54a 1 parent bf7ab27
@Dolkar authored
Showing with 12 additions and 19 deletions.
  1. +12 −19 bit_twiddler/bit_twiddler.py
View
31 bit_twiddler/bit_twiddler.py
@@ -330,7 +330,7 @@ def __init__(self, output_func = sys.stdout.write, error_func = sys.stderr.write
self.op_prec[key] = prec
self.op_opnum[key] = opnum
- self.keywords = set(self.op_func) | SPEC_OPERS
+ self.keywords = COMMANDS | set(self.op_func) | SPEC_OPERS
self.reserved_vars = set([MAXVAL, ASSIGN])
self.static = STATIC | set(self.op_func) # Their token is equal to themselves
@@ -346,7 +346,7 @@ def set_base(self, base, bit_width):
def raiseError(self, what):
"""In case something goes wrong..."""
self.error(what + '\n')
- return False, None
+ return None, None
def formatInt(self, val, base, width):
string = BASE_CONVERTORS[base](val).lstrip('0bx').rstrip('L')
@@ -395,7 +395,7 @@ def _error_func(string):
self.output, self.error = output.write, _error_func
tokens, post_oper = self.parseExpr(re.findall(_LEXER_PATT, expr))
- if not isinstance(tokens, bool):
+ if tokens != None:
tokens = self.to_postfix(tokens)
self.execExpr(tokens, post_oper)
@@ -421,15 +421,13 @@ def mainloop(self):
if parens < 0:
self.raiseError(_ERR_INBALANCED)
- continue
elif brackets < 0:
self.raiseError(_ERR_INVALID_TABLE)
- continue
-
- # Parse it already!
- tokens, post_oper = self.parseExpr(re.findall(_LEXER_PATT, raw))
- if tokens:
- self.execExpr(self.to_postfix(tokens), post_oper)
+ else:
+ # Parse it already!
+ tokens, post_oper = self.parseExpr(re.findall(_LEXER_PATT, raw))
+ if tokens:
+ self.execExpr(self.to_postfix(tokens), post_oper)
def getVar(self, varname):
@@ -441,8 +439,7 @@ def parseExpr(self, expr, exec_cmds = True):
Parses an expression to a list of tokens. In case of inbalanced
parentheses, it prompts for the rest. Returns a list of tokens
and how to handle them (post_oper). If expression cannot be evaluated,
- a boolean value is returned instead of token list. If True is returned,
- the interpreter is terminated. New prompt should appear otherwise.
+ a tuple of "None" is returned.
"""
expr_len = len(expr)
@@ -488,15 +485,11 @@ def parseExpr(self, expr, exec_cmds = True):
# It's a table definition!
end = expr.index(RTABLE, i)
t, _ = self.parseExpr(expr[i + 1:end], exec_cmds = False)
- if isinstance(t, bool):
- return t, None
+ if t == None:
+ return None, None
tokens.append(list(t))
i = end
- elif token == CMD_HELP:
- "Implement this!"
- return None, None
-
elif token == CMD_QUIT:
quit()
@@ -557,7 +550,7 @@ def parseExpr(self, expr, exec_cmds = True):
if expr_len == 1:
self.set_base(token[:3], width)
- return False, None
+ return None, None
else:
post_oper = (token[:3], width)
Please sign in to comment.
Something went wrong with that request. Please try again.