Skip to content

Commit

Permalink
Update TimeplusPulsar to handle code block via $$
Browse files Browse the repository at this point in the history
  • Loading branch information
jovezhong committed Dec 19, 2024
1 parent c10060c commit 3e447ad
Showing 1 changed file with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed 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.
Expand All @@ -35,11 +35,43 @@
package org.flywaydb.community.database.timeplus;

import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.parser.Parser;
import org.flywaydb.core.internal.parser.ParsingContext;
import org.flywaydb.core.internal.parser.*;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class TimeplusParser extends Parser {
private static final String ALTERNATIVE_QUOTE = "$$";

protected TimeplusParser(Configuration configuration, ParsingContext parsingContext, int peekDepth) {
super(configuration, parsingContext, peekDepth);
}

@Override
protected boolean isAlternativeStringLiteral(String peek) {
if (peek.startsWith(ALTERNATIVE_QUOTE)) {
return true;
}
return super.isAlternativeStringLiteral(peek);
}

@Override
protected Token handleAlternativeStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException {
String alternativeQuoteOpen = ALTERNATIVE_QUOTE;
String alternativeQuoteEnd = ALTERNATIVE_QUOTE;

String text;

reader.swallow(alternativeQuoteOpen.length());
text = reader.readUntilExcluding(alternativeQuoteOpen, alternativeQuoteEnd);
reader.swallow(alternativeQuoteEnd.length());

return new Token(TokenType.STRING, pos, line, col, text, text, context.getParensDepth());
}

@Override
protected boolean isSingleLineComment(String peek, ParserContext context, int col) {
return peek.startsWith("--") || peek.startsWith("//");
}
}

0 comments on commit 3e447ad

Please sign in to comment.