untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 15 forks source link

Parser struggle to correctly interpret comments #113

Closed lefouvert closed 7 months ago

lefouvert commented 10 months ago

Hi ! First, many thanks for this mod ❤️.

Here the code :

use { Vessel } from ksp::vessel

pub struct Stage(vessel: Vessel) {
    ship: Vessel = vessel
}

impl Stage {

    fn partialFlameout(self, stage: int) -> bool = {
        return self.ship.parts.filter(fn(p) ->  p.activation_stage == stage         // all parts in this stage
                                            &&  p.engine_module.defined)            // which are engines
                                .map(fn(p) ->   p.engine_module.value.has_ignited   // engine have been started
                                            &&  p.engine_module.value.is_flameout)  // engine fuel is depleted
                                .filter(fn(s) -> s) // s == true                    // keep only those which are flameout
                                .length > 0                                         // if there is at least one
    }
    // fn partialFlameout(self, stage: int) -> bool = {
    //     return self.ship.parts.filter(fn(p) ->  p.activation_stage == stage
    //                                         &&  p.engine_module.defined)
    //                             .map(fn(p) ->   p.engine_module.value.has_ignited
    //                                         &&  p.engine_module.value.is_flameout)
    //                             .filter(fn(s) -> s)
    //                             .length > 0
    // }
}

This code give this error message :

Rebooted in 00:00:02.2753749 ERROR: [ship\gitreport.to2(9, 5)] Parsing ship\gitreport.to2(9, 5): Expected '}'

However, if we uncomment the lower function block and comment the upper function block, everything is fine. I suspect the parser is confused with inline comment in ongoing instruction.

I assume it was not an expected behavior.

Have a great day !

Edit : typo

untoldwind commented 9 months ago

Should work now with 0.5.2.4

lefouvert commented 9 months ago

version : 0.5.2.5 (Ckan)

Hi, I encounter similar behavior in an other case : gitreport::commentparsing.to2

const Sexagesimal: float = 60.0

pub fn hms(timespan: float) -> (hour: int, minute: int, second: float) = {
    return (
        hour: truncate(timespan / Sexagesimal**2).to_int, // foo
        minute: truncate((timespan % Sexagesimal**2) / Sexagesimal).to_int, // bar
        second: timespan % Sexagesimal // foobar
    )
}

give this error :

Rebooted in 00:00:02.4082456 ERROR: [gitreport\commentparsing.to2(36, 57)] Parsing gitreport\commentparsing.to2(36, 57): Expected ')'

Edit Maybe this behavior could also come with large array manualy instancied row by row and... commented. Dunno, I didn't test it, but I mention it just in case...

untoldwind commented 9 months ago

This should work now in 0.5.2.6 ... though there are probably still some places left where comments do not work as intended.

lefouvert commented 9 months ago

Don't worry, it's expected. Parser rules are a nightmare (I know about, I built two for KSP1 KOS : one to minify my code, and the second one to serialize JSON files, holding various kind of parameters, and able to deserialize them into a lexicon), not about complexity, but about completeness. If I catch a another one, I'll let you know :)

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] commented 7 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.