-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added script to export antlr tokens to use in frontend editor
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
ksqldb-parser/src/main/java/io/confluent/ksql/util/GrammarTokenExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.util; | ||
|
||
import io.confluent.ksql.parser.SqlBaseLexer; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import scala.Console; | ||
|
||
public final class GrammarTokenExporter { | ||
private GrammarTokenExporter() { | ||
} | ||
|
||
public static void main(final String[] args) throws IOException { | ||
final List<String> tokens = GrammarTokenExporter.getTokens(); | ||
Console.println("'" + String.join(" ", tokens) + "'"); | ||
} | ||
|
||
private static final Pattern pattern = Pattern.compile("T__[0-9]"); | ||
|
||
public static List<String> getTokens() { | ||
final List<String> tokens = new ArrayList<>(Arrays.asList(SqlBaseLexer.ruleNames)); | ||
return tokens.stream().filter(pattern.asPredicate().negate()).collect(Collectors.toList()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
ksqldb-parser/src/test/java/io/confluent/ksql/util/GrammarTokenExporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
|
||
package io.confluent.ksql.util; | ||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.Test; | ||
|
||
public class GrammarTokenExporterTest { | ||
private static final List<String> expectedTokens = new ArrayList<>(Arrays.asList("EMIT", "CHANGES", | ||
"FINAL", "SELECT", "FROM", "AS", "ALL", "DISTINCT", "WHERE", "WITHIN", | ||
"WINDOW", "GROUP", "BY", "HAVING", "LIMIT", "AT", "OR", "AND", "IN", "NOT", | ||
"EXISTS", "BETWEEN", "LIKE", "ESCAPE", "IS", "NULL", "TRUE", "FALSE", | ||
"INTEGER", "DATE", "TIME", "TIMESTAMP", "INTERVAL", "YEAR", "MONTH", "DAY", | ||
"HOUR", "MINUTE", "SECOND", "MILLISECOND", "YEARS", "MONTHS", "DAYS", | ||
"HOURS", "MINUTES", "SECONDS", "MILLISECONDS", "ZONE", "TUMBLING", "HOPPING", | ||
"SIZE", "ADVANCE", "RETENTION", "GRACE", "PERIOD", "CASE", "WHEN", "THEN", | ||
"ELSE", "END", "JOIN", "FULL", "OUTER", "INNER", "LEFT", "RIGHT", "ON", | ||
"PARTITION", "STRUCT", "WITH", "VALUES", "CREATE", "TABLE", "TOPIC", "STREAM", | ||
"STREAMS", "INSERT", "DELETE", "INTO", "DESCRIBE", "EXTENDED", "PRINT", | ||
"EXPLAIN", "ANALYZE", "TYPE", "TYPES", "CAST", "SHOW", "LIST", "TABLES", | ||
"TOPICS", "QUERY", "QUERIES", "TERMINATE", "LOAD", "COLUMNS", "COLUMN", | ||
"PARTITIONS", "FUNCTIONS", "FUNCTION", "DROP", "TO", "RENAME", "ARRAY", | ||
"MAP", "SET", "DEFINE", "UNDEFINE", "RESET", "SESSION", "SAMPLE", "EXPORT", | ||
"CATALOG", "PROPERTIES", "BEGINNING", "UNSET", "RUN", "SCRIPT", "DECIMAL", | ||
"KEY", "CONNECTOR", "CONNECTORS", "SINK", "SOURCE", "NAMESPACE", "MATERIALIZED", | ||
"VIEW", "PRIMARY", "REPLACE", "ASSERT", "ADD", "ALTER", "VARIABLES", "IF", | ||
"EQ", "NEQ", "LT", "LTE", "GT", "GTE", "PLUS", "MINUS", "ASTERISK", "SLASH", | ||
"PERCENT", "CONCAT", "ASSIGN", "STRUCT_FIELD_REF", "LAMBDA_EXPRESSION", | ||
"STRING", "INTEGER_VALUE", "DECIMAL_VALUE", "FLOATING_POINT_VALUE", "IDENTIFIER", | ||
"DIGIT_IDENTIFIER", "QUOTED_IDENTIFIER", "BACKQUOTED_IDENTIFIER", "VARIABLE", | ||
"EXPONENT", "DIGIT", "LETTER", "SIMPLE_COMMENT", "DIRECTIVE_COMMENT", | ||
"BRACKETED_COMMENT", "WS", "UNRECOGNIZED")); | ||
|
||
@Test | ||
public void shouldNeedBackQuotes() { | ||
List<String> tokens = GrammarTokenExporter.getTokens(); | ||
|
||
assertEquals(expectedTokens, tokens); | ||
} | ||
} |