github-actions[bot] commented on code in PR #63225: URL: https://github.com/apache/doris/pull/63225#discussion_r3240453364
########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/ParseErrorStrategy.java: ########## @@ -0,0 +1,94 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.parser; + +import com.google.common.collect.ImmutableMap; +import org.antlr.v4.runtime.DefaultErrorStrategy; +import org.antlr.v4.runtime.InputMismatchException; +import org.antlr.v4.runtime.NoViableAltException; +import org.antlr.v4.runtime.Parser; +import org.antlr.v4.runtime.RecognitionException; +import org.antlr.v4.runtime.Token; +import org.apache.commons.lang3.StringUtils; + +import java.util.Map; + +/** + * A ParserErrorStrategy extends the {@link DefaultErrorStrategy}, that does special handling + * on errors. + * + * The intention of this class is to provide more information of these errors encountered in ANTLR + * parser to the downstream consumers. + */ +public class ParseErrorStrategy extends DefaultErrorStrategy { + private static final Map<String, String> USER_WORD_DICT = ImmutableMap.of("'<EOF>'", "end of input"); + + @Override + protected String getTokenErrorDisplay(Token t) { + String tokenName = super.getTokenErrorDisplay(t); + return USER_WORD_DICT.getOrDefault(tokenName, tokenName); + } + + @Override + protected void reportInputMismatch(Parser recognizer, InputMismatchException e) { + recognizer.notifyErrorListeners(e.getOffendingToken(), Review Comment: This path never produces the reserved-keyword diagnostic that the PR advertises and that `testReservedKeywordAsIdentifierError` asserts. For `create database load`, SLL bails out, LL reaches this `reportInputMismatch`, and the message is built as only `Syntax error at or near 'load'`; there is no `reserved keyword` text and no backtick suggestion such as `` `load` ``. As a result the new unit test fails and the user-facing reserved-keyword guidance is not actually implemented. Please detect the identifier-expected/reserved-token case here (or update the tests/PR scope if the intended behavior is only the generic message). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
