Skip to content

Commit 8a4cd9e

Browse files
committed
Adding vendor libraries. Starting CSV reading library.
1 parent 3797651 commit 8a4cd9e

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

docs/install/install_bern.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
$ErrorActionPreference = 'Stop'
99

10-
$installDir = "C:\Beraan"
10+
$installDir = "C:\Bern"
1111
$repo = "mirvoxtm/Bern"
1212
$zipName = "Bern_win_1.0.1.zip"
1313
$exeName = "Bern.exe"

lib/vendor/csv.brn

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import core
2+
import strings
3+
4+
def read_csv(file_name) do
5+
content = read_file(file_name)
6+
lines = split(content, "\n")
7+
obj = #{}#
8+
idx = 0
9+
for line in lines do
10+
fields = split(line, ",")
11+
obj["" + idx] = fields
12+
idx = idx + 1
13+
end
14+
return transform_csv(obj)
15+
end
16+
17+
def transform_csv(raw_data) do
18+
headers = raw_data["0"]
19+
result = #{}#
20+
idx = 1
21+
22+
for idx < (:> raw_data) do
23+
row = raw_data["" + idx]
24+
row_obj = #{}#
25+
field_idx = 0
26+
27+
for field_idx < (:> headers) do
28+
row_obj[headers[field_idx]] = row[field_idx]
29+
field_idx = field_idx + 1
30+
end
31+
32+
result["" + (idx - 1)] = row_obj
33+
idx = idx + 1
34+
end
35+
36+
return result
37+
end
38+
39+
-- TODO: write_csv -- #{}# -> file

src/Language/Eval.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ evaluate (Index expr idxExpr) table = do
409409
Just v -> Right v
410410
Nothing -> Left ("Key not found: " ++ key)
411411
Nothing -> Left "Index must be integer or string (in case of objects)"
412+
(Object kvs, Integer i) ->
413+
let key = show i in
414+
case lookup key kvs of
415+
Just v -> Right v
416+
Nothing -> Left ("Key not found: " ++ key)
412417
(Object kvs, Character c) ->
413418
case lookup [c] kvs of
414419
Just v -> Right v
@@ -911,6 +916,7 @@ evalUnaryOp SizeOf v
911916
| Just s <- valueToString v = Right (Integer (length s))
912917
evalUnaryOp SizeOf (List _ len) = Right (Integer len)
913918
evalUnaryOp SizeOf (Set _ len) = Right (Integer len)
919+
evalUnaryOp SizeOf (Object kvs) = Right (Integer (length kvs))
914920
evalUnaryOp _ _ = Left "Type error in unary operation"
915921

916922
evalUnion :: BinaryOperation -> Value -> Value -> Either String Value

src/Parsing/Parser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ parseForIn = do
557557
_ <- symbol "for"
558558
varName <- lexeme $ some letterChar
559559
idxVar <- optional (symbol "," >> lexeme (some letterChar))
560-
_ <- symbol ":"
560+
_ <- symbol ":" <|> symbol "in"
561561
collection <- parseExpression
562562
_ <- symbol "do"
563563
body <- parseBlockCommands

0 commit comments

Comments
 (0)