def __isCommand(self, key, word2): """ decide if a keyword and next word are of the form 'command arg, ...' which will get translated to 'command(arg, ...)' to allow 'command syntax' """ # this could be in one long test, but we simplify: # first test key: if (not isValidName(key) or key in self.friends or key.startswith('#') or len(key) < 1 or len(word2) < 1): return False if self._larch is not None: comms = self._larch.symtable.get_symbol('_sys.valid_commands', create=True) if key not in comms: return False # next test word2 return (isValidName(word2) or isNumber(word2) or isLiteralStr(word2) )
def __isCommand(self, key, word2): """ decide if a keyword and next word are of the form 'command arg, ...' which will get translated to 'command(arg, ...)' to allow 'command syntax' """ # this could be in one long test, but we simplify: # first test key: if (not isValidName(key) or key in self.friends or key.startswith('#') or len(key) < 1 or len(word2) < 1): return False # next test word2 return (isValidName(word2) or isNumber(word2) or isLiteralStr(word2))
def get_DefVar(text): """ looks for defined variable statement, of the form >> def varname = exression returns (varname, expression) if this is a valid defvar statement or None, None if not a valid defvar statement """ if text.find('=') > 0 and text.startswith('def '): t = text[4:].replace('=',' = ').strip() words = t.split() if len(words) > 2 and words[1] == '=': iequal = t.find('=') iparen = t.find('(') icolon = t.find(':') if iparen < 0 : iparen = len(t)+1 if icolon < 0 : icolon = len(t)+1 # print iequal, iparen, icolon, words[0], isValidName(words[0]) if (iequal < iparen and iequal < icolon and isValidName(words[0])): return words[0], t[iequal+1:].strip() return None, None
def __isCommand(self, key, word2): """ decide if a keyword and next word are of the form 'command arg, ...' which will get translated to 'command(arg, ...)' to allow 'command syntax' """ # this could be in one long test, but we simplify: # first test key: if (not isValidName(key) or key in self.friends or key.startswith('#') or len(key) < 1 or len(word2) < 1): return False # next test word2 return (isValidName(word2) or isNumber(word2) or isLiteralStr(word2) )
def get_DefVar(text): """ looks for defined variable statement, of the form >> def varname = exression returns (varname, expression) if this is a valid defvar statement or None, None if not a valid defvar statement """ if text.find('=') > 0 and text.startswith('def '): t = text[4:].replace('=', ' = ').strip() words = t.split() if len(words) > 2 and words[1] == '=': iequal = t.find('=') iparen = t.find('(') icolon = t.find(':') if iparen < 0: iparen = len(t) + 1 if icolon < 0: icolon = len(t) + 1 # print iequal, iparen, icolon, words[0], isValidName(words[0]) if (iequal < iparen and iequal < icolon and isValidName(words[0])): return words[0], t[iequal + 1:].strip() return None, None