about summary refs log tree commit diff
path: root/app/lib/scope_parser.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-03-02 18:02:48 +0100
committerClaire <claire.github-309c@sitedethib.com>2022-03-02 18:02:48 +0100
commit425a6c90c44a620e5015cd659cf5d8e3bf68ee07 (patch)
tree1bb889bca498b07dd4f3a56a5690ea9c2f602382 /app/lib/scope_parser.rb
parent0b8fe020b599341d78cc03431eb156485c70ebea (diff)
parent462a6f7d721fa0717c5627fd0f0d73ee9ec5a675 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
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