Skip to content

Support dynamic delimiter in mysql parser#778

Merged
huydo862003 merged 7 commits intomasterfrom
feat/support-delimiter-in-mysql-parser
Nov 19, 2025
Merged

Support dynamic delimiter in mysql parser#778
huydo862003 merged 7 commits intomasterfrom
feat/support-delimiter-in-mysql-parser

Conversation

@huydo862003
Copy link
Copy Markdown
Contributor

Summary

  • Support dynamic DELIMITER in mysql parser.
DELIMITER @@

CREATE TABLE Users (
  id int
)@@

Issue

#566

Lasting Changes (Technical)

(please list down: code changes/things that have wide-effect; new libraries/functions added that can be used by others; examples below)

  • (Added class EmailValidator to validate email address' validity)
  • (Added Tenant#is_trial? check)

Checklist

Please check directly on the box once each of these are done

  • Documentation (if necessary)
  • Tests (integration test/unit test)
  • Integration Tests Passed
  • Code Review

@huydo862003 huydo862003 changed the title Support delimiter in mysql parser Support dynamic delimiter in mysql parser Nov 8, 2025
@huydo862003 huydo862003 added the PR: New Feature 🚀 A type of pull request used for changelog categories label Nov 8, 2025
@huydo862003 huydo862003 force-pushed the feat/support-delimiter-in-mysql-parser branch from 412ef22 to d0dd8a6 Compare November 17, 2025 04:38
Comment on lines +49 to +59
@members {
this.currentDelimiter = ";";

this.setDelimiter = function (delimiter) {
this.currentDelimiter = delimiter.trim();
};

this.isCurrentDelimiter = function (text) {
return text === this.currentDelimiter;
};
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This work. Another way is you could define a lexer base class :and move the code here to there. Please check the. For more details, check the PostgresSQL Lexer.g4 and .js for an example

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have extracted out a base class nhe:

options {
// MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
superClass = MySqlLexerBase;
caseInsensitive = true;
}

export default class MySqlLexerBase extends antlr4.Lexer {

Comment on lines +21 to +23
CREATE TABLE Table_4 (
id INT
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add more test for the following cases:

  1. DELIMITER GO
  2. DELIMITER END
  3. DELIMITER inside comment (should be ignored) -- DELIMITER ...
  4. DELIMITER appear in quoted string
CREATE TABLE Table_5 (
  id INT COMMENT 'just a comment with semi colon ;',
  name varchar default 'default value with semi colon ;'
);

DELIMITER @

CREATE TABLE Table_6 (
  id INT COMMENT 'just a comment with new delimiter @',
  name varchar default 'default value with new delimiter @'
)@

Copy link
Copy Markdown
Contributor Author

@huydo862003 huydo862003 Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed all the problems and add some contrived testcases in delimiter.in.sql nhe: https://github.com/holistics/dbml/blob/c646dddacc98307a490e8363c197bbefdfe1347d/packages/dbml-core/__tests__/parser/mysql-parse/input/delimiter.in.sql.

I have also added other unrelated tests to make sure changes to the Lexer does not break anything unrelated to delimiters.

@huydo862003 huydo862003 force-pushed the feat/support-delimiter-in-mysql-parser branch from 09d99e5 to ab37dcd Compare November 18, 2025 15:36
@huydo862003 huydo862003 force-pushed the feat/support-delimiter-in-mysql-parser branch from ab37dcd to ecda97a Compare November 19, 2025 02:14
@huydo862003 huydo862003 merged commit bfc05f5 into master Nov 19, 2025
4 checks passed
@huydo862003 huydo862003 deleted the feat/support-delimiter-in-mysql-parser branch November 19, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 A type of pull request used for changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants