Skip to content

Commit

Permalink
Rework highlight rules for RDT syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
xingrz committed Mar 27, 2024
1 parent 47e5a62 commit 1007ccc
Showing 1 changed file with 64 additions and 6 deletions.
70 changes: 64 additions & 6 deletions src/editor/rdt.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,84 @@
import { Mode as TextMode } from 'ace-code/src/mode/text';
import { TextHighlightRules } from 'ace-code/src/mode/text_highlight_rules';
import type { Ace } from 'ace-code';

export class RDTHighlightRules extends TextHighlightRules {
constructor() {
super();
this.normalizeRules();
}

_basicRules: Ace.HighlightRule[] = [
{
token: 'text',
regex: /\\/,
next: 'start',
},
{
token: 'keyword.operator',
regex: /!@/,
next: 'cellLink',
},
{
token: 'keyword.operator',
regex: /!~/,
next: 'start',
},
{
token: 'keyword.operator',
regex: /(!_)|(__)/,
next: 'cellParams',
},
{
token: 'text',
regex: /~~/,
next: 'sideText',
},
{
token: 'comment.block',
regex: /<!--/,
next: 'comment',
},
];

$rules = {
start: [
...this._basicRules,
{
token: 'keyword.operator.rdt',
regex: '(?:\\\\|!~)',
defaultToken: 'keyword.control',
},
],
cellLink: [
...this._basicRules,
{ defaultToken: 'constant.character' },
],
cellParams: [
...this._basicRules,
{ defaultToken: 'string' },
],
sideText: [
{
token: 'punctuation.definition.string',
regex: '(?:~~.*$)',
token: 'text',
regex: /~~/,
},
{
token: 'keyword.control.statement.rdt',
regex: '(?:[^\\\\(~~)(!~)]+)',
token: 'comment.block',
regex: /<!--/,
next: 'comment',
},
{
regex: /$/,
next: 'start',
},
{ defaultToken: 'string' },
],
comment: [
{
token: 'comment.block',
regex: /-->/,
next: 'start',
},
{ defaultToken: 'comment.block' },
],
};
}
Expand Down

0 comments on commit 1007ccc

Please sign in to comment.