feat: simple-mode code-block highlighting, prompt, and copy rules
Add a custom Shiki grammar for the simple-mode command language (src/grammars/rdbms.mjs), registered with Expressive Code. Two language ids share it: rdbms (real commands) and rdbms-syntax (abstract templates). Simple-mode blocks now highlight; advanced examples keep sql. Separation + copy ergonomics via CSS (global.css): a decorative, copy-safe "> " prompt on rdbms command lines (not in the copy buffer), and the copy button hidden on multi-command rdbms blocks and on rdbms-syntax templates (the app input is single-line, so a multi-command paste is not runnable); single-command, sql, and sh blocks keep copy. Content: convert 22 simple-mode fences to rdbms; lead the simplest examples (first project, Tables reference) with bare "with pk" (the beginner default that creates a ready-made id key), pointing to the named form. Record the fence + prompt conventions in STYLE.md.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// Minimal Shiki / TextMate grammar for the RDBMS Playground *simple-mode*
|
||||
// command language, so docs code blocks fenced as ```rdbms get syntax
|
||||
// highlighting. Advanced-mode examples use the built-in `sql` grammar.
|
||||
//
|
||||
// Keyword/clause vocabulary is taken from the in-app help/usage strings
|
||||
// (`src/friendly/strings/en-US.yaml`) and the command grammar. Matching is
|
||||
// case-insensitive (keywords are case-insensitive in the app; identifiers
|
||||
// are case-preserving and intentionally left unscoped so they read as plain
|
||||
// text against the coloured keywords).
|
||||
//
|
||||
// Two language ids share one grammar:
|
||||
// - `rdbms` — real commands; gets a decorative `> ` prompt via CSS.
|
||||
// - `rdbms-syntax` — abstract syntax templates (with <placeholders>); same
|
||||
// highlighting, but a distinct `data-language` so the
|
||||
// prompt (scoped to data-language='rdbms') is NOT added.
|
||||
|
||||
const patterns = [
|
||||
{ include: '#comment' },
|
||||
{ include: '#string' },
|
||||
{ include: '#flag' },
|
||||
{ include: '#number' },
|
||||
{ include: '#constant' },
|
||||
{ include: '#type' },
|
||||
{ include: '#keyword' },
|
||||
];
|
||||
|
||||
const repository = {
|
||||
comment: {
|
||||
match: '#.*$',
|
||||
name: 'comment.line.number-sign.rdbms',
|
||||
},
|
||||
string: {
|
||||
name: 'string.quoted.single.rdbms',
|
||||
begin: "'",
|
||||
end: "'",
|
||||
patterns: [{ match: "''", name: 'constant.character.escape.rdbms' }],
|
||||
},
|
||||
flag: {
|
||||
match: '--[A-Za-z][A-Za-z-]*',
|
||||
name: 'keyword.operator.flag.rdbms',
|
||||
},
|
||||
number: {
|
||||
match: '\\b[0-9]+(?:\\.[0-9]+)?\\b',
|
||||
name: 'constant.numeric.rdbms',
|
||||
},
|
||||
constant: {
|
||||
match: '(?i)\\b(true|false|null)\\b',
|
||||
name: 'constant.language.rdbms',
|
||||
},
|
||||
type: {
|
||||
match: '(?i)\\b(text|int|real|decimal|bool|date|datetime|blob|serial|shortid)\\b',
|
||||
name: 'support.type.rdbms',
|
||||
},
|
||||
keyword: {
|
||||
match:
|
||||
'(?i)\\b(create|table|tables|drop|add|column|with|pk|to|from|into|values|insert|update|set|where|delete|show|data|rename|change|alter|relationship|relationships|index|indexes|on|as|references|constraint|not|unique|default|check|primary|key|cascade|restrict|and|or|in|between|like|is|explain|replay|undo|redo|save|new|load|rebuild|export|import|copy|mode|help|hint|quit|messages|all|last|types|simple|advanced)\\b',
|
||||
name: 'keyword.control.rdbms',
|
||||
},
|
||||
};
|
||||
|
||||
/** Real simple-mode commands — gets the `> ` prompt (via CSS). */
|
||||
export default {
|
||||
name: 'rdbms',
|
||||
scopeName: 'source.rdbms',
|
||||
aliases: ['rdbms-playground'],
|
||||
patterns,
|
||||
repository,
|
||||
};
|
||||
|
||||
/** Abstract syntax templates — same highlighting, no prompt. */
|
||||
export const rdbmsSyntax = {
|
||||
name: 'rdbms-syntax',
|
||||
scopeName: 'source.rdbms-syntax',
|
||||
patterns,
|
||||
repository,
|
||||
};
|
||||
Reference in New Issue
Block a user