Skip to content

Commit

Permalink
Try to minimise diff and document
Browse files Browse the repository at this point in the history
  • Loading branch information
jiribenes committed Jul 20, 2024
1 parent cc1e0eb commit 58c0700
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/effekt-syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import ILanguage = monaco.languages.IMonarchLanguage;
import ITheme = monaco.editor.IStandaloneThemeData;

export const syntax = <ILanguage>{
defaultToken: '',
// defaultToken: 'invalid',
tokenPostfix: '.effekt',

keywords: [
'module', 'import', 'def', 'val', 'var', 'effect', 'type', 'match',
'case', 'record', 'extern', 'include', 'resume', 'with', 'if', 'try',
'else', 'do', 'handle', 'while', 'fun', 'region', 'in', 'new',
'box', 'unbox', 'interface', 'resource', 'and', 'is', 'namespace',
'return', 'as', 'pure'
'return', 'as'
],

definitionKeywords: [
Expand All @@ -22,43 +22,57 @@ export const syntax = <ILanguage>{
literals: ['true', 'false'],

operators: [
'=', '>', '<', '!', '~', '?', ':', '==', '<=', '>=', '!=',
'&&', '||', '++', '--', '+', '-', '*', '/', '&', '|', '^', '%',
'<<', '>>', '>>>', '+=', '-=', '*=', '/=', '&=', '|=', '^=',
'%=', '<<=', '>>=', '>>>=', '=>', '::'
'=',
':',
'>', '<', '==', '<=', '>=', '!=',
'&&', '||',
'++',
'+', '-', '*', '/',
'=>', '::'
],

// we include these common regular expressions
symbols: /[=><!~?:&|+\-*\/\^%]+/,

// supported escapes
escapes: /\\(?:[btnfr\\"']|u[0-9A-Fa-f]{4})/,

// The main tokenizer for our languages
tokenizer: {
root: [
[/[a-z_$][\w$]*/, {
// identifiers and keywords
[/[a-z_$][\w$?!]*/, {
cases: {
'@definitionKeywords': { token: 'keyword', next: '@definition' },
'@keywords': 'keyword',
'@literals': 'literal',
'@default': 'identifier'
}
}],
[/[A-Z][\w\$]*/, 'type.identifier'],
[/[A-Z][\w\$?!]*/, 'type.identifier'],

// whitespace
{ include: '@whitespace' },

// delimiters and operators
[/[{}()\[\]]/, '@brackets'],
[/[<>](?!@symbols)/, '@brackets'],
[/@symbols/, { cases: { '@operators': 'operator', '@default': '' } }],
[/@symbols/, { cases: { '@operators': 'operator',
'@default': '' } } ],

// numbers
[/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
[/0[xX][0-9a-fA-F]+/, 'number.hex'],
[/\d+/, 'number'],

// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],

// strings
[/"([^"\\]|\\.)*$/, 'string.invalid'],
[/"/, { token: 'string.quote', bracket: '@open', next: '@string' }],

// characters
[/'[^\\']'/, 'string'],
[/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
[/'/, 'string.invalid']
Expand Down Expand Up @@ -93,8 +107,8 @@ export const syntax = <ILanguage>{

whitespace: [
[/[ \t\r\n]+/, 'white'],
[/\/\*/, 'comment', '@comment'],
[/\/\/.*$/, 'comment'],
[/\/\*/, 'comment', '@comment' ],
[/\/\/.*$/, 'comment'],
],
},
};
Expand All @@ -119,6 +133,7 @@ export const docsTheme = <ITheme>{
]
};


export const pageTheme = <ITheme>{
base: 'vs',
inherit: false,
Expand Down

0 comments on commit 58c0700

Please sign in to comment.