Skip to content

Instantly share code, notes, and snippets.

@srenatus
Last active February 14, 2020 13:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srenatus/0b8a6f07fbd33dde4314811dfe7318dd to your computer and use it in GitHub Desktop.
Save srenatus/0b8a6f07fbd33dde4314811dfe7318dd to your computer and use it in GitHub Desktop.
@eephillip has created a package for the sublime syntax, see https://github.com/eephillip/rego.sublime-package
package authz
allow {
input.path = ["users"]
input.method = "POST"
}
allow {
input.path = ["users", profile_id]
input.method = "GET"
profile_id = input.user_id
}
<head><title>example.rego</title><style>
pre {
font-size:13px;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
}</style></head>
<body style="background-color:#2b303b;">
<pre style="background-color:#2b303b;">
<span style="color:#b48ead;">package </span><span style="color:#c0c5ce;">authz
</span><span style="color:#c0c5ce;">
</span><span style="color:#8fa1b3;">allow</span><span style="color:#c0c5ce;"> {
</span><span style="color:#c0c5ce;"> input.path = [&quot;</span><span style="color:#a3be8c;">users</span><span style="color:#c0c5ce;">&quot;]
</span><span style="color:#c0c5ce;"> input.method = &quot;</span><span style="color:#a3be8c;">POST</span><span style="color:#c0c5ce;">&quot;
</span><span style="color:#c0c5ce;">}
</span><span style="color:#c0c5ce;">
</span><span style="color:#8fa1b3;">allow</span><span style="color:#c0c5ce;"> {
</span><span style="color:#c0c5ce;"> input.path = [&quot;</span><span style="color:#a3be8c;">users</span><span style="color:#c0c5ce;">&quot;, profile_id]
</span><span style="color:#c0c5ce;"> input.method = &quot;</span><span style="color:#a3be8c;">GET</span><span style="color:#c0c5ce;">&quot;
</span><span style="color:#c0c5ce;"> profile_id = input.user_id
</span><span style="color:#c0c5ce;">}
</span></pre>
</body>
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Rego
file_extensions:
- rego
- Rego
scope: source.rego
contexts:
main:
- include: comment
- include: keyword
- include: operator
- include: head
- include: term
comment:
- match: (#).*$\n?
scope: comment.line.number-sign.rego
captures:
1: punctuation.definition.comment.rego
call:
- match: '([a-zA-Z_][a-zA-Z0-9_]*)\('
scope: meta.function-call.rego
captures:
1: support.function.any-method.rego
constant:
- match: \b(?:true|false|null)\b
scope: constant.language.rego
head:
- match: "^([[:alpha:]_][[:alnum:]_]*)"
captures:
1: entity.name.function.declaration
push:
- meta_scope: meta.function.rego
- match: '(=|{|\n)'
pop: true
- include: term
keyword:
- match: (^|\s+)(?:(default|not|package|import|as|with|else))\s+
scope: keyword.other.rego
number:
- match: |-
(?x: # turn on extended mode
-? # an optional minus
(?:
0 # a zero
| # ...or...
[1-9] # a 1-9 character
\d* # followed by zero or more digits
)
(?:
(?:
\. # a period
\d+ # followed by one or more digits
)?
(?:
[eE] # an e character
[+-]? # followed by an option +/-
\d+ # followed by one or more digits
)? # make exponent optional
)? # make decimal portion optional
)
scope: constant.numeric.rego
operator:
- match: \=|\!\=|>|<|<\=|>\=|\+|-|\*|%|/|\||&|:\=
scope: keyword.operator.comparison.rego
string:
- match: '"'
captures:
0: punctuation.definition.string.begin.rego
push:
- meta_scope: string.quoted.double.rego
- match: '"'
captures:
0: punctuation.definition.string.end.rego
pop: true
- match: |-
(?x: # turn on extended mode
\\ # a literal backslash
(?: # ...followed by...
["\\/bfnrt] # one of these characters
| # ...or...
u # a u
[0-9a-fA-F]{4} # and four hex digits
)
)
scope: constant.character.escape.rego
- match: \\.
scope: invalid.illegal.unrecognized-string-escape.rego
term:
- include: constant
- include: string
- include: number
- include: call
- include: variable
variable:
- match: '\b[[:alpha:]_][[:alnum:]_]*\b'
scope: meta.identifier.rego
@FanchenBao
Copy link

Thanks for doing this!

@srenatus
Copy link
Author

@eephillip
Copy link

ℹ️ @FanchenBao: it's been picked up by @eephillip here: https://github.com/eephillip/rego.sublime-package

 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment