Cole-Greer commented on code in PR #3091: URL: https://github.com/apache/tinkerpop/pull/3091#discussion_r2032174244
########## gremlin-language/src/main/java/org/apache/tinkerpop/gremlin/language/corpus/GrammarReader.java: ########## @@ -0,0 +1,63 @@ +/* + * 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.tinkerpop.gremlin.language.corpus; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Reads ANTLR grammar file to extract Gremlin keyword string representations. + */ +public class GrammarReader { + + // Pattern to match token definitions like: TADDALL: 'addAll'; + private static final Pattern tokenPattern = Pattern.compile("T[A-Z0-9_]+:\\s*'([^']+)'\\s*;"); + + /** + * Parse a grammar file to extract all keyword string representations. + * + * @param grammarFilePath The path to the ANTLR grammar file + * @return A set of keyword string representations + * @throws IOException If there's an error reading the file + */ + public static Set<String> parse(final String grammarFilePath) throws IOException { Review Comment: I'm not entirely sure on the purpose of this method yet, but I'm worried that the regex-based approach may be fragile if there are any keyword definitions in the grammar which are split over multiple lines. If the goal is simply to obtain a list of all keyword tokens from the grammar, it may be more robust to parse this out of the gremlin-language generated sources such as `gremlin-language/target/generated-sources/antlr4/org/apache/tinkerpop/gremlin/language/grammar/Gremlin.tokens`. -- 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]
