From 844bb0f1890f25a2354af7d611e41b81e9ddae15 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sun, 11 Oct 2020 22:31:36 -0400 Subject: [PATCH] Working language mod, though it doesn't have access to anything defined in the outer --- new_kraken.kp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/new_kraken.kp b/new_kraken.kp index f818937..5fea893 100644 --- a/new_kraken.kp +++ b/new_kraken.kp @@ -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) ) )