chappertron / lammps-analyser

A linter for the LAMMPS scripting language
GNU General Public License v2.0
0 stars 0 forks source link

Handle unterminated strings more gracefully #20

Closed chappertron closed 7 hours ago

chappertron commented 1 week ago

If a string does not end with a " or ' character (depending on the kind), currently the whole node is reported as a syntax error.

This could be improved by matching on the kind of error nodes in arguments and attempting to parse as a string.

A sketch may look like this.

    match node.kind() {

        // NOTE: need better error handling here.
        "ERROR" => {
                    let child = node.child(0)?;
                    match child.kind() {
                        '"' => {return string(child,text);},
                        '\'' => {return raw_string(child,text);},
                        _ => todo!["handle other cases or just error"]
                    }
                }
        _ => todo!("other cases")
    }

Then, within the raw_string and string functions, we can check for the missing quotes.

A similar approach could work for parenthesis and expansions.

chappertron commented 7 hours ago

Support added for this in commit 80aa257