From 7dfb0fdf24fb4a1f757be14ce5806b5a81f20ab8 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 20 May 2020 07:02:20 -0500 Subject: [PATCH] HHH-14033 - SQL script parsing problem with multi-line comments - Better handling of multi-line comments - Restructured some internal classes to consolidate packages - Added "system"-style SchemaToolingLogging This commit: - unifies handling of Antlr `-traceParser` across parsers - adds comment crediting to Terrance Parr for the BLOCK_COMMENT lexer rule in the sql-script grammar --- .../src/main/antlr/{sql-stmt.g => sql-script.g} | 5 +++++ .../graph/internal/parse/GraphParser.java | 10 ++++++++++ .../sql/ordering/antlr/OrderByFragmentParser.java | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) rename hibernate-core/src/main/antlr/{sql-stmt.g => sql-script.g} (95%) diff --git a/hibernate-core/src/main/antlr/sql-stmt.g b/hibernate-core/src/main/antlr/sql-script.g similarity index 95% rename from hibernate-core/src/main/antlr/sql-stmt.g rename to hibernate-core/src/main/antlr/sql-script.g index 9e97a5ee78..9aba884a02 100644 --- a/hibernate-core/src/main/antlr/sql-stmt.g +++ b/hibernate-core/src/main/antlr/sql-script.g @@ -126,6 +126,11 @@ LINE_COMMENT } ; +/** + * Note : this comes from the great Terrance Parr (author of Antlr) - + * + * https://theantlrguy.atlassian.net/wiki/spaces/ANTLR3/pages/2687360/How+do+I+match+multi-line+comments + */ BLOCK_COMMENT : "/*" ( /* '\r' '\n' can be matched in one alternative or by matching diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java index 26dd66d045..933bf3c044 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java @@ -164,4 +164,14 @@ public class GraphParser extends GeneratedGraphParser { ); } } + + @Override + public void traceIn(String s) throws TokenStreamException { + // nothing to do - this parser already does a good job with logging trace info + } + + @Override + public void traceOut(String s) throws TokenStreamException { + // nothing to do - this parser already does a good job with logging trace info + } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java b/hibernate-core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java index 07289b8331..8fa6cde1d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java @@ -293,19 +293,29 @@ public class OrderByFragmentParser extends GeneratedOrderByFragmentParser { @Override public void traceIn(String ruleName) { + if ( ! LOG.isTraceEnabled() ) { + return; + } + if ( inputState.guessing > 0 ) { return; } - String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> "; + + final String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> "; LOG.trace( prefix + ruleName ); } @Override public void traceOut(String ruleName) { + if ( ! LOG.isTraceEnabled() ) { + return; + } + if ( inputState.guessing > 0 ) { return; } - String prefix = "<-" + StringHelper.repeat( '-', ( --traceDepth * 2 ) ) + " "; + + final String prefix = "<-" + StringHelper.repeat( '-', ( --traceDepth * 2 ) ) + " "; LOG.trace( prefix + ruleName ); }