Skip to content

Commit

Permalink
feat(prism): add conditions tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh committed Nov 5, 2023
1 parent d589d10 commit 48c2635
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/theme/supported-themes/openfga-dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const openfgaDark: OpenFgaThemeConfiguration = {
[OpenFgaDslThemeTokenType.TYPE]: "#79ED83",
[OpenFgaDslThemeTokenType.RELATION]: "#20F1F5",
[OpenFgaDslThemeTokenType.DIRECTLY_ASSIGNABLE]: "#CEEC93",
[OpenFgaDslThemeTokenType.CONDITION]: "#79ED83",
[OpenFgaDslThemeTokenType.CONDITION_PARAM]: "#20F1F5",
[OpenFgaDslThemeTokenType.CONDITION_PARAM_TYPE]: "#AAAAAA",
},
styles: {},
};
3 changes: 3 additions & 0 deletions src/theme/theme.typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export enum OpenFgaDslThemeTokenType {
TYPE = "type",
RELATION = "relation",
DIRECTLY_ASSIGNABLE = "directly-assignable",
CONDITION = "condition",
CONDITION_PARAM = "condition-param",
CONDITION_PARAM_TYPE = "condition-param-type",
}

export enum OpenFgaDslThemeToken {
Expand Down
6 changes: 3 additions & 3 deletions src/theme/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const tokenTypeMap: Record<OpenFgaDslThemeToken, OpenFgaDslThemeTokenType> = {
[OpenFgaDslThemeToken.OPERATOR_OR]: OpenFgaDslThemeTokenType.KEYWORD,
[OpenFgaDslThemeToken.KEYWORD_CONDITION]: OpenFgaDslThemeTokenType.KEYWORD,
[OpenFgaDslThemeToken.KEYWORD_WITH]: OpenFgaDslThemeTokenType.KEYWORD,
[OpenFgaDslThemeToken.VALUE_CONDITION]: OpenFgaDslThemeTokenType.TYPE,
[OpenFgaDslThemeToken.VALUE_CONDITION]: OpenFgaDslThemeTokenType.CONDITION,
[OpenFgaDslThemeToken.VALUE_RELATION_COMPUTED]: OpenFgaDslThemeTokenType.DEFAULT,
[OpenFgaDslThemeToken.VALUE_RELATION_NAME]: OpenFgaDslThemeTokenType.RELATION,
[OpenFgaDslThemeToken.VALUE_RELATION_TUPLE_TO_USERSET_COMPUTED]: OpenFgaDslThemeTokenType.DEFAULT,
Expand All @@ -32,8 +32,8 @@ const tokenTypeMap: Record<OpenFgaDslThemeToken, OpenFgaDslThemeTokenType> = {
[OpenFgaDslThemeToken.VALUE_TYPE_RESTRICTIONS_RELATION]: OpenFgaDslThemeTokenType.DIRECTLY_ASSIGNABLE,
[OpenFgaDslThemeToken.VALUE_TYPE_RESTRICTIONS_TYPE]: OpenFgaDslThemeTokenType.DIRECTLY_ASSIGNABLE,
[OpenFgaDslThemeToken.VALUE_TYPE_RESTRICTIONS_WILDCARD]: OpenFgaDslThemeTokenType.DIRECTLY_ASSIGNABLE,
[OpenFgaDslThemeToken.CONDITION_PARAM]: OpenFgaDslThemeTokenType.RELATION,
[OpenFgaDslThemeToken.CONDITION_PARAM_TYPE]: OpenFgaDslThemeTokenType.DEFAULT,
[OpenFgaDslThemeToken.CONDITION_PARAM]: OpenFgaDslThemeTokenType.CONDITION_PARAM,
[OpenFgaDslThemeToken.CONDITION_PARAM_TYPE]: OpenFgaDslThemeTokenType.CONDITION_PARAM_TYPE,
};

export function getThemeTokenStyle(
Expand Down
14 changes: 13 additions & 1 deletion src/tools/prism/language-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const languageDefinition = {
[OpenFgaDslThemeTokenType.COMMENT]: {
pattern: /^\s*#.*/,
},
[OpenFgaDslThemeTokenType.KEYWORD]: /\b(type|relations|define|and|or|but not|from|as|model|schema)\b/,
[OpenFgaDslThemeTokenType.KEYWORD]: /\b(type|relations|define|and|or|but not|from|as|model|schema|condition)\b/,
[OpenFgaDslThemeTokenType.TYPE]: {
pattern: /(\btype\s+)\w+/i,
lookbehind: true,
Expand All @@ -16,4 +16,16 @@ export const languageDefinition = {
greedy: true,
},
[OpenFgaDslThemeTokenType.DIRECTLY_ASSIGNABLE]: /\[.*]|self/,
[OpenFgaDslThemeTokenType.CONDITION]: {
pattern: /(\bcondition\s+)\w+/i,
lookbehind: true,
greedy: true,
},
"condition-params": {
pattern: /\(.*\)\s*{/,
inside: {
"condition-param": /\b(\w+)\s*:/i,
"condition-param-type": /\b(string|int|map|uint|list|timestamp|bool|duration|double|ipaddress)\b/,
},
},
};

0 comments on commit 48c2635

Please sign in to comment.