aturoczy commented on code in PR #6542: URL: https://github.com/apache/hive/pull/6542#discussion_r3442831285
########## beeline/src/java/org/apache/hive/beeline/HiveSqlHighlighter.java: ########## @@ -0,0 +1,345 @@ +/* + * 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.hive.beeline; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.function.BooleanSupplier; +import java.util.regex.Pattern; + +import org.jline.reader.Highlighter; +import org.jline.reader.LineReader; +import org.jline.utils.AttributedString; +import org.jline.utils.AttributedStringBuilder; +import org.jline.utils.AttributedStyle; + +public class HiveSqlHighlighter implements Highlighter { + + static final AttributedStyle KEYWORD_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.CYAN).bold(); + static final AttributedStyle TYPE_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.BLUE).bold(); + static final AttributedStyle CONSTANT_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.MAGENTA).bold(); + static final AttributedStyle FUNCTION_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW); + static final AttributedStyle STRING_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN); + static final AttributedStyle NUMBER_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.MAGENTA); + static final AttributedStyle COMMENT_STYLE = + AttributedStyle.DEFAULT.faint(); + static final AttributedStyle TABLE_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW); + static final AttributedStyle COLUMN_STYLE = + AttributedStyle.DEFAULT.foreground(AttributedStyle.WHITE); + static final AttributedStyle DEFAULT_STYLE = AttributedStyle.DEFAULT; + + // Keywords after which an identifier is (most likely) a table/relation name. + // Used by the positional table-vs-column heuristic. + static final Set<String> TABLE_CONTEXT = immutableUpper( + "FROM", "JOIN", "INTO", "UPDATE", "TABLE", "DESCRIBE", "TRUNCATE"); + + // ---- Hive data types (matched before the generic keyword set) ------------ + static final Set<String> TYPES = immutableUpper( + "TINYINT", "SMALLINT", "INT", "INTEGER", "BIGINT", "FLOAT", "DOUBLE", + "DECIMAL", "NUMERIC", "DEC", "REAL", "PRECISION", "BOOLEAN", "STRING", + "CHAR", "VARCHAR", "BINARY", "DATE", "DATETIME", "TIMESTAMP", + "TIMESTAMPLOCALTZ", "INTERVAL", "ARRAY", "MAP", "STRUCT", "UNIONTYPE", + "VARIANT", "LONG"); + + static final Set<String> CONSTANTS = immutableUpper( + "TRUE", "FALSE", "NULL", "UNKNOWN"); + + private static final String KEYWORD_LIST = Review Comment: Good point. Let me check it. -- 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]
