# Buggy code
def open(cls, grammar_filename, rel_to=None, **options):
    """Create an instance of Lark with the grammar given by its filename

    If rel_to is provided, the function will find the grammar filename in relation to it.

    Example:

        >>> Lark.open("grammar_file.lark", rel_to=__file__, parser="lalr")
        Lark(...)

    """
    if rel_to:
        basepath = os.path.dirname(rel_to)
        grammar_filename = os.path.join(basepath, grammar_filename)
    with open(grammar_filename) as f:
        return cls(f, **options)


# Traceback (KeyError)
Traceback (most recent call last):
File "d:\lark-parser\lark\lexer.py", line 221, in __init__
lexer = lexer_by_tokens[key]
KeyError: frozenset({Token(TERMINAL, '__ANON_0'), 'grammar'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:\lark-parser\lark\lexer.py", line 179, in __init__
re.compile(t.pattern.to_regexp())
File "F:\Python\lib\re.py", line 233, in compile
return _compile(pattern, flags)
File "F:\Python\lib\re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "F:\Python\lib\sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "F:\Python\lib\sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags &amp; SRE_FLAG_VERBOSE, 0)
File "F:\Python\lib\sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "F:\Python\lib\sre_parse.py", line 553, in _parse
raise source.error(msg, len(this) + 1 + len(that))
sre_constants.error: bad character range ˜-Ã at position 5

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\no_ambiguous.py", line 11, in <module>
_parser = lark.Lark.open( "parser.lark", start='grammar', parser='lalr' )
File "d:\lark-parser\lark\lark.py", line 206, in open
return cls(f, **options)
File "d:\lark-parser\lark\lark.py", line 165, in __init__
self.parser = self._build_parser()
File "d:\lark-parser\lark\lark.py", line 188, in _build_parser
return self.parser_class(self.lexer_conf, parser_conf, options=self.options)
File "d:\lark-parser\lark\parser_frontends.py", line 46, in __init__
self.init_contextual_lexer(lexer_conf, parser_conf)
File "d:\lark-parser\lark\parser_frontends.py", line 23, in init_contextual_lexer
user_callbacks=lexer_conf.callbacks)
File "d:\lark-parser\lark\lexer.py", line 225, in __init__
lexer = Lexer(state_tokens, ignore=ignore, user_callbacks=user_callbacks)
File "d:\lark-parser\lark\lexer.py", line 181, in __init__
raise LexError("Cannot compile token %s: %s" % (t.name, t.pattern))
NameError: name 'LexError' is not defined

# Fixed code
def open(cls, grammar_filename, rel_to=None, **options):
    """Create an instance of Lark with the grammar given by its filename

    If rel_to is provided, the function will find the grammar filename in relation to it.

    Example:

        >>> Lark.open("grammar_file.lark", rel_to=__file__, parser="lalr")
        Lark(...)

    """
    if rel_to:
        basepath = os.path.dirname(rel_to)
        grammar_filename = os.path.join(basepath, grammar_filename)
    with open(grammar_filename, encoding="utf8") as f:
        return cls(f, **options)