File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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))
912917evalUnaryOp SizeOf (List _ len) = Right (Integer len)
913918evalUnaryOp SizeOf (Set _ len) = Right (Integer len)
919+ evalUnaryOp SizeOf (Object kvs) = Right (Integer (length kvs))
914920evalUnaryOp _ _ = Left " Type error in unary operation"
915921
916922evalUnion :: BinaryOperation -> Value -> Value -> Either String Value
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments