aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-12-04 19:13:53 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-05 14:21:53 +0200
commiteb2e1e80b11825102c6fb80e04b0a0fffd4e63fb (patch)
treeed685b7cdf72320d0758904846df1a5747393853
parent77117fa515c5853b5f756d899db0ec9b502298e7 (diff)
Fix line numbers in script file tokens
-rw-r--r--.gitignore4
-rw-r--r--examples/types-concept.lisp34
-rw-r--r--src/Interpreter.hs2
-rw-r--r--src/Tokenizer.hs12
-rw-r--r--stdlib/common.lisp2
5 files changed, 45 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index c368d45..7dfc212 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
.stack-work/
-*~ \ No newline at end of file
+*~
+
+.DS_Store
diff --git a/examples/types-concept.lisp b/examples/types-concept.lisp
new file mode 100644
index 0000000..8359c6b
--- /dev/null
+++ b/examples/types-concept.lisp
@@ -0,0 +1,34 @@
+; lowercase types: polymorphic
+; everything else: monomorphic
+
+(type compose (\[
+ (\[b] c) ; f
+ (\[a] b)] ; g
+ (\[a] c)))
+(let!
+ compose (\[f g] (\[x] (f (g x)))))
+
+((compose (+ 1) (+ 2)) 3)
+
+(type id (\[a] a))
+(let! id (\[a] a))
+
+(type mod (\[Int Int] Int))
+(let! mod (\[n k]
+ (- n (* k (/ n k)))))
+
+(type not (\[Bool] Bool))
+(let! not (\[b]
+ (match b
+ true false
+ false true)))
+
+(type is-even (\[Int] Bool))
+(let! is-even (\[n]
+ (match (mod n 2)
+ 0 true
+ 1 false)))
+
+; match cannot be type annotated because its variadic
+; but the match above is inferred as this:
+(type match (\[a a b a b] b))
diff --git a/src/Interpreter.hs b/src/Interpreter.hs
index 1f9153c..52b3a33 100644
--- a/src/Interpreter.hs
+++ b/src/Interpreter.hs
@@ -320,7 +320,7 @@ runScriptFile fileName = do
runInlineScript :: String -> String -> LContext [AST]
runInlineScript fileName src =
- runInlineScript' 0 fileName src
+ runInlineScript' 1 fileName src
runInlineScript' :: LineNo -> String -> String -> LContext [AST]
runInlineScript' lineNo fileName src = do
diff --git a/src/Tokenizer.hs b/src/Tokenizer.hs
index 777bedb..b38e568 100644
--- a/src/Tokenizer.hs
+++ b/src/Tokenizer.hs
@@ -97,10 +97,10 @@ tokenize' (row, col) fileName src = do
.> filter (\t -> length (tokenContent t) > 0)
where
- augment row col ('\r':'\n':rest) =
- TChar '\n' row col : augment (row + 1) 1 rest
- augment row col ('\n':rest) =
- TChar '\n' row col : augment (row + 1) 1 rest
- augment row col (c:rest) =
- TChar c row col : augment row (col + 1) rest
+ augment row' col' ('\r':'\n':rest) =
+ TChar '\n' row' col' : augment (row' + 1) 1 rest
+ augment row' col' ('\n':rest) =
+ TChar '\n' row' col' : augment (row' + 1) 1 rest
+ augment row' col' (c:rest) =
+ TChar c row' col' : augment row' (col' + 1) rest
augment _ _ [] = []
diff --git a/stdlib/common.lisp b/stdlib/common.lisp
index 2db5d62..efb1183 100644
--- a/stdlib/common.lisp
+++ b/stdlib/common.lisp
@@ -26,7 +26,7 @@
otherwise
(prepend (f (head lst)) (map f (tail lst))))))
-(map (+ 1) [1 2 3])
+; (map (+ 1) [1 2 3])
;; foldr :: (a -> b -> b) -> b -> [a] -> b
(let! foldr (\[f accumulator lst]