objectionary / eo

EOLANG, an Experimental Pure Object-Oriented Programming Language Based on 𝜑-calculus
https://www.eolang.org
MIT License
1.02k stars 127 forks source link

ANTLR parsing error messages are not descriptive enough, in `PhiMojo` #3370

Open volodya-lombrozo opened 2 months ago

volodya-lombrozo commented 2 months ago

One of the integration tests in jeo-maven-plugin has the following pipeline:

bytecode -> (disassemble) xmir -> phi -> unphi -> xmir (assemble) -> bytecode.

First of all I generate App.xmir from App.class file (disassemble):

App.xmir.txt

Then I use eo:0.39.0:xmir-to-phi to generate App.phi:

App.phi.txt

Then I run eo:0.39.0:phi-to-xmir to generate App.xmir (and it is generated):

App.xmir.txt

However, during the eo:0.39.0:phi-to-xmir I get the following exception that fails the entire build:

1 files with parsing errors were found: [org/eolang/hone/App.phi]
Here is the full log ```txt [INFO] --- eo:0.39.0:phi-to-xmir (phi-to-xmir) @ phi-unphi-it --- line 23:12 token recognition error at: '@' [INFO] 45 attributes loaded from 39 stream(s) in 9ms, 45 saved, 456 ignored: ["Archiver-Version", "Automatic-Module-Name", "Bnd-LastModified", "Build-Jdk", "Build-Jdk-Spec", "Built-By", "Bundle-ContactAddress", "Bundle-Description", "Bundle-DocURL", "Bundle-License", "Bundle-ManifestVersion", "Bundle-Name", "Bundle-RequiredExecutionEnvironment", "Bundle-SymbolicName", "Bundle-Vendor", "Bundle-Version", "Created-By", "EO-Dob", "EO-Revision", "EO-Version", "Export-Package", "Extension-Name", "Implementation-Build", "Implementation-Title", "Implementation-URL", "Implementation-Vendor", "Implementation-Vendor-Id", "Implementation-Version", "Import-Package", "Include-Resource", "JCabi-Build", "JCabi-Date", "JCabi-Version", "Main-Class", "Manifest-Version", "Multi-Release", "Originally-Created-By", "Project-Name", "Require-Capability", "Specification-Title", "Specification-Vendor", "Specification-Version", "Tool", "X-Compile-Source-JDK", "X-Compile-Target-JDK"] [INFO] Parsed to xmir: /Users/lombrozo/Workspace/EOlang/jeo-maven-plugin/target/it/phi-unphi/target/generated-sources/eo-phi/org/eolang/hone/App.phi -> /Users/lombrozo/Workspace/EOlang/jeo-maven-plugin/target/it/phi-unphi/target/generated-sources/eo-unphi/org/eolang/hone/App.xmir [INFO] Parsed 1 phi files to xmir [ERROR] 1 files with parsing errors were found: [org/eolang/hone/App.phi] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.514 s [INFO] Finished at: 2024-09-13T14:27:54+03:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.eolang:eo-maven-plugin:0.39.0:phi-to-xmir (phi-to-xmir) on project phi-unphi-it: 'org.eolang.maven.UnphiMojo@5e80d5' execution failed: java.lang.IllegalStateException: 1 files with parsing errors were found: [org/eolang/hone/App.phi] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eolang:eo-maven-plugin:0.39.0:phi-to-xmir (phi-to-xmir) on project phi-unphi-it: 'org.eolang.maven.UnphiMojo@5e80d5' execution failed at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:904) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281) at org.apache.maven.cli.MavenCli.main (MavenCli.java:204) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314) Caused by: org.apache.maven.plugin.MojoFailureException: 'org.eolang.maven.UnphiMojo@5e80d5' execution failed at org.eolang.maven.SafeMojo.exitError (SafeMojo.java:391) at org.eolang.maven.SafeMojo.execute (SafeMojo.java:292) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:904) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281) at org.apache.maven.cli.MavenCli.main (MavenCli.java:204) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314) Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: 1 files with parsing errors were found: [org/eolang/hone/App.phi] at java.util.concurrent.FutureTask.report (FutureTask.java:122) at java.util.concurrent.FutureTask.get (FutureTask.java:205) at org.eolang.maven.SafeMojo.execWithTimeout (SafeMojo.java:340) at org.eolang.maven.SafeMojo.execute (SafeMojo.java:274) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:904) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281) at org.apache.maven.cli.MavenCli.main (MavenCli.java:204) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314) Caused by: java.lang.IllegalStateException: 1 files with parsing errors were found: [org/eolang/hone/App.phi] at org.eolang.maven.UnphiMojo.exec (UnphiMojo.java:147) at org.eolang.maven.SafeMojo.lambda$execWithTimeout$4 (SafeMojo.java:337) at java.util.concurrent.FutureTask.run (FutureTask.java:317) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642) at java.lang.Thread.run (Thread.java:1583) ```
volodya-lombrozo commented 2 months ago

@maxonfjvipon Could you take a look, please? It's kinda urgent.

maxonfjvipon commented 2 months ago

@volodya-lombrozo the name @init@-KClW is invalid and not supported by phi grammar. The name has to start with simple english letter

volodya-lombrozo commented 2 months ago

@maxonfjvipon Why doesn't xmir-to-phi say anything about it? I believe it's a bug either in xmir-to-phi, or phi-to-xmir must accept @init@-KClW. Moreover, the exception message 1 files with parsing errors were found: [org/eolang/hone/App.phi] doesn't say anything about @init@-KClW naming, which is frustrating and consumes lots of time to investigate the problem. We would be able to avoid this discussion, if we had informative messages.

maxonfjvipon commented 2 months ago

@volodya-lombrozo it said here (from you log)

image
volodya-lombrozo commented 2 months ago

@maxonfjvipon Missed that, thank you! However, it's still rather cryptic and not very obvious. As I understand, it's a default lexer message. Is it possible to add context to this message? https://www.yegor256.com/2015/12/01/rethrow-exceptions.html

As for the the rest:

I believe it's a bug either in xmir-to-phi, or phi-to-xmir must accept @init@-KClW.

It's still important and blocks other issues.

maxonfjvipon commented 2 months ago

@volodya-lombrozo according to phi paper:

image

"attribute is ... an english letters starting with a lowercase letter"

maxonfjvipon commented 2 months ago

@yegor256 WDYT? Should we add an ability to parse such names @init@-KClW in phi grammar?

volodya-lombrozo commented 2 months ago

@maxonfjvipon Could you add this check to the xmir-to-phi or allow such names, please?

Note: The problem happens on xmir-to-phi <-> phi-to-xmir side ONLY in eo-maven-plugin . jeo:disassemble and jeo:assemble have nothing to do with this.

yegor256 commented 2 months ago

@maxonfjvipon no, we should not allow such names in phi grammar (we should reject them both at xmir-to-phi and in phi-to-xmir)

maxonfjvipon commented 2 months ago

@volodya-lombrozo this "check" is enabled by grammar itself, it just fails on parsing step

volodya-lombrozo commented 2 months ago

@yegor256 What about the following names:

a@init@
a-init-a
a------

?

volodya-lombrozo commented 2 months ago

@maxonfjvipon

@volodya-lombrozo this "check" is enabled by grammar itself, it just fails on parsing step

Anyway, it is still a relevant question:

However, it's still rather cryptic and not very obvious. As I understand, it's a default lexer message. Is it possible to add context to this message? https://www.yegor256.com/2015/12/01/rethrow-exceptions.html

yegor256 commented 2 months ago

@volodya-lombrozo any name is fine, as long as it starts with [a-z] and doesn't contain spaces and EOLs. @maxonfjvipon please, correct me if I'm wrong

maxonfjvipon commented 2 months ago

@yegor256 you're right

yegor256 commented 1 month ago

@volodya-lombrozo still a bug?

volodya-lombrozo commented 1 month ago

@maxonfjvipon Did you add any checks before the xmir-to-phi goal?

maxonfjvipon commented 1 month ago

@volodya-lombrozo I didn't. @yegor256 we should think about a general mechanism of interpretation ANTLR error messages to some human readable ones, so the end-user is not guessing what went wrong but seeing a bug immediately

yegor256 commented 1 month ago

@maxonfjvipon how about we try to use paraphrase from ANTLR: https://stackoverflow.com/a/2266574/187141