def parse_feature_node(s,next_index=0): next_index = jump_over_space(s,next_index) start_index = next_index while True: # Alnum and '-' are both legal characters inside a node ch = s[next_index] if ch.isalnum() or ch == '-' or ch == '_': next_index += 1 else: break feature_node = s[start_index:next_index] if feature_node == '': feature_node = None return (feature_node,next_index)
def parse_feature_node(s, next_index=0): next_index = jump_over_space(s, next_index) start_index = next_index while True: # Alnum and '-' are both legal characters inside a node ch = s[next_index] if ch.isalnum() or ch == '-' or ch == '_': next_index += 1 else: break feature_node = s[start_index:next_index] if feature_node == '': feature_node = None return (feature_node, next_index)
def check_symbol(s,next_index,symbol): """ Check whether we have got a defined symbol in the grammar. Return False if not, or return the next_index after this symbol. :param s: The string need to be checked :type s: str :param next_index: Index on the string :type next_index: integer :param symbol: The symbol to be checked against :type symbol: str """ try: next_index = jump_over_space(s,next_index) if s[next_index:next_index + len(symbol)] == symbol: return next_index + len(symbol) # We must ignore the symbol except IndexError: return False else: return False
def check_symbol(s, next_index, symbol): """ Check whether we have got a defined symbol in the grammar. Return False if not, or return the next_index after this symbol. :param s: The string need to be checked :type s: str :param next_index: Index on the string :type next_index: integer :param symbol: The symbol to be checked against :type symbol: str """ try: next_index = jump_over_space(s, next_index) if s[next_index:next_index + len(symbol)] == symbol: return next_index + len(symbol) # We must ignore the symbol except IndexError: return False else: return False
def parse_feature_value(s,next_index=0): """ Parse the value of a feature entry. The value can be a plain text string without any space or new line, or it can be several sub values separated by '/'. In both case the function will return a list containing each sub strings. :param s: The string to be parsed :type s: str :return: A tuple containing the value as well as next_index :rtype: tuple(list(str),integer) """ next_index = jump_over_space(s,next_index) start_index = next_index while True: if not s[next_index].isspace(): next_index += 1 else: break feature_value = s[start_index:next_index] if feature_value == '': feature_value = None feature_value = feature_value.split('/') return (feature_value,next_index)
def parse_feature_value(s, next_index=0): """ Parse the value of a feature entry. The value can be a plain text string without any space or new line, or it can be several sub values separated by '/'. In both case the function will return a list containing each sub strings. :param s: The string to be parsed :type s: str :return: A tuple containing the value as well as next_index :rtype: tuple(list(str),integer) """ next_index = jump_over_space(s, next_index) start_index = next_index while True: if not s[next_index].isspace(): next_index += 1 else: break feature_value = s[start_index:next_index] if feature_value == '': feature_value = None feature_value = feature_value.split('/') return (feature_value, next_index)