rrevenantt / antlr4rust

ANTLR4 parser generator runtime for Rust programming laguage
Other
398 stars 70 forks source link

Generated lexer depends on Java function: self.IsNewlineAtPos(-1) #60

Open rostamn739 opened 1 year ago

rostamn739 commented 1 year ago

Hello. I've tried to build the official antlr4 gramamr for sql/plsql which gives a successful build but fails on comple

I've used the release for 0.3-beta generator tool:

The Rust compiler errors are

... 14 more similar errors upwards
error[E0424]: expected value, found module `self`
    --> src/plsqllexer.rs:4024:7
     |
4019 |         fn START_CMD_sempred(_localctx: Option<&LexerContext<'input>>, pred_index:isize,
     |            ----------------- this function doesn't have a `self` parameter
...
4024 |                         self.IsNewlineAtPos(-2)
     |                         ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
4019 |         fn START_CMD_sempred(&self, _localctx: Option<&LexerContext<'input>>, pred_index:isize,
     |                              ++++++

Some errors have detailed explanations: E0405, E0424.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `plsql-antlr4` due to 14 previous errors
rostamn739 commented 1 year ago

:arrow_up:

Actually, there are more errors in case of successful generation Full log:

Checking plsql-antlr4 v0.1.0 (/home/rustam/work/antlr-rust/plsql-antlr4)
error[E0424]: expected value, found module `self`
    --> src/plsqllexer.rs:9175:18
     |
9169 |     fn REMARK_COMMENT_sempred(
     |        ---------------------- this function doesn't have a `self` parameter
...
9175 |             0 => self.IsNewlineAtPos(-4),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
9170 |         &self, _localctx: Option<&LexerContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqllexer.rs:9185:18
     |
9179 |     fn PROMPT_MESSAGE_sempred(
     |        ---------------------- this function doesn't have a `self` parameter
...
9185 |             1 => self.IsNewlineAtPos(-4),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
9180 |         &self, _localctx: Option<&LexerContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqllexer.rs:9195:18
     |
9189 |     fn START_CMD_sempred(
     |        ----------------- this function doesn't have a `self` parameter
...
9195 |             2 => self.IsNewlineAtPos(-2),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
9190 |         &self, _localctx: Option<&LexerContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8603:18
     |
8597 |     fn unified_auditing_sempred(
     |        ------------------------ this function doesn't have a `self` parameter
...
8603 |             0 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8598 |         &self, _localctx: Option<&Unified_auditingContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8613:18
     |
8607 |     fn audit_direct_path_sempred(
     |        ------------------------- this function doesn't have a `self` parameter
...
8613 |             1 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8608 |         &self, _localctx: Option<&Audit_direct_pathContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8623:18
     |
8617 |     fn audit_container_clause_sempred(
     |        ------------------------------ this function doesn't have a `self` parameter
...
8623 |             2 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8618 |         &self, _localctx: Option<&Audit_container_clauseContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8633:18
     |
8627 |     fn auditing_on_clause_sempred(
     |        -------------------------- this function doesn't have a `self` parameter
...
8633 |             3 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8628 |         &self, _localctx: Option<&Auditing_on_clauseContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8643:18
     |
8637 |     fn sql_statement_shortcut_sempred(
     |        ------------------------------ this function doesn't have a `self` parameter
...
8643 |             4 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8638 |         &self, _localctx: Option<&Sql_statement_shortcutContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8653:18
     |
8647 |     fn library_editionable_sempred(
     |        --------------------------- this function doesn't have a `self` parameter
...
8653 |             5 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8648 |         &self, _localctx: Option<&Library_editionableContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8663:18
     |
8657 |     fn library_debug_sempred(
     |        --------------------- this function doesn't have a `self` parameter
...
8663 |             6 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8658 |         &self, _localctx: Option<&Library_debugContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8673:18
     |
8667 |     fn alter_view_editionable_sempred(
     |        ------------------------------ this function doesn't have a `self` parameter
...
8673 |             7 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8668 |         &self, _localctx: Option<&Alter_view_editionableContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8683:18
     |
8677 |     fn partial_database_recovery_10g_sempred(
     |        ------------------------------------- this function doesn't have a `self` parameter
...
8683 |             8 => self.isVersion10(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8678 |         &self, _localctx: Option<&Partial_database_recovery_10gContext<'input>>,
     |         ++++++

error[E0424]: expected value, found module `self`
    --> src/plsqlparser.rs:8693:18
     |
8687 |     fn period_definition_sempred(
     |        ------------------------- this function doesn't have a `self` parameter
...
8693 |             9 => self.isVersion12(),
     |                  ^^^^ `self` value is a keyword only available in methods with a `self` parameter
     |
help: add a `self` receiver parameter to make the associated `fn` a method
     |
8688 |         &self, _localctx: Option<&Period_definitionContext<'input>>,
     |         ++++++

error[E0405]: cannot find trait `PlSqlParserParserContext` in this scope
      --> src/plsqlparser.rs:241915:14
       |
8441   | / pub trait PlSqlParserContext<'input>:
8442   | |     for<'x> Listenable<dyn PlSqlParserListener<'input> + 'x>
8443   | |     + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = PlSqlParserContextType>
8444   | | {
8445   | | }
       | |_- similarly named trait `PlSqlParserContext` defined here
...
241915 |   impl<'input> PlSqlParserParserContext<'input> for Table_ref_aux_internalContextAll<'input> {}
       |                ^^^^^^^^^^^^^^^^^^^^^^^^ help: a trait with a similar name exists: `PlSqlParserContext`

Some errors have detailed explanations: E0405, E0424.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `plsql-antlr4` due to 14 previous errors
rrevenantt commented 1 year ago

You need to change grammar to use 'recog' instead of 'self' in predicates as mentioned in readme https://github.com/rrevenantt/antlr4rust#differences-with-java

rostamn739 commented 1 year ago

@rrevenantt Thank you so much! I'll try and report if succesful

rostamn739 commented 1 year ago

@rrevenantt Your solution does partly solve my problems, however the functions

Are still absent from the methods of recog variable

The errors are as follows

...
error[E0599]: no method named `isVersion10` found for mutable reference `&mut BaseParser<'_, PlSqlParserExt<'_>, I, plsqlparser::PlSqlParserContextType, dyn plsqlparserlistener::PlSqlParserListener<'_>>` in the current scope
    --> src/plsqlparser.rs:8683:24
     |
8683 |             8 => recog.isVersion10(),
     |                        ^^^^^^^^^^^ method not found in `&mut BaseParser<'_, PlSqlParserExt<'_>, I, plsqlparser::PlSqlParserContextType, dyn plsqlparserlistener::PlSqlParserListener<'_>>`

error[E0599]: no method named `isVersion12` found for mutable reference `&mut BaseParser<'_, PlSqlParserExt<'_>, I, plsqlparser::PlSqlParserContextType, dyn plsqlparserlistener::PlSqlParserListener<'_>>` in the current scope
    --> src/plsqlparser.rs:8693:24
     |
8693 |             9 => recog.isVersion12(),
     |                        ^^^^^^^^^^^ method not found in `&mut BaseParser<'_, PlSqlParserExt<'_>, I, plsqlparser::PlSqlParserContextType, dyn plsqlparserlistener::PlSqlParserListener<'_>>`

error[E0599]: no method named `isVersion12` found for mutable reference `&mut PlSqlParser<'input, I, H>` in the current scope
     --> src/plsqlparser.rs:77169:30
      |
77169 |                 if !({ recog.isVersion12() }) {
      |                              ^^^^^^^^^^^ method not found in `&mut PlSqlParser<'input, I, H>`

...

And such (23 similar errors - method not found)

rostamn739 commented 1 year ago

I'm trying to add the missing methods via an extension trait:

pub trait BaseLexerAdopt {
    fn IsNewLineAtPos(&self, pos: isize) -> bool;
}

impl<'input, Input: CharStream<From<'input>>> BaseLexerAdopt for BaseLexer<'input, PlSqlLexerActions, Input, LocalTokenFactory<'input>> {
    fn IsNewLineAtPos(&self, pos: isize) -> bool {
        let la = self.input.map(|input| input.la(pos));
        la.map(|la| la == -1 || la == '\n').unwrap_or(false)
    }
}

please tell me if that'd suffice a temporary patch