about summary refs log tree commit diff
path: root/app/lib/scope_parser.rb
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2022-03-08 17:55:38 -0600
committerStarfall <us@starfall.systems>2022-03-08 17:55:38 -0600
commit239d67fc2c0ec82617de50a9831bc1a9efc30ecc (patch)
treea6806025fe9e094994366434b08093cee5923557 /app/lib/scope_parser.rb
parentad1733ea294c6049336a9aeeb7ff96c8fea22cfa (diff)
parent02133866e6915e37431298b396e1aded1e4c44c5 (diff)
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/lib/scope_parser.rb')
-rw-r--r--app/lib/scope_parser.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/lib/scope_parser.rb b/app/lib/scope_parser.rb
new file mode 100644
index 000000000..d268688c8
--- /dev/null
+++ b/app/lib/scope_parser.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class ScopeParser < Parslet::Parser
+  rule(:term)      { match('[a-z]').repeat(1).as(:term) }
+  rule(:colon)     { str(':') }
+  rule(:access)    { (str('write') | str('read')).as(:access) }
+  rule(:namespace) { str('admin').as(:namespace) }
+  rule(:scope)     { ((namespace >> colon).maybe >> ((access >> colon >> term) | access | term)).as(:scope) }
+  root(:scope)
+end