textX: object_processors do not run on rule

I have simplified my grammar to reproduce a bug in object processors:

from textx import metamodel_from_str
grammar = """
Command:
    name=ID parameters=ParameterList
;
    
ParameterList:
    '(' parameters*=Parameter ')'
;
Parameter:
     ExplicitFloat
;
ExplicitFloat:
    /-?\d+\.\d+/
;
"""

code = """
mycommand(0.1 1.1)
"""
mm = metamodel_from_str(grammar)
mm.register_obj_processors({'ExplicitFloat': lambda x: float(x)})

mymodel = mm.model_from_str(code)

first_param = mymodel.parameters.parameters[0]
assert isinstance(first_param, float), f"first parameter is of type {type(first_param)} instead of float"

The ExplicitFloat is not changed to a float and remains str. If the ExplicitFloat appears “higher” in the syntax tree of the grammar, then it occasionally translates it. Am I doing something wrong, or is there a bug in the object processors?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@Geniedesalpages This issue is now fixed on master. The calls to match rules are done on all levels. The inconsistency in nested rules I mentioned before is fixed so that in case you have a nesting match rule with multiple parts (like '+' ExplicitFloat) everything will get converted to text and concatenated. Please see this test.