Implementation:MaterializeInc Materialize Mzsql TextMate Grammar
| Knowledge Sources | |
|---|---|
| Domains | Developer_Tooling, Editor_Integration, SQL |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
A TextMate grammar definition file that provides syntax highlighting for Materialize SQL (mzsql) in Visual Studio Code.
Description
This mzsql.tmLanguage.json file defines the lexical grammar for the Materialize SQL dialect using the TextMate grammar format consumed by VS Code. It was originally adapted from the Microsoft vscode-mssql SQL grammar and extended with Materialize-specific keywords such as CREATE SOURCE, CREATE SINK, PEEK, TAIL, SHOW SOURCES, and CREATE MATERIALIZED VIEW. The grammar provides tokenization rules for SQL DDL/DML keywords, data types with optional precision parameters, string literals (single-quoted, double-quoted, backtick-quoted), comments (line and block), numeric constants, operators, aggregate/window/system functions, and an extensive keyword list covering hundreds of SQL and T-SQL keywords.
Usage
This file is consumed by the Materialize VS Code extension to provide syntax highlighting when editing .mzsql files or when the language mode is set to "Materialize SQL". Developers modify this grammar when new SQL keywords or syntax constructs are added to the Materialize SQL dialect.
Code Reference
Source Location
- Repository: MaterializeInc_Materialize
- File: misc/editor/vscode/syntaxes/mzsql.tmLanguage.json
Signature
{
"name": "Materialize SQL",
"scopeName": "source.mzsql",
"patterns": [
{ "match": "((?<!@)@)\\b(\\w+)\\b", "name": "text.variable" },
{ "include": "#comments" },
{
"match": "(?i:\\s*(create(?:\\s+or\\s+replace)?)\\s+(aggregate|...|source|sink|(?:materialized\\s+)?view)...)",
"name": "meta.create.sql"
},
{
"match": "(?i:\\b(select(\\s+distinct)?|insert\\s+(ignore\\s+)?into|update|delete|peek|tail|from|...)\\b)",
"name": "keyword.other.DML.sql"
},
// Data types with optional precision: bigint, varchar(N), numeric(P,S), timestamp(tz)
// Operators: comparison, math, concatenation, star
// Functions: aggregate, conversion, datetime, ranking, string, system
],
"repository": {
"comments": { /* --, #, and block comment patterns */ },
"strings": { /* single-quoted, double-quoted, backtick-quoted */ },
"regexps": { /* regex literal patterns */ },
"string_escape": { "match": "\\\\." },
"string_interpolation": { "match": "(#\\{)([^\\}]*)(\\})" }
}
}
Import
# The grammar is referenced in the VS Code extension's package.json:
# "grammars": [{
# "language": "mzsql",
# "scopeName": "source.mzsql",
# "path": "./syntaxes/mzsql.tmLanguage.json"
# }]
# Install the Materialize VS Code extension to activate this grammar
code --install-extension materialize.vscode-materialize
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| Source text | String (SQL) | Yes | Materialize SQL source code to be tokenized for syntax highlighting |
| scopeName | String | Yes | TextMate scope identifier: "source.mzsql" |
Outputs
| Name | Type | Description |
|---|---|---|
| Token scopes | TextMate scopes | Classified token scopes (e.g., keyword.other.DML.sql, storage.type.sql, string.quoted.single.sql) used by VS Code themes for coloring |
| Syntax tree | TextMate parse tree | Hierarchical token structure enabling bracket matching, code folding, and scope-based operations |
Usage Examples
-- Example Materialize SQL with syntax highlighting provided by this grammar:
CREATE MATERIALIZED VIEW active_users AS
SELECT user_id, count(*) AS event_count
FROM user_events
WHERE event_time > now() - INTERVAL '1 hour'
GROUP BY user_id
HAVING count(*) > 10;
CREATE SOURCE kafka_source
FROM KAFKA BROKER 'localhost:9092' TOPIC 'events'
FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY 'http://localhost:8081';
SHOW SOURCES;