lark
lark copied to clipboard
%import not working for UTF-8 files
Opening UTF-8 files was fixed in #179 but importing UTF-8 files is still broken.
Given parser.lark:
grammar: /[a-zØ-öø-ÿ]/
and import.lark:
%import .parser.grammar
Opening the parser
import lark
parser = lark.Lark.open('import.lark', start='grammar' )
leads to an error.
Traceback
Traceback (most recent call last):
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\utils.py", line 175, in get_regexp_width
return [int(x) for x in sre_parse.parse(regexp).getwidth()]
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\sre_parse.py", line 948, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\sre_parse.py", line 443, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\sre_parse.py", line 598, in _parse
raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range ˜-Ã at position 5
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\parser_frontends.py", line 175, in _prepare_match
width = get_regexp_width(regexp)[0]
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\utils.py", line 177, in get_regexp_width
raise ValueError(regexp)
ValueError: [a-zØ-öø-ÿ]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\lark.py", line 285, in open
return cls(f, **options)
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\lark.py", line 231, in __init__
self.parser = self._build_parser()
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\lark.py", line 251, in _build_parser
return self.parser_class(self.lexer_conf, parser_conf, options=self.options)
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\parser_frontends.py", line 154, in __init__
self._prepare_match(lexer_conf)
File "C:\Users\JLaasonen\.virtualenvs\ebl-api-LV-IZRrf\lib\site-packages\lark\parser_frontends.py", line 177, in _prepare_match
raise ValueError("Bad regexp in token %s: %s" % (t.name, regexp))
ValueError: Bad regexp in token __ANON_0: [a-zØ-öø-ÿ]
The problem seems to be the import_grammar method, where the call to open lacks the encoding argument.
Merged, so closing.