diff --git a/grammar/code/janet.janet b/grammar/code/janet.janet new file mode 100644 index 0000000..d4b570c --- /dev/null +++ b/grammar/code/janet.janet @@ -0,0 +1,41 @@ +#!/usr/bin/env janet + +(def to-ast + ~{ + :ws (set " \t\r\f\n\0\v") + :readermac (set "';~,|") + :symchars (+ (range "09" "AZ" "az" "\x80\xFF") (set "!$%&*+-./:@^_")) + :token (some :symchars) + :hex (range "09" "af" "AF") + :escape (* "\\" (+ (set `"'0?\abefnrtvz`) + (* "x" :hex :hex) + (* "u" [4 :hex]) + (* "U" [6 :hex]) + (error (constant "bad escape")))) + :comment (* "#" (any (if-not (+ "\n" -1) 1))) + :symbol :token + :keyword (* ":" (any :symchars)) + :constant (* (+ "true" "false" "nil") (not :symchars)) + :bytes (* "\"" (any (+ :escape (if-not "\"" 1))) "\"") + :string :bytes + :buffer (* "@" :bytes) + :long-bytes {:delim (some "`") + :open (capture :delim :n) + :close (cmt (* (not (> -1 "`")) (-> :n) '(backmatch :n)) ,=) + :main (drop (* :open (any (if-not :close 1)) :close))} + :long-string :long-bytes + :long-buffer (* "@" :long-bytes) + :number (cmt (<- :token) ,scan-number) + :raw-value (+ :comment :constant :number :keyword + :string :buffer :long-string :long-buffer + :parray :barray :ptuple :btuple :struct :dict :symbol) + :value (* (any (+ :ws :readermac)) :raw-value (any :ws)) + :root (any :value) + :root2 (any (* :value :value)) + :ptuple (* "(" :root (+ ")" (error ""))) + :btuple (* "[" :root (+ "]" (error ""))) + :struct (* "{" :root2 (+ "}" (error ""))) + :parray (* "@" :ptuple) + :barray (* "@" :btuple) + :dict (* "@" :struct) + :main :root}) diff --git a/grammar/php.janet b/grammar/code/php.janet similarity index 100% rename from grammar/php.janet rename to grammar/code/php.janet diff --git a/grammar/page/markdown.janet b/grammar/page/markdown.janet new file mode 100644 index 0000000..d6c69fb --- /dev/null +++ b/grammar/page/markdown.janet @@ -0,0 +1,47 @@ +#!/usr/bin/env janet + +(def to-ast + "A custom markdown flavored grammar" + ~{ + # Symbole + :end-of-line (* (? "\r") "\n") + :space "\u0020" + :tab (+ "\u0009" (4 :space)) + + :code-block-tag "```" + :list-item-starter (+ "*" "-") + :italic-tag "*" + :bold-tag "**" + :stroke-tag "~~" + :code-line-tag "`" + + :rich-text-tag (+ :italic-tag :bold-tag :stroke-tag :code-line-tag) + :basic-text (some (if-not (+ :end-of-line :code-line-tag :stroke-tag :bold-tag :italic-tag) 1)) + + :c-basic-text (cmt (<- :basic-text),|[:text $0]) + + :bold (cmt (* :bold-tag :rich-text :bold-tag),|[:bold $0 $&]) + :italic (cmt (* :italic-tag :rich-text :italic-tag),|[:italic $0 $&]) + :stroke (cmt (* :stroke-tag :rich-text :stroke-tag),|[:stroke $0 $&]) + :code-line (cmt (* :code-line-tag (<- :rich-text) :code-line-tag),|[:code-line $0 $&]) + + :rich-text (cmt (some (+ :code-line :bold :italic :stroke :c-basic-text)),|(map (fn [arg] [(get arg 0) (get arg 1)]) $&)) + :line (cmt (* :rich-text :end-of-line),|[:line $0]) + + # Block + :heading (cmt (* (<- (between 1 6 "#")) :space (<- :basic-text)),|[:heading (length $0) $1]) + :hr (cmt (* (at-least 3 (+ "-" "_" "*")) :end-of-line),|[:hr]) + :code-block (cmt (* :code-block-tag (? (<- :basic-text)) :end-of-line (<- (some (if-not :code-block-tag 1))) :code-block-tag),|[:code-block $0 $1]) + :quote (cmt (* ">" :space (? :rich-text)),|[:quote $0]) + :list-item (cmt (* (<- (? (between 0 2 :tab))) :list-item-starter :space :rich-text),|[:list-item (/ (length $0) 4) $1]) + :list (cmt (some (* :list-item (? :end-of-line))),|[:list $&]) + + :block (+ :heading + :hr + :code-block + :quote + :list + :line + :end-of-line) + + :main (some (* :block (? :end-of-line)))}) diff --git a/blog.janet b/page.janet similarity index 51% rename from blog.janet rename to page.janet index 6ff4a12..244bc12 100644 --- a/blog.janet +++ b/page.janet @@ -1,7 +1,9 @@ #!/usr/bin/env janet -(import ./grammar/php :as php) -(import ./grammar/janet :as janet) +(import ./grammar/code/php :as php) +(import ./grammar/code/janet :as janet) + +(import ./grammar/page/markdown :as markdown-page) (defn read-from-file [file-path] "Read a file from string filepath" @@ -27,52 +29,6 @@ (string/replace-all ">" ">" (string/replace-all "&" "&" value)))))) -(def md-to-ast - "A custom markdown flavored grammar" - ~{ - # Symbole - :end-of-line (* (? "\r") "\n") - :space "\u0020" - :tab (+ "\u0009" (4 :space)) - - :code-block-tag "```" - :list-item-starter (+ "*" "-") - :italic-tag "*" - :bold-tag "**" - :stroke-tag "~~" - :code-line-tag "`" - - :rich-text-tag (+ :italic-tag :bold-tag :stroke-tag :code-line-tag) - :basic-text (some (if-not (+ :end-of-line :code-line-tag :stroke-tag :bold-tag :italic-tag) 1)) - - :c-basic-text (cmt (<- :basic-text),|[:text $0]) - - :bold (cmt (* :bold-tag :rich-text :bold-tag),|[:bold $0 $&]) - :italic (cmt (* :italic-tag :rich-text :italic-tag),|[:italic $0 $&]) - :stroke (cmt (* :stroke-tag :rich-text :stroke-tag),|[:stroke $0 $&]) - :code-line (cmt (* :code-line-tag (<- :rich-text) :code-line-tag),|[:code-line $0 $&]) - - :rich-text (cmt (some (+ :code-line :bold :italic :stroke :c-basic-text)),|(map (fn [arg] [(get arg 0) (get arg 1)]) $&)) - :line (cmt (* :rich-text :end-of-line),|[:line $0]) - - # Block - :heading (cmt (* (<- (between 1 6 "#")) :space (<- :basic-text)),|[:heading (length $0) $1]) - :hr (cmt (* (at-least 3 (+ "-" "_" "*")) :end-of-line),|[:hr]) - :code-block (cmt (* :code-block-tag (? (<- :basic-text)) :end-of-line (<- (some (if-not :code-block-tag 1))) :code-block-tag),|[:code-block $0 $1]) - :quote (cmt (* ">" :space (? :rich-text)),|[:quote $0]) - :list-item (cmt (* (<- (? (between 0 2 :tab))) :list-item-starter :space :rich-text),|[:list-item (/ (length $0) 4) $1]) - :list (cmt (some (* :list-item (? :end-of-line))),|[:list $&]) - - :block (+ :heading - :hr - :code-block - :quote - :list - :line - :end-of-line) - - :main (some (* :block (? :end-of-line)))}) - (defn code-ast-to-html [ast] (string/join @@ -89,17 +45,17 @@ ast) "")) -(defn ast-to-html +(defn page-ast-to-html "Convert an AST to html" [ast] (defn to-codeblock [lang value] (string "
" (code-ast-to-html (peg/match (eval-string (string lang "/to-ast")) value)) "
")) - (defn to-codeline [value] (string "" (ast-to-html value) "")) + (defn to-codeline [value] (string "" (page-ast-to-html value) "")) (defn to-heading [level value] (string "" (htmlspecialchars value) "")) - (defn to-quote [value] (string "
" (ast-to-html value) "
")) - (defn to-line [value] (string "

" (ast-to-html value) "

")) - (defn to-italic [value] (string "" (ast-to-html value) "")) - (defn to-bold [value] (string "" (ast-to-html value) "")) - (defn to-stroke [value] (string "" (ast-to-html value) "")) + (defn to-quote [value] (string "
" (page-ast-to-html value) "
")) + (defn to-line [value] (string "

" (page-ast-to-html value) "

")) + (defn to-italic [value] (string "" (page-ast-to-html value) "")) + (defn to-bold [value] (string "" (page-ast-to-html value) "")) + (defn to-stroke [value] (string "" (page-ast-to-html value) "")) (string/join (map @@ -129,8 +85,59 @@ (print "]")))) (defn main [bin & args] - (pp-ast (peg/match md-to-ast (read-from-file "raw/~blog/blog.md"))) (write-to-file "test4.html" (string - (read-from-file "partial-template/header.html") - (ast-to-html (peg/match md-to-ast (read-from-file "raw/~blog/blog.md"))) - (read-from-file "partial-template/footer.html")))) + ``` + + + + + + + + + + + + + + Meow + + + + +
+ ``` + (page-ast-to-html (peg/match markdown-page/to-ast (read-from-file "raw/~blog/blog.md"))) + ``` +
+ + + + ```))) diff --git a/partial-template/footer.html b/partial-template/footer.html deleted file mode 100644 index feecd54..0000000 --- a/partial-template/footer.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - \ No newline at end of file diff --git a/partial-template/header.html b/partial-template/header.html deleted file mode 100644 index 662f3ea..0000000 --- a/partial-template/header.html +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - Meow - - - - -
diff --git a/sample.html b/sample.html deleted file mode 100644 index aa238b0..0000000 --- a/sample.html +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - Meow - - - - -
-

Suspendisse quam dolor, sollicitudin nec velit sodales, tempus iaculis elit.

-

Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, - consectetur, adipisci velit...

-
-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus porta erat non maximus - porttitor. Etiam massa felis, - luctus at eros nec, vestibulum sodales dolor. Donec pellentesque, tellus eu pharetra fringilla, arcu - sapien fringilla - nulla, eget gravida arcu mi eu diam. In hac habitasse platea dictumst. Vestibulum neque mauris, faucibus - eget hendrerit - molestie, ultrices sed purus. In porttitor scelerisque euismod. Sed ultrices efficitur interdum. - Maecenas massa urna, - lobortis ac arcu ac, hendrerit ultricies turpis. Nulla in consectetur justo, sit amet elementum lacus. -

-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vitae consequat massa. Aliquam - egestas pellentesque - elementum. Ut efficitur justo eu libero vestibulum dapibus. Etiam vitae turpis nunc. Maecenas sit amet - elementum dolor. - In luctus tellus non rhoncus dictum. Mauris laoreet velit velit, in pellentesque enim auctor a. Nulla at - lacus vel magna - lacinia tincidunt. Ut aliquet suscipit tincidunt. - - Nulla arcu tortor, aliquet quis congue in, vestibulum vitae arcu. Duis nisi ex, tincidunt quis - condimentum in, - sollicitudin quis nisi. In fringilla ultricies venenatis. Aliquam a quam eros. Curabitur eget tincidunt - orci. Quisque - hendrerit porta augue, eget venenatis diam pellentesque sed. Sed pellentesque vitae urna blandit - lobortis. Sed tellus - nulla, rutrum rhoncus ante at, lacinia efficitur augue. Pellentesque habitant morbi tristique senectus - et netus et - malesuada fames ac turpis egestas. Nam eget dolor ut augue commodo lacinia et at dolor. Sed ut vehicula - lacus. Integer - semper vehicula dignissim. -

-

Donec vitae nisl in sem viverra cursus.

-

Suspendisse dictum urna nunc, non laoreet tortor vulputate eget. Praesent sit amet risus a - lacus eleifend bibendum. - Vivamus et placerat tellus, ut tristique nibh. Maecenas porttitor ex ac turpis interdum iaculis. Etiam - egestas erat non - metus vehicula, viverra vulputate est condimentum. Interdum et malesuada fames ac ante ipsum primis in - faucibus. Nam - vehicula diam sed pharetra malesuada. Etiam non libero et risus viverra volutpat. Donec in justo tortor. - Mauris gravida - finibus sem eget lacinia. Praesent lacinia posuere lacus eget dignissim. Morbi tempus mauris id ante - aliquet finibus. - Quisque ut dignissim neque, ut accumsan urna. Morbi interdum erat eu erat tempus finibus. -

-
-
- - - \ No newline at end of file diff --git a/sample.php b/sample.php deleted file mode 100644 index 6c6b9dd..0000000 --- a/sample.php +++ /dev/null @@ -1,28 +0,0 @@ - "yolo"; -$🎈 = "balooooon"; -$u_a = 2; - diff --git a/test4.html b/test4.html new file mode 100644 index 0000000..0b3aa70 --- /dev/null +++ b/test4.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + Meow + + + + +
+

JDOSHDS

dkjsdjksla

DJIS

dsdds

dsds

dskldks dksl dskjds od dlakdl;as dd djklas ds ds ds

dsds HEHJKS
<?php
+
+// Yolo
+
+/* yo yo yo */
+
+/*
+HY
+    dsidh */
+
+class Hey {
+
+}
+
+const HELLO = "test";
+
+$u = 25;
+
+function abc(int $u = 2, App\Test $test): void 
+{
+    $u*7;
+    return;
+}
+
+ = fn () => "yolo";
+$🎈 = "balooooon";
+$u_a = 2;
+
+ + + + \ No newline at end of file