def read_nonterminals(filename):
    "Reads the user-defined nonterminal symbols in 'filename', checks that\n       it has the expected format and has no duplicates, and returns the nonterminal\n       symbols as a list of strings, e.g.\n       ['#nonterm:contact_list', '#nonterm:phone_number', ... ]. "
    ans = [line.strip(' \t\r\n') for line in open(filename, 'r', encoding='latin-1')]
    if (len(ans) == 0):
        raise RuntimeError('The file {0} contains no nonterminals symbols.'.format(filename))
    for nonterm in ans:
        if (nonterm[:9] != '#nonterm:'):
            raise RuntimeError("In file '{0}', expected nonterminal symbols to start with '#nonterm:', found '{1}'".format(filename, nonterm))
    if (len(set(ans)) != len(ans)):
        raise RuntimeError('Duplicate nonterminal symbols are present in file {0}'.format(filename))
    return ans
Reads the user-defined nonterminal symbols in 'filename', checks that
it has the expected format and has no duplicates, and returns the nonterminal
symbols as a list of strings, e.g.
['#nonterm:contact_list', '#nonterm:phone_number', ... ].
def read_nonterminals(filename):
    "Reads the user-defined nonterminal symbols in 'filename', checks that\n       it has the expected format and has no duplicates, and returns the nonterminal\n       symbols as a list of strings, e.g.\n       ['#nonterm:contact_list', '#nonterm:phone_number', ... ]. "
    ans = [line.strip(' \t\r\n') for line in open(filename, 'r', encoding='latin-1')]
    if (len(ans) == 0):
        raise RuntimeError('The file {0} contains no nonterminals symbols.'.format(filename))
    for nonterm in ans:
        if (nonterm[:9] != '#nonterm:'):
            raise RuntimeError("In file '{0}', expected nonterminal symbols to start with '#nonterm:', found '{1}'".format(filename, nonterm))
    if (len(set(ans)) != len(ans)):
        raise RuntimeError('Duplicate nonterminal symbols are present in file {0}'.format(filename))
    return ans