Skip to content

Commit

Permalink
fix: monaco theme and language definition
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh committed Dec 2, 2022
1 parent dbec9e4 commit c0b1591
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
75 changes: 62 additions & 13 deletions src/syntax-highlighters/monaco/language-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,53 @@ export const language = <MonacoEditor.languages.IMonarchLanguage>{
keywords: [],
operators: [],

identifiers: new RegExp(/(?:\w|-[a-zA-Z])*/),
identifiers: new RegExp(/(?!self)(?:\w|-[a-zA-Z])*/),

brackets: [
{ open: "[", close: "]", token: OpenFgaDslThemeToken.DELIMITER_BRACKET_TYPE_RESTRICTIONS },
{ open: "(", close: ")", token: OpenFgaDslThemeToken.DELIMITER_BRACKET_RELATION_DEFINITION },
],

typeRestrictionsDelimiters: [
{ open: "[", close: "]", token: OpenFgaDslThemeToken.DELIMITER_BRACKET_TYPE_RESTRICTIONS },
[new RegExp(/,/), OpenFgaDslThemeToken.DELIMITER_BRACKET_RELATION_DEFINITION],
],

tokenizer: {
root: [
{ include: "@whitespace" },

[new RegExp(/[:]/), OpenFgaDslThemeToken.DELIMITER_DEFINE_COLON],
[new RegExp(/[{}[\]()]/), "@brackets"],
[
new RegExp(/^(\s*#).*/),
OpenFgaDslThemeToken.COMMENT,
],

[new RegExp(/@[a-zA-Z]\w*/), "tag"],
[
new RegExp(/(\[)(\s*)(@identifiers)(\s*)(\])/),
[
"@brackets",
"@whitespace",
OpenFgaDslThemeToken.VALUE_TYPE_RESTRICTIONS_TYPE,
"@whitespace",
"@brackets"
]
],
[
new RegExp(/(,)(\s*)(@identifiers)(\s*)(\])/),
[
OpenFgaDslThemeToken.DELIMITER_COMMA_TYPE_RESTRICTIONS,
"@whitespace",
OpenFgaDslThemeToken.VALUE_TYPE_RESTRICTIONS_TYPE,
"@whitespace",
"@brackets"
]
],
[
new RegExp(/(\[)(\s*)(@identifiers)(\s*)(,)/),
[
"@brackets",
"@whitespace",
"type.type-restrictions.value",
"@whitespace",
OpenFgaDslThemeToken.DELIMITER_COMMA_TYPE_RESTRICTIONS
]
],
[new RegExp(/[{}[\]()]/), "@brackets"],

[
new RegExp(/(schema)(\s+)(\d\.\d)/),
Expand All @@ -94,6 +121,23 @@ export const language = <MonacoEditor.languages.IMonarchLanguage>{
new RegExp(/(but not)(\s+)(@identifiers)/),
[OpenFgaDslThemeToken.OPERATOR_BUT_NOT, "@whitespace", OpenFgaDslThemeToken.VALUE_RELATION_COMPUTED],
],

[
new RegExp(/(as)(\s+)(@identifiers)/),
[
OpenFgaDslThemeToken.KEYWORD_AS,
"@whitespace",
OpenFgaDslThemeToken.VALUE_RELATION_COMPUTED,
]
],
[
new RegExp(/(:)(\s+)(@identifiers)/),
[
OpenFgaDslThemeToken.DELIMITER_DEFINE_COLON,
"@whitespace",
OpenFgaDslThemeToken.VALUE_RELATION_COMPUTED,
]
],
[
new RegExp(/(@identifiers)(\s+)(from)(\s+)(@identifiers)/),
[
Expand All @@ -120,8 +164,11 @@ export const language = <MonacoEditor.languages.IMonarchLanguage>{
OpenFgaDslThemeToken.VALUE_TYPE_RESTRICTIONS_WILDCARD,
],
],
[new RegExp(/,/), OpenFgaDslThemeToken.DELIMITER_COMMA_TYPE_RESTRICTIONS],
[new RegExp(/but\snot/), OpenFgaDslThemeToken.OPERATOR_BUT_NOT],

[":", OpenFgaDslThemeToken.DELIMITER_DEFINE_COLON],
[",", OpenFgaDslThemeToken.DELIMITER_COMMA_TYPE_RESTRICTIONS],
[Keyword.BUT_NOT, OpenFgaDslThemeToken.OPERATOR_BUT_NOT],
[Keyword.SELF, OpenFgaDslThemeToken.KEYWORD_SELF],
[
new RegExp(/@identifiers/),
{
Expand All @@ -133,10 +180,12 @@ export const language = <MonacoEditor.languages.IMonarchLanguage>{
[Keyword.DEFINE]: OpenFgaDslThemeToken.KEYWORD_DEFINE,
[Keyword.FROM]: OpenFgaDslThemeToken.KEYWORD_FROM,
[Keyword.AS]: OpenFgaDslThemeToken.KEYWORD_AS,
[Keyword.SELF]: OpenFgaDslThemeToken.KEYWORD_SELF,
[Keyword.MODEL]: OpenFgaDslThemeToken.KEYWORD_MODEL,
[Keyword.SCHEMA]: { token: OpenFgaDslThemeToken.KEYWORD_SCHEMA },
"@default": "identifier",
// TODO: This should be "identifier", however because tupleset was not properly
// detected with the rules above, this is the quickiest hacky fix we can do to
// get it out there for people to use
"@default": OpenFgaDslThemeToken.VALUE_RELATION_TUPLE_TO_USERSET_TUPLESET,
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/theme/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export function getThemeTokenStyle(
token: OpenFgaDslThemeToken,
themeConfig: OpenFgaThemeConfiguration,
): {
color?: string;
foreground?: string;
fontStyle?: string;
} {
return {
color:
foreground:
themeConfig.rawColorOverrides?.[token] ||
themeConfig.colors[tokenTypeMap[token || OpenFgaDslThemeTokenType.DEFAULT]],
fontStyle:
Expand Down

0 comments on commit c0b1591

Please sign in to comment.