Skip to content

✨ feat(mq-lang): add =~ regex match operator and is_regex_match builtin#1305

Merged
harehare merged 15 commits intomainfrom
feat/regex-match-operator
Feb 21, 2026
Merged

✨ feat(mq-lang): add =~ regex match operator and is_regex_match builtin#1305
harehare merged 15 commits intomainfrom
feat/regex-match-operator

Conversation

@harehare
Copy link
Copy Markdown
Owner

  • Add =~ as a binary operator for regex matching (maps to is_regex_match)
  • Implement is_regex_match builtin function
  • Update parser, CST, AST, lexer, and token definitions
  • Add tests and update syntax highlighting for all editors

Closes #1274

- Add =~ as a binary operator for regex matching (maps to is_regex_match)
- Implement is_regex_match builtin function
- Update parser, CST, AST, lexer, and token definitions
- Add tests and update syntax highlighting for all editors

Closes #1274
Copilot AI review requested due to automatic review settings February 20, 2026 14:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a regex match operator (=~) and the is_regex_match builtin function to the mq language, providing a more ergonomic way to perform regex matching compared to the previous test() function that required chaining regex_match() with !is_empty(). The operator maps to the is_regex_match builtin, which returns a boolean indicating whether a pattern matches a string.

Changes:

  • Added =~ binary operator for regex matching (note: issue #1274 specified ~= but implementation uses =~)
  • Implemented is_regex_match builtin function that returns boolean instead of an array of matches
  • Updated test() function in builtin.mq to use the more efficient is_regex_match directly
  • Updated syntax highlighting across all editors (VSCode, Neovim, Zed, Playground, REPL)

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
crates/mq-lang/src/lexer/token.rs Added TildeEqual token kind for the =~ operator
crates/mq-lang/src/lexer.rs Added lexer parser for =~ token and included it in binary operators
crates/mq-lang/src/cst/node.rs Added RegexMatch variant to BinaryOp enum
crates/mq-lang/src/cst/parser.rs Mapped TildeEqual token to RegexMatch binary operation
crates/mq-lang/src/ast/parser.rs Set operator precedence, mapped to builtin function, added to operator recognition
crates/mq-lang/src/ast/constants.rs Added IS_REGEX_MATCH constant for the builtin function name
crates/mq-lang/src/eval/builtin.rs Implemented IS_REGEX_MATCH builtin with hash constant, dispatch entry, and helper function
crates/mq-lang/builtin.mq Simplified test() to use is_regex_match directly instead of regex_match + !is_empty()
crates/mq-lang/tests/integration_tests.rs Added basic test case for the =~ operator
editors/vscode/syntaxes/mq.tmLanguage.json Added =~ to VSCode syntax highlighting
editors/neovim/syntax/mq.vim Added =~ to Neovim syntax highlighting
editors/zed/languages/mq/highlights.scm Added =~ to Zed syntax highlighting
packages/mq-playground/src/Playground.tsx Added =~ to Monaco editor syntax highlighting
crates/mq-repl/src/repl.rs Added =~ to REPL syntax highlighting

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 20, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/regex-match-operator (168dedb) with main (361faa2)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (c441c97) during the generation of this report, so 361faa2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copilot AI review requested due to automatic review settings February 20, 2026 15:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

@harehare
Copy link
Copy Markdown
Owner Author

@copilot
Can you check out the changes and add some tests them?

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 21, 2026

@harehare I've opened a new pull request, #1310, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI review requested due to automatic review settings February 21, 2026 03:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

- match: '\b(def|do|let|if|elif|else|end|while|foreach|self|nodes|match|fn|break|continue|include|import|module|var|macro|quote|unquote|loop)\b'
scope: keyword.control.mq
- match: '(->|=|\||:|;|\?|!|\+|\-|\*|/|%|<|>|<=|>=|==|!=|&&)'
- match: '(->|=|\||:|;|\?|!|\+|\-|\*|/|%|<|>|<=|>=|==|!=|&&|=~)'
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

The =~ operator is placed after the = operator in the alternation pattern. In regex alternations, patterns are tried left-to-right, so the single = will match before =~ gets a chance to be tested. This will cause =~ to be incorrectly highlighted as two separate operators (= and ~).

The =~ operator should be placed before the single = operator in the pattern to ensure it matches correctly. The corrected pattern should be:
'(->|=~|=|\||:|;|\?|!|\+|\-|\*|/|%|<|>|<=|>=|==|!=|&&)'

This ensures that two-character operators like =~, <=, >=, ==, != are matched before their single-character prefixes.

Suggested change
- match: '(->|=|\||:|;|\?|!|\+|\-|\*|/|%|<|>|<=|>=|==|!=|&&|=~)'
- match: '(->|=~|=|\||:|;|\?|!|\+|\-|\*|/|%|<|>|<=|>=|==|!=|&&)'

Copilot uses AI. Check for mistakes.
Comment on lines 2444 to 2445
const HASH_IS_REGEX_MATCH: u64 = fnv1a_hash_64("is_regex_match");
const HASH_IS_NAN: u64 = fnv1a_hash_64("is_nan");
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

The hash constant HASH_IS_REGEX_MATCH is not in alphabetical order. According to the codebase convention (see memory about hash constants being in alphabetical order), hash constants should be ordered alphabetically by function name.

Currently:

  • HASH_IS_DEBUG_MODE (is_debug_mode)
  • HASH_IS_REGEX_MATCH (is_regex_match)
  • HASH_IS_NAN (is_nan)

Alphabetically correct order should be:

  • HASH_IS_DEBUG_MODE (is_debug_mode)
  • HASH_IS_NAN (is_nan)
  • HASH_IS_REGEX_MATCH (is_regex_match)

The constant should be moved to line 2445 (after HASH_IS_NAN).

Suggested change
const HASH_IS_REGEX_MATCH: u64 = fnv1a_hash_64("is_regex_match");
const HASH_IS_NAN: u64 = fnv1a_hash_64("is_nan");
const HASH_IS_NAN: u64 = fnv1a_hash_64("is_nan");
const HASH_IS_REGEX_MATCH: u64 = fnv1a_hash_64("is_regex_match");

Copilot uses AI. Check for mistakes.
@harehare
Copy link
Copy Markdown
Owner Author

@copilot
Could you document the Regex operator?

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 21, 2026

@harehare I've opened a new pull request, #1311, to work on those changes. Once the pull request is ready, I'll request review from you.

📝 docs(mq-lang): document =~ regex match operator; fix hash ordering and syntax highlighting
Copilot AI review requested due to automatic review settings February 21, 2026 06:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

@harehare harehare merged commit 7f8f213 into main Feb 21, 2026
11 checks passed
@harehare harehare deleted the feat/regex-match-operator branch February 21, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation of Regex-based Selectors and Comparison Operators

3 participants