Fix error swallowing grammer errors for custom grammers on read-string, start constructing standard_grammar
This commit is contained in:
13
fungll.krak
13
fungll.krak
@@ -108,6 +108,19 @@ obj Grammer<T,K> (Object) {
|
||||
return terminals[erminal-1].regexString
|
||||
}
|
||||
}
|
||||
fun to_string(): str {
|
||||
var to_ret = str()
|
||||
for (var i = 0; i < nonterminals.size; i++;) {
|
||||
for (var j = 0; j < nonterminals[i].size; j++;) {
|
||||
to_ret += nonterminal_names[i] + " ::="
|
||||
for (var k = 0; k < nonterminals[i][j].size; k++;) {
|
||||
to_ret += " " + to_string(nonterminals[i][j][k])
|
||||
}
|
||||
to_ret += "\n"
|
||||
}
|
||||
}
|
||||
return "start_symbol: " + to_string(start_symbol) + "\n" + to_ret
|
||||
}
|
||||
fun eval_BSR(input: ref str, BSR: ref set<BS>): T {
|
||||
var top = -1
|
||||
for (var i = 0; i < BSR.data.size; i++;) {
|
||||
|
||||
11
k_prime.krak
11
k_prime.krak
@@ -454,6 +454,11 @@ fun read_str(grammar: ref Grammer<KPResult,KPValue>, s: str): pair<int, KPResult
|
||||
}
|
||||
}
|
||||
if longest >= 0 {
|
||||
println("trying to parse: " + s)
|
||||
println(str("length of BSR is: ") + BSR.size())
|
||||
for (var i = 0; i < BSR.data.size; i++;) {
|
||||
println(str() + i + ": " + grammar.to_string(BSR.data[i]))
|
||||
}
|
||||
return make_pair(longest, grammar.eval_BSR(s.slice(0, longest), BSR))
|
||||
} else {
|
||||
println("trying to parse: " + s)
|
||||
@@ -1239,7 +1244,7 @@ fun main(argc: int, argv: **char): int {
|
||||
return make_pair(null<KPEnv>(), KPResult::Err(kpString(str("read-string with second param not containing a sub array : ") + i + " index 1 not array")))
|
||||
}
|
||||
var rule = inner_arr[1].get_array_rc().get()
|
||||
add_grammer_rule_helper(grammar, nonterminal_str, rule, inner_arr[2], fun(f: ref KPValue, x: ref vec<KPResult>): KPResult {
|
||||
var result = add_grammer_rule_helper(grammar, nonterminal_str, rule, inner_arr[2], fun(f: ref KPValue, x: ref vec<KPResult>): KPResult {
|
||||
var params = vec<KPValue>()
|
||||
for (var j = 0; j < x.size; j++;) {
|
||||
if is_err(x[j]) {
|
||||
@@ -1253,6 +1258,9 @@ fun main(argc: int, argv: **char): int {
|
||||
}
|
||||
return function_call(get_value(unwrapped_f), params, kpEnv(null<KPEnv>()))
|
||||
})
|
||||
if is_err(result) {
|
||||
return make_pair(null<KPEnv>(), result)
|
||||
}
|
||||
}
|
||||
|
||||
if !params[2].is_symbol() {
|
||||
@@ -1264,6 +1272,7 @@ fun main(argc: int, argv: **char): int {
|
||||
}
|
||||
grammar.set_start_symbol((-1*start_symbol_idx)-1)
|
||||
println("Doing actual reading with new grammer of " + params[0].get_string())
|
||||
println("With grammer:\n" + grammar.to_string())
|
||||
return make_pair(null<KPEnv>(), READ(grammar, params[0].get_string()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
(let (
|
||||
rec-lambda (vau se (p b) (eval (array Y (array lambda (quote (recurse)) (array lambda p b))) se))
|
||||
rep (vY (lambda (recurse) (wrap (vau de () (do (println (eval (read-string (get_line "> ")) de))
|
||||
(eval (array recurse) de))))))
|
||||
|
||||
if (vau de (con than & else) (cond (eval con de) (eval than de)
|
||||
(> (len else) 0) (eval (idx else 0) de)
|
||||
@@ -70,8 +68,25 @@
|
||||
true
|
||||
(concat (array (vapply recurse (array (idx x 0)) de)) (vapply recurse (array (slice x 1 -1)) de))))
|
||||
true x))))
|
||||
standard_grammar (array
|
||||
(array (quote WS) (array "( | |
|
||||
|(;[ -~]*
|
||||
))+") (lambda (x) nil))
|
||||
(array (quote atom) (array "-?[0-9]+") (lambda (x) (read-string x)))
|
||||
; String here
|
||||
(array (quote atom) (array "-|(([a-z]|[A-Z]|_|\\*|/|\\?|\\+|!|=|&|<|>|%)([a-z]|[A-Z]|_|[0-9]|\\*|\\?|\\+|-|!|=|&|<|>|%)*)") (lambda (x) (cond (= "true" x) true
|
||||
(= "false" x) false
|
||||
(= "nil" x) nil
|
||||
true (read-string x))))
|
||||
(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))))
|
||||
)
|
||||
rep (vY (lambda (recurse) (wrap (vau de () (do (println (eval (read-string (get_line "> ") standard_grammar (quote form)) de))
|
||||
(eval (array recurse) de))))))
|
||||
print_through (lambda (x) (do (println x) x))
|
||||
provide (vau de (& items) (array let
|
||||
(flat_map (lambda (item) (array item (eval item de))) items)))
|
||||
(flat_map (lambda (item) (array item (array quote (eval item de)))) items)))
|
||||
scope_let_sans_import (provide
|
||||
root_env
|
||||
lambda
|
||||
@@ -89,6 +104,7 @@
|
||||
vY
|
||||
quote
|
||||
quasiquote
|
||||
standard_grammar
|
||||
provide
|
||||
)
|
||||
insert_into_scope_let (lambda (scope_let name item) (array (idx scope_let 0) (concat (idx scope_let 1) (array name item))))
|
||||
@@ -102,8 +118,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)))) root_env)
|
||||
(> (len *ARGV*) 1) (eval (concat scope_let (array (read-string (slurp (idx *ARGV* 1))))) root_env)
|
||||
(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)
|
||||
true (eval (concat scope_let (array (array rep))) root_env)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user