Skip to content

Difficult to identify the location of an error of type: SyntaxException: Expected: \|,} at line: 3680 char: 2 #428

@rdan

Description

@rdan

Hello,
I am using mako to create a generator of files (.c, .h, ...).
While implementing the templates, I faced the error:
SyntaxException: Expected: \|,} at line: 3680 char: 2.
It took me some time to identify where the issue was.

I finally identified its location:
99: #define EVADC_u32CFG${Cfg_Adc["INDEX"]}_${CfgrdGroup}_CFGD_FADCI_KHz ${CfgrdGroup["FADCI_KHz"]
(there is a missing '}' at the end).

After searching in the code who is reporting this error, I found that "Lexer.parse_until_text()" is.
The difficulty with the exception generated by this function is that it points to a location far far from the source of the problem.
So, I did the following modifications in the function:
1/
I added the following lines at the start of the function:

        startlineno = self.matched_lineno
        startcharpos = self.matched_charpos

2/
I replaced the following code:

            raise exceptions.SyntaxException(
                "Expected: %s" % ",".join(text), **self.exception_kwargs
            )

by:

            self.matched_lineno = startlineno
            self.matched_charpos = startcharpos
            raise exceptions.SyntaxException(
                "Expected '%s' while parsing text starting" % ",".join(text), **self.exception_kwargs
            )

And now, the reported error message is:
SyntaxException: Expected '\|,}' while parsing text starting at line: 99 char: 69

This way, at least I am able to identify the python block or expression that triggered the exception.

I don't know if this is the proper way to reach this goal, but at least I think it would be beneficial for every user of mako to be able to identify the python block/expression in which an error has been detected.

Ronan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions