mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-11-22 08:46:56 -06:00
port working cql grammer into cql module
This commit is contained in:
parent
afc807285f
commit
1403e8ff0f
1077
driver-cql-shaded/src/main/grammars/cql3/CqlLexer.g4
Normal file
1077
driver-cql-shaded/src/main/grammars/cql3/CqlLexer.g4
Normal file
File diff suppressed because it is too large
Load Diff
1314
driver-cql-shaded/src/main/grammars/cql3/CqlParser.g4
Normal file
1314
driver-cql-shaded/src/main/grammars/cql3/CqlParser.g4
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
||||
package io.nosqlbench.generators.cql.lang;
|
||||
|
||||
import io.nosqlbench.generators.cql.generated.CqlParser;
|
||||
import io.nosqlbench.generators.cql.generated.CqlParserBaseListener;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CQLAstBuilder extends CqlParserBaseListener {
|
||||
|
||||
@Override
|
||||
public void exitCreateTable(CqlParser.CreateTableContext ctx) {
|
||||
List<CqlParser.ColumnDefinitionContext> columnDefinitionContexts =
|
||||
ctx.columnDefinitionList().columnDefinition();
|
||||
for (CqlParser.ColumnDefinitionContext coldef : columnDefinitionContexts) {
|
||||
CqlParser.ColumnContext column = coldef.column();
|
||||
Token symbol = column.OBJECT_NAME().getSymbol();
|
||||
CqlParser.DataTypeContext datatype = coldef.dataType();
|
||||
CqlParser.DataTypeNameContext dtn = datatype.dataTypeName();
|
||||
CqlParser.DataTypeDefinitionContext dtd = datatype.dataTypeDefinition();
|
||||
if (dtd != null) {
|
||||
List<CqlParser.DataTypeNameContext> dataTypeNameContexts = dtd.dataTypeName();
|
||||
for (CqlParser.DataTypeNameContext dtnc : dataTypeNameContexts) {
|
||||
System.out.println("here");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package io.nosqlbench.generators.cql.lang;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.tree.ErrorNode;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
public class CQLTreeBuilder implements ParseTreeListener {
|
||||
@Override
|
||||
public void visitTerminal(TerminalNode node) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitErrorNode(ErrorNode node) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterEveryRule(ParserRuleContext ctx) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitEveryRule(ParserRuleContext ctx) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package io.nosqlbench.generators.cql.lang;
|
||||
|
||||
import io.nosqlbench.generators.cql.generated.CqlLexer;
|
||||
import io.nosqlbench.generators.cql.generated.CqlParser;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
|
||||
public class ParserForCql {
|
||||
public static void parse(String input) {
|
||||
CharStream instream = CharStreams.fromString(input);
|
||||
|
||||
Lexer lexer = new CqlLexer(instream);
|
||||
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
|
||||
|
||||
CqlParser cqlParser = new CqlParser(commonTokenStream);
|
||||
cqlParser.addParseListener(new CQLAstBuilder());
|
||||
CqlParser.RootContext root = cqlParser.root();
|
||||
}
|
||||
|
||||
// public static String fingerprint(String input) {
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package io.nosqlbench.generators.cql.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
public class ParserForCqlTest {
|
||||
|
||||
@Test
|
||||
public void parseAll() {
|
||||
List<Path> cql3_examples = getSubPaths("cql3_examples");
|
||||
|
||||
for (Path examplePath : cql3_examples) {
|
||||
try {
|
||||
String example = Files.readString(examplePath, StandardCharsets.UTF_8);
|
||||
ParserForCql.parse(example);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static List<Path> getSubPaths(String resourcePath) {
|
||||
List<Path> subpaths = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Enumeration<URL> resources = ParserForCqlTest.class.getClassLoader().getResources(resourcePath);
|
||||
|
||||
while (resources.hasMoreElements()) {
|
||||
URL url = resources.nextElement();
|
||||
System.out.println("url=" + url.toExternalForm());
|
||||
Path path = Paths.get(url.toURI());
|
||||
Files.walk(path, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(p -> !Files.isDirectory(p, LinkOption.NOFOLLOW_LINKS))
|
||||
.forEach(subpaths::add);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return subpaths;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user