Working language mod, though it doesn't have access to anything defined in the outer

This commit is contained in:
Nathan Braswell
2020-10-11 22:31:36 -04:00
parent 42c2fcfb66
commit 844bb0f189

View File

@@ -68,6 +68,12 @@
true
(concat (array (vapply recurse (array (idx x 0)) de)) (vapply recurse (array (slice x 1 -1)) de))))
true x))))
tiny_grammar (array
(array (quote WS) (array "( | |
|(;[ -~]*
))+") (lambda (x) nil))
(array (quote start_symbol) (array (quote WS) * "only_str" (quote WS) *) (lambda (_ _ _) 1337))
)
standard_grammar (array
(array (quote WS) (array "( | |
|(;[ -~]*
@@ -82,8 +88,10 @@
(array (quote form) (array (quote atom)) (lambda (x) x))
(array (quote form) (array "\\(" (quote WS) * "\\)" ) (lambda (_ _ _) (array)))
(array (quote form) (array "\\(" (quote WS) * (quote form) (array (quote WS) + (quote form)) * (quote WS) * "\\)" ) (lambda (_ _ head tail _ _) (concat (array head) (map (lambda (x) (idx x 1)) tail))))
(array (quote start_symbol) (array (quote WS) * (quote form) (quote WS) *) (lambda (_ f _) f))
(array (quote start_symbol) (array (quote WS) * "#lang" (quote WS) * (quote form) "[ -~]*") (lambda (_ _ _ gram source) (read-string source (eval gram) (quote start_symbol))))
)
rep (vY (lambda (recurse) (wrap (vau de () (do (println (eval (read-string (get_line "> ") standard_grammar (quote form)) de))
rep (vY (lambda (recurse) (wrap (vau de () (do (println (eval (read-string (get_line "> ") standard_grammar (quote start_symbol)) de))
(eval (array recurse) de))))))
print_through (lambda (x) (do (println x) x))
provide (vau de (& items) (array let
@@ -119,8 +127,8 @@
(do
(println "Welcome to Kraken! Parameters were" *ARGV*)
(cond (and (>= (len *ARGV*) 3) (= "-C" (idx *ARGV* 1))) (eval (concat scope_let (array (read-string (idx *ARGV* 2) standard_grammar (quote form)))) root_env)
(> (len *ARGV*) 1) (eval (concat scope_let (array (read-string (slurp (idx *ARGV* 1)) standard_grammar (quote form)))) root_env)
(cond (and (>= (len *ARGV*) 3) (= "-C" (idx *ARGV* 1))) (eval (concat scope_let (array (read-string (idx *ARGV* 2) standard_grammar (quote start_symbol)))) root_env)
(> (len *ARGV*) 1) (eval (concat scope_let (array (read-string (slurp (idx *ARGV* 1)) standard_grammar (quote start_symbol)))) root_env)
true (eval (concat scope_let (array (array rep))) root_env)
)
)