[ https://issues.apache.org/jira/browse/TINKERPOP-3028?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17852594#comment-17852594 ]
ASF GitHub Bot commented on TINKERPOP-3028: ------------------------------------------- vkagamlyk commented on code in PR #2640: URL: https://github.com/apache/tinkerpop/pull/2640#discussion_r1628500051 ########## gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/translator/GoTranslateVisitor.java: ########## @@ -0,0 +1,292 @@ +/* + * 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.translator; + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.TerminalNode; +import org.apache.commons.lang3.StringUtils; +import org.apache.tinkerpop.gremlin.language.grammar.GremlinParser; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.apache.tinkerpop.gremlin.util.DatetimeHelper; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class GoTranslateVisitor extends AbstractTranslateVisitor { + private final static String GO_PACKAGE_NAME = "gremlingo."; + + public GoTranslateVisitor() { + super("g"); + } + + public GoTranslateVisitor(final String graphTraversalSourceName) { + super(graphTraversalSourceName); + } + + @Override + public Void visitDateLiteral(final GremlinParser.DateLiteralContext ctx) { + // child at 2 is the date argument to datetime() and comes enclosed in quotes + final String dtString = ctx.getChild(2).getText(); + final Date dt = DatetimeHelper.parse(removeFirstAndLastCharacters(dtString)); + sb.append("time.UnixMilli(" + dt.getTime() + ")"); + return null; + } + + @Override + public Void visitInfLiteral(final GremlinParser.InfLiteralContext ctx) { + if (ctx.SignedInfLiteral().getText().equals("-Infinity")) + sb.append("math.Inf(-11)"); Review Comment: ```suggestion sb.append("math.Inf(-1)"); ``` > Convert translators to make use of the grammar > ---------------------------------------------- > > Key: TINKERPOP-3028 > URL: https://issues.apache.org/jira/browse/TINKERPOP-3028 > Project: TinkerPop > Issue Type: Improvement > Components: translator > Affects Versions: 3.6.6 > Reporter: Stephen Mallette > Assignee: Stephen Mallette > Priority: Major > > {{Translator}} infrastructure uses bytecode and reflection which has a number > of technical imperfections and exemptions for it to work properly. Switching > to the grammar for translation simplifies the code, removes friction and > complexity when generating GLV tests, and should perform better. The focus > for this issue is the Java series of translators which are relied on quite > heavily. -- This message was sent by Atlassian Jira (v8.20.10#820010)