From 6706f88d5b563ed8aaf7babb45e5f85dab001db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Dujava?= <19737748+jdujava@users.noreply.github.com> Date: Tue, 23 Jul 2024 09:16:06 +0200 Subject: [PATCH] Better color reference (#151) - add `\mathcolor` - support directly passing color scheme and spec - (optionally) include following argument Signed-off-by: Jonas Dujava --- grammar.js | 19 ++++++--- src/grammar.json | 100 +++++++++++++++++++++++++++++++++----------- src/node-types.json | 40 +++++++++++++++++- 3 files changed, 128 insertions(+), 31 deletions(-) diff --git a/grammar.js b/grammar.js index 46c1657b5..a63845406 100644 --- a/grammar.js +++ b/grammar.js @@ -1188,12 +1188,21 @@ module.exports = grammar({ ), color_reference: $ => - seq( - field( - 'command', - choice('\\color', '\\colorbox', '\\textcolor', '\\pagecolor'), + prec.right( + seq( + field( + 'command', + choice('\\color', '\\pagecolor', '\\textcolor', '\\mathcolor','\\colorbox'), + ), + choice( + field('name', $.curly_group_text), + seq( + field('model', $.brack_group_text), + field('spec', $.curly_group), + ), + ), + optional(field('text', $.curly_group)), ), - field('name', $.curly_group_text), ), tikz_library_import: $ => diff --git a/src/grammar.json b/src/grammar.json index f24031fe3..dac43ab98 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -6513,42 +6513,92 @@ ] }, "color_reference": { - "type": "SEQ", - "members": [ - { - "type": "FIELD", - "name": "command", - "content": { + "type": "PREC_RIGHT", + "value": 0, + "content": { + "type": "SEQ", + "members": [ + { + "type": "FIELD", + "name": "command", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "\\color" + }, + { + "type": "STRING", + "value": "\\pagecolor" + }, + { + "type": "STRING", + "value": "\\textcolor" + }, + { + "type": "STRING", + "value": "\\mathcolor" + }, + { + "type": "STRING", + "value": "\\colorbox" + } + ] + } + }, + { "type": "CHOICE", "members": [ { - "type": "STRING", - "value": "\\color" + "type": "FIELD", + "name": "name", + "content": { + "type": "SYMBOL", + "name": "curly_group_text" + } }, { - "type": "STRING", - "value": "\\colorbox" - }, + "type": "SEQ", + "members": [ + { + "type": "FIELD", + "name": "model", + "content": { + "type": "SYMBOL", + "name": "brack_group_text" + } + }, + { + "type": "FIELD", + "name": "spec", + "content": { + "type": "SYMBOL", + "name": "curly_group" + } + } + ] + } + ] + }, + { + "type": "CHOICE", + "members": [ { - "type": "STRING", - "value": "\\textcolor" + "type": "FIELD", + "name": "text", + "content": { + "type": "SYMBOL", + "name": "curly_group" + } }, { - "type": "STRING", - "value": "\\pagecolor" + "type": "BLANK" } ] } - }, - { - "type": "FIELD", - "name": "name", - "content": { - "type": "SYMBOL", - "name": "curly_group_text" - } - } - ] + ] + } }, "tikz_library_import": { "type": "SEQ", diff --git a/src/node-types.json b/src/node-types.json index 98fca424e..8323475a4 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -1709,6 +1709,10 @@ "type": "\\colorbox", "named": false }, + { + "type": "\\mathcolor", + "named": false + }, { "type": "\\pagecolor", "named": false @@ -1719,15 +1723,45 @@ } ] }, + "model": { + "multiple": false, + "required": false, + "types": [ + { + "type": "brack_group_text", + "named": true + } + ] + }, "name": { "multiple": false, - "required": true, + "required": false, "types": [ { "type": "curly_group_text", "named": true } ] + }, + "spec": { + "multiple": false, + "required": false, + "types": [ + { + "type": "curly_group", + "named": true + } + ] + }, + "text": { + "multiple": false, + "required": false, + "types": [ + { + "type": "curly_group", + "named": true + } + ] } } }, @@ -9221,6 +9255,10 @@ "type": "\\let", "named": false }, + { + "type": "\\mathcolor", + "named": false + }, { "type": "\\nameCref", "named": false