commit b567823d48d8831a38596158d9236a37d2d908cc
parent d5bdca5656fcab659890730313dc3d45ca2394f2
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date: Mon, 8 Jun 2026 00:45:39 +0200
Website example parsed
Diffstat:
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/mnt.janet b/src/mnt.janet
@@ -1,9 +1,9 @@
-(def base_indent 2)
+(def- base_indent 4)
-(defn inc_indent [x]
+(defn- inc_indent [x]
(+ x base_indent))
-(def mnt_peg
+(def peg
(peg/compile
~{:main (* (only-tags (constant 0 :col)) :all :check_empty)
:key (* :check_indent (<- (to (+ " :" ":"))) :check_end)
@@ -11,7 +11,7 @@
:increase (only-tags (/ (backref :col) ,inc_indent :col))
:indent (lenprefix (backref :col) " ")
:list (some (* :indent "-" :val (+ -1 (some "\n"))))
- :comment (some (* "#" (to (+ "\n" -1)) (? "\n")))
+ :comment (some (* (any " ") "#" (to (+ "\n" -1)) (? "\n")))
:all (* (any :comment) (+ :lists :maps :nil))
:map (some (unref (group (* :indent :key ":" (+ (* -1 :nil) (* :val (+ (some "\n") -1)) (* (some "\n") :increase :all)))) :col))
:maps (/ (group (* :map (any (+ :comment :map)))) ,from-pairs)
@@ -24,3 +24,11 @@
:nil (constant :nil)
}))
+(defn parse [str] ((peg/match peg str) 0))
+
+(defn parsefile [path]
+ (def f (file/open path :rn))
+ (def p (parse (file/read f :all)))
+ (file/close f)
+ p)
+