geographika/mappyfile

lark.exceptions.UnexpectedCharacters: No terminal defined for 'b' at line 1 col 1

blueromans opened this issue · 4 comments

Can you help me about this error?
`Traceback (most recent call last):
File "/Users/n2software/Documents/djangotest/testpro/maptest.py", line 11, in
ast = p.parse_file('default.map')
File "/Users/n2software/Documents/djangotest/testenv/lib/python3.6/site-packages/mappyfile/parser.py", line 181, in parse_file
return self.parse(text, fn=fn)
File "/Users/n2software/Documents/djangotest/testenv/lib/python3.6/site-packages/mappyfile/parser.py", line 194, in parse
tree = self.lalr.parse(text)
File "/Users/n2software/Documents/djangotest/testenv/lib/python3.6/site-packages/lark/lark.py", line 223, in parse
return self.parser.parse(text)
File "/Users/n2software/Documents/djangotest/testenv/lib/python3.6/site-packages/lark/parser_frontends.py", line 36, in parse
return self.parser.parse(token_stream, *[sps] if sps is not NotImplemented else [])
File "/Users/n2software/Documents/djangotest/testenv/lib/python3.6/site-packages/lark/parsers/lalr_parser.py", line 68, in parse
for i, token in enumerate(stream):
File "/Users/n2software/Documents/djangotest/testenv/lib/python3.6/site-packages/lark/lexer.py", line 250, in lex
for x in l.lex(stream, self.root_lexer.newline_types, self.root_lexer.ignore_types):
File "/Users/n2software/Documents/djangotest/testenv/lib/python3.6/site-packages/lark/lexer.py", line 105, in lex
raise UnexpectedCharacters(stream, line_ctr.char_pos, line_ctr.line, line_ctr.column, state=self.state)
lark.exceptions.UnexpectedCharacters: No terminal defined for 'b' at line 1 col 1

b'\x08Turkiye6\xc3\x89|B\xc3\x82\xc3\xad`

This is the code
import mappyfile
from django.core.serializers import json
from mappyfile.parser import Parser
from mappyfile.transformer import MapfileToDict
from mappyfile.pprint import PrettyPrinter
from lark import UnexpectedToken
from mappyfile.validator import Validator

p = Parser()
m = MapfileToDict()
ast = p.parse_file('default.map')
d = m.transform(ast)
print(json.dumps(d, indent=4))

Merhaba @blueromans

The code looks fine. What version of mappyfile are you using?

print(mappyfile.__version__)

Is your default.map saved in UTF-8? This is required by both MapServer and mappyfile, and may explain the error. Is it possible to add default.map (or a cut-down version that still causes the issue) to this issue?

hi @geographika version is 0.7.2. I havent got any information about default.map.

@blueromans - I'm afraid without providing the Mapfile that is causing the issue I can't provide any assistance. It seems most likely you are trying to open an invalid Mapfile.
Try the same code with one of the sample Mapfiles in https://github.com/geographika/mappyfile/tree/master/tests/sample_maps

If you can recreate the issue with a sample map in http://mappyfile.geographika.net please reopen the issue. Otherwise it looks like this may be an issue with code external to mappyfile.