Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when 'name' is not a hashable type. #40

Closed
max-kamps opened this issue Aug 18, 2017 · 4 comments · Fixed by #269
Closed

Crash when 'name' is not a hashable type. #40

max-kamps opened this issue Aug 18, 2017 · 4 comments · Fixed by #269

Comments

@max-kamps
Copy link

When a rules's name is not a hashable type (e.g. a list), like in this rule:

Root:
	name+=ID[','] ;

process_node crashes ungracefully:

  File "/usr/bin/textx", line 11, in <module>
    sys.exit(textx())
  File "/usr/lib/python3.6/site-packages/textx/commands/console.py", line 51, in textx
    model = metamodel.model_from_file(args.model, debug=args.d)
  File "/usr/lib/python3.6/site-packages/textx/metamodel.py", line 465, in model_from_file
    encoding, debug=debug)
  File "/usr/lib/python3.6/site-packages/textx/model.py", line 168, in get_model_from_file
    debug=debug)
  File "/usr/lib/python3.6/site-packages/textx/model.py", line 194, in get_model_from_str
    model = parse_tree_to_objgraph(self, self.parse_tree[0])
  File "/usr/lib/python3.6/site-packages/textx/model.py", line 520, in parse_tree_to_objgraph
    model = process_node(parse_tree)
  File "/usr/lib/python3.6/site-packages/textx/model.py", line 333, in process_node
    parser._instances[id(inst.__class__)][inst.name] = inst
TypeError: unhashable type: 'list'
@igordejanovic
Copy link
Member

Attributes called name are treated in a special way. They are used for reference auto-resolving feature. So, yes, name must be of a hashable type. I'll add a note in the docs.

@igordejanovic
Copy link
Member

As a side note, if you don't have a strict requirement for name to be a list, the idiomatic way to use this kind of identifier would be to create your match rule for a list of IDs and use that instead.

Root: name=MyID;
MyID: ID+[','];

Match rules by default return matched string (if you do not use match filters) so no problem with name lookups.

@max-kamps
Copy link
Author

Oh no, I was just surprised that it crashed instead of reporting that the metamodel was not OK.
I still think it would be better to check for stuff like this while parsing the metamodel, but I understand if that is too complex with the current setup. Haven't bothered to look into the code yet.

@igordejanovic
Copy link
Member

Yes. I agree. Better error reporting would be nice. I'll look into it when find some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants