Skip to content

Commit 1d3bfc0

Browse files
committed
wip
1 parent e94a305 commit 1d3bfc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+10361
-9165
lines changed

backend/src/BuiltinDarkInternal/Libs/DBs.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ let fns : List<BuiltInFn> =
3333
{ name = fn "darkInternalCanvasDBUnlocked" 0
3434
typeParams = []
3535
parameters = [ Param.make "canvasID" TUuid "" ]
36-
returnType = TList TInt64
36+
returnType = TList TUInt64
3737
description = "Get a list of unlocked DBs"
3838
fn =
3939
(function
4040
| _, _, [ DUuid canvasID ] ->
4141
uply {
4242
let! unlocked = UserDB.unlocked canvasID
43-
return unlocked |> List.map int64 |> List.map DInt64 |> Dval.list KTInt64
43+
return unlocked |> List.map DUInt64 |> Dval.list KTUInt64
4444
}
4545
| _ -> incorrectArgs ())
4646
sqlSpec = NotQueryable

backend/src/BuiltinExecution/Libs/Parser.fs

+33-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module BuiltinExecution.Libs.Parser
33
open FSharp.Control.Tasks
44
open System.Threading.Tasks
55
open System.Text
6+
open System.Globalization
7+
open System
68

79
open Prelude
810
open LibExecution.RuntimeTypes
@@ -33,7 +35,21 @@ let fns : List<BuiltInFn> =
3335
let byteIndexToCharIndex (byteIndex : int) (text : string) : int =
3436
let bytes = Encoding.UTF8.GetBytes(text)
3537
let subText = Encoding.UTF8.GetString(bytes, 0, byteIndex)
36-
subText.Length
38+
StringInfo.ParseCombiningCharacters(subText).Length
39+
40+
let getUnicodeAwareSubstring
41+
(line : string)
42+
(startIndex : int)
43+
(endIndex : int)
44+
=
45+
let textElements = StringInfo.GetTextElementEnumerator(line)
46+
let mutable result = ""
47+
let mutable currentIndex = 0
48+
while textElements.MoveNext() do
49+
if currentIndex >= startIndex && currentIndex < endIndex then
50+
result <- result + (textElements.GetTextElement())
51+
currentIndex <- currentIndex + 1
52+
result
3753

3854
let rec mapNodeAtCursor (cursor : TreeCursor) : Dval =
3955
let mutable children = []
@@ -48,8 +64,9 @@ let fns : List<BuiltInFn> =
4864

4965
let fields =
5066
let mapPoint (point : Point) =
67+
let pointRow = point.row + 1
5168
let fields =
52-
[ "row", DInt64 point.row; "column", DInt64 point.column ]
69+
[ "row", DInt64 pointRow; "column", DInt64 point.column ]
5370
DRecord(pointTypeName, pointTypeName, [], Map fields)
5471

5572
let startPos = cursor.Current.StartPosition
@@ -59,26 +76,33 @@ let fns : List<BuiltInFn> =
5976
let fields = [ "start", mapPoint startPos; "end_", mapPoint endPos ]
6077
DRecord(rangeTypeName, rangeTypeName, [], Map fields)
6178

62-
let startCharIndex = byteIndexToCharIndex startPos.column sourceCode
63-
let endCharIndex = byteIndexToCharIndex endPos.column sourceCode
64-
6579
let sourceText =
6680
let lines = String.splitOnNewline sourceCode
6781
if lines.Length = 0 then
6882
""
6983
else
84+
let startLine = lines[startPos.row]
85+
let endLine = lines[endPos.row]
86+
let startCharIndex = byteIndexToCharIndex startPos.column startLine
87+
let endCharIndex = byteIndexToCharIndex endPos.column endLine
88+
7089
match startPos.row with
7190
| row when row = endPos.row ->
72-
lines[row][startCharIndex .. (endCharIndex - 1)]
91+
getUnicodeAwareSubstring startLine startCharIndex endCharIndex
7392
| _ ->
74-
let firstLine = lines[startPos.row][startCharIndex..]
93+
let firstLine =
94+
getUnicodeAwareSubstring
95+
startLine
96+
startCharIndex
97+
startLine.Length
7598
let middleLines =
7699
if startPos.row + 1 <= endPos.row - 1 then
77100
lines[startPos.row + 1 .. endPos.row - 1]
101+
|> List.map (fun line ->
102+
getUnicodeAwareSubstring line 0 line.Length)
78103
else
79104
[]
80-
let lastLine = lines[endPos.row][.. (endCharIndex - 1)]
81-
105+
let lastLine = getUnicodeAwareSubstring endLine 0 endCharIndex
82106
String.concat "\n" (firstLine :: middleLines @ [ lastLine ])
83107

84108
let fieldName =

backend/src/LibExecution/PackageIDs.fs

+3
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ module Fn =
383383
let parseSingleTestFromFile =
384384
p [] "parseSingleTestFromFile" "53f3fbc6-25fd-427a-ab0d-ba0559543c99"
385385

386+
let parseTestFile =
387+
p [] "parseTestFile" "95dc8d95-dd38-4df2-aaac-9e78187a17be"
388+
386389
// what we expose to the outside world
387390
let idForName
388391
(owner : string)

backend/src/LibExecution/ProgramTypesToRuntimeTypes.fs

+29-2
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,23 @@ module MatchPattern =
163163

164164

165165
module Expr =
166+
let replaceEscapeSequences (s: string) : string =
167+
s
168+
|> fun s -> s.Replace(@"\t", "\t")
169+
|> fun s -> s.Replace(@"\n", "\n")
170+
|> fun s -> s.Replace(@"\r", "\r")
171+
|> fun s -> s.Replace(@"\b", "\b")
172+
|> fun s -> s.Replace(@"\f", "\f")
173+
|> fun s -> s.Replace(@"\v", "\v")
174+
|> fun s -> s.Replace(@"\""", "\"")
175+
|> fun s -> s.Replace(@"\'", "'")
176+
|> fun s -> s.Replace(@"\\", "\\")
177+
166178
let rec toRT (e : PT.Expr) : RT.Expr =
167179
match e with
168-
| PT.EChar(id, char) -> RT.EChar(id, char)
180+
| PT.EChar(id, char) ->
181+
let char = char |> replaceEscapeSequences
182+
RT.EChar(id, char)
169183
| PT.EInt64(id, num) -> RT.EInt64(id, num)
170184
| PT.EUInt64(id, num) -> RT.EUInt64(id, num)
171185
| PT.EInt8(id, num) -> RT.EInt8(id, num)
@@ -350,7 +364,20 @@ module Expr =
350364

351365
and stringSegmentToRT (segment : PT.StringSegment) : RT.StringSegment =
352366
match segment with
353-
| PT.StringText text -> RT.StringText text
367+
| PT.StringText text ->
368+
text
369+
|> fun s ->
370+
System.Text.RegularExpressions.Regex.Replace(s, @"\\x([0-9A-Fa-f]{2})",
371+
fun m ->
372+
let hexValue = System.Convert.ToByte(m.Groups[1].Value, 16)
373+
string (char hexValue))
374+
|> fun s ->
375+
System.Text.RegularExpressions.Regex.Replace(s, @"\\u([0-9A-Fa-f]{4})",
376+
fun m ->
377+
let unicodeValue = System.Convert.ToInt32(m.Groups[1].Value, 16)
378+
string (char unicodeValue))
379+
|> replaceEscapeSequences
380+
|> RT.StringText
354381
| PT.StringInterpolation expr -> RT.StringInterpolation(toRT expr)
355382

356383

backend/src/Prelude/Prelude.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ let readFloat (f : float) : (Sign * string * string) =
290290
let makeFloat (sign : Sign) (whole : string) (fraction : string) : float =
291291
try
292292
if whole <> "" then assert_ "non-zero string" [] (whole[0] <> '-')
293-
if whole <> "0" then assertRe $"makefloat" "[1-9][0-9]*" whole
293+
if whole <> "0" then assertRe $"makefloat" "0*[0-9]+" whole
294294
let sign =
295295
match sign with
296296
| Positive -> ""

backend/testfiles/execution/cloud/_events.dark

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
type FruitRecord = { fruits: List<String> }
55

66
// getQueue works
7-
Builtin.testGetQueue_v0 "TestWorker" = []
7+
Builtin.testGetQueue "TestWorker" = []
88

99
// emit works
1010
(let _ = Builtin.emit "value" "TestWorker"
11-
let queue = Builtin.testGetQueue_v0 "TestWorker"
11+
let queue = Builtin.testGetQueue "TestWorker"
1212
queue) = [ "\"value\"" ]
1313

1414
// emit works with mixed values
1515
(let _ = Builtin.emit "value" "TestWorker"
1616
let _ = Builtin.emit 1 "TestWorker"
1717
let _ = Builtin.emit (FruitRecord { fruits = [ "apple"; "banana" ] }) "TestWorker"
18-
let queue = Builtin.testGetQueue_v0 "TestWorker"
19-
Stdlib.List.sort queue) = [ "\"value\""
20-
"1"
21-
"FruitRecord {\n fruits: [\n \"apple\", \"banana\"\n ]\n}" ]
18+
let queue = Builtin.testGetQueue "TestWorker"
19+
Stdlib.List.sort queue) = [ "\"value\""
20+
"1"
21+
"FruitRecord {\n fruits: [\n \"apple\", \"banana\"\n ]\n}" ]

0 commit comments

Comments
 (0)