Skip to content

Commit

Permalink
chore: slight cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
x86y committed Oct 16, 2023
1 parent 159bada commit 42ed77d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 84 deletions.
6 changes: 6 additions & 0 deletions Beacon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
F379CEC72ADDB24D00164F76 /* LexBQN.swift in Sources */ = {isa = PBXBuildFile; fileRef = F379CEC52ADDB24D00164F76 /* LexBQN.swift */; };
F379CEC92ADDD2A700164F76 /* Tokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F379CEC82ADDD2A700164F76 /* Tokenizer.swift */; };
F379CECA2ADDD2A700164F76 /* Tokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F379CEC82ADDD2A700164F76 /* Tokenizer.swift */; };
F379CECC2ADDD42C00164F76 /* HistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F379CECB2ADDD42C00164F76 /* HistoryView.swift */; };
F379CECD2ADDD42C00164F76 /* HistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F379CECB2ADDD42C00164F76 /* HistoryView.swift */; };
F3877C8E29952A6600E2FCB5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F3877C8D29952A6600E2FCB5 /* Assets.xcassets */; };
F38F03A92A323F8500F66354 /* libksim.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F38F03A82A323F8500F66354 /* libksim.a */; };
F3AC4D262A4F6C3100B4FECD /* curl.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3AC4D252A4F6C3000B4FECD /* curl.xcframework */; };
Expand Down Expand Up @@ -113,6 +115,7 @@
F379CEC22ADD94BC00164F76 /* LexK.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LexK.swift; sourceTree = "<group>"; };
F379CEC52ADDB24D00164F76 /* LexBQN.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LexBQN.swift; sourceTree = "<group>"; };
F379CEC82ADDD2A700164F76 /* Tokenizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tokenizer.swift; sourceTree = "<group>"; };
F379CECB2ADDD42C00164F76 /* HistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryView.swift; sourceTree = "<group>"; };
F3877C8B29952A5400E2FCB5 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
F3877C8D29952A6600E2FCB5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
F38F03A82A323F8500F66354 /* libksim.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libksim.a; path = Beacon/libs/libksim.a; sourceTree = "<group>"; };
Expand Down Expand Up @@ -221,6 +224,7 @@
F30A7B892A370B7800503966 /* BuffersView.swift */,
F3E1DFF32A31F9D800B4A553 /* ConfigView.swift */,
F3DF82892A4EF33A00F6CD19 /* DashboardView.swift */,
F379CECB2ADDD42C00164F76 /* HistoryView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -459,6 +463,7 @@
F32D9E8429966FCD007BC97C /* Beacon-Bridging-Header.h in Sources */,
F379CEC72ADDB24D00164F76 /* LexBQN.swift in Sources */,
F379CEC42ADD94BC00164F76 /* LexK.swift in Sources */,
F379CECD2ADDD42C00164F76 /* HistoryView.swift in Sources */,
F30A7B8B2A370B7800503966 /* BuffersView.swift in Sources */,
F31BCE7F2A348B7500A6116D /* HelpView.swift in Sources */,
F32D9E8529966FCD007BC97C /* ArraygroundApp.swift in Sources */,
Expand All @@ -479,6 +484,7 @@
F312CF8829951C89008EC197 /* Beacon-Bridging-Header.h in Sources */,
F379CEC62ADDB24D00164F76 /* LexBQN.swift in Sources */,
F379CEC32ADD94BC00164F76 /* LexK.swift in Sources */,
F379CECC2ADDD42C00164F76 /* HistoryView.swift in Sources */,
F30A7B8A2A370B7800503966 /* BuffersView.swift in Sources */,
F31BCE7E2A348B7500A6116D /* HelpView.swift in Sources */,
F3B198CE299517DA00FE664F /* ArraygroundApp.swift in Sources */,
Expand Down
Binary file modified Beacon/Assets.xcassets/AppIcon.appiconset/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Beacon/Utilities/LexK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func parseK(_ str: String) -> [String] {
continue
} else if (c == " " && n == "/") || ((p == "\n" || p == "\0") && c == "/") {
res[i] = comC
while str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)] != "\n" {
while i < str.count, str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)] != "\n" {
i += 1
}
} else if fns.contains(c) || c.unicodeScalars.first!.value >= 0x80 {
Expand Down
8 changes: 4 additions & 4 deletions Beacon/Utilities/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ struct Token: Identifiable {
let type: TokenType
}

func tokenize(_ str: String, _ parseKOutput: [String]) -> [[Token]] {
func tokenize(_ str: String, _ lexed: [String]) -> [[Token]] {
var tokens: [Token] = []
var i = 0

while i < parseKOutput.count {
if let type = TokenType(rawValue: parseKOutput[i]) {
while i < lexed.count {
if let type = TokenType(rawValue: lexed[i]) {
var j = i + 1
while j < parseKOutput.count && parseKOutput[j] == "" {
while j < lexed.count && lexed[j] == "" {
j += 1
}
let value = str[str.index(str.startIndex, offsetBy: i) ..< str.index(str.startIndex, offsetBy: j)]
Expand Down
79 changes: 0 additions & 79 deletions Beacon/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,6 @@ import MobileCoreServices
import SwiftUI
import UIKit

struct HistoryView: View {
var index: Int
var historyItem: Entry
var curBuffer: String
var onMySubmit: (String) -> Void
@Binding var input: String
@Binding var ephemerals: [Int: [String]]
@Binding var editType: Behavior
@ObservedObject var viewModel: HistoryModel

var body: some View {
VStack(alignment: .leading) {
if editType == Behavior.inlineEdit {
TextField("Source", text: Binding(
get: {
if index < viewModel.history[curBuffer, default: []].count {
return self.viewModel.history[curBuffer, default: []][index].src
} else {
return ""
}
},
set: {
if index < viewModel.history[curBuffer, default: []].count {
self.viewModel.history[curBuffer, default: []][index].src = $0
ephemerals[index, default: []].append($0)
}
}
))
.onSubmit {
onMySubmit(self.viewModel.history[curBuffer, default: []][index].src)
for k in ephemerals.keys {
self.viewModel.history[curBuffer, default: []][k].src = ephemerals[k, default: []].first!
}
ephemerals = [:] // reset all virtual textfield edits
}
.font(Font.custom("BQN386 Unicode", size: 18))
.foregroundColor(.blue)
} else if editType == Behavior.duplicate {
VStack(spacing: 1) {
let tokens = historyItem.lang == .k
? tokenize(historyItem.src, parseK(historyItem.src))
: tokenize(historyItem.src, parseBQN(code: historyItem.src))
ForEach(Array(tokens.enumerated()), id: \.offset) { _, line in
HStack(spacing: 0) {
ForEach(line, id: \.id) { token in
Text(token.value)
.foregroundColor(tokenToColor(token.type))
.font(Font.custom("BQN386 Unicode", size: 18))
.onTapGesture {
self.input = historyItem.src
}
}
}.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
Text("\(trimLongText(historyItem.out))")
.font(Font.custom("BQN386 Unicode", size: 18))
.foregroundColor(historyItem.out.starts(with: "Error:") || historyItem.out.starts(with: "\"Error:") ? .red : .primary)
.multilineTextAlignment(.leading)
.onTapGesture {
self.input = historyItem.out
}
}.frame(maxWidth: .infinity, alignment: .leading)
}
}

struct ContentView: View {
@State var input: String = ""
@State var ephemerals: [Int: [String]] = [:]
Expand Down Expand Up @@ -204,17 +137,5 @@ struct ContentView: View {
viewModel.load(Buffers.get())
kinit()
repl_init()
/* for filename in modules {
print(e(input: "•Import \"\(Bundle.main.resourcePath!)/bqn-libs/\(filename)\""))
} */
// isFocused = true
}
}

/*
struct ContentView_Preview: PreviewProvider {
static var previews: some View {
ContentView()
}
}
*/
74 changes: 74 additions & 0 deletions Beacon/Views/HistoryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// HistoryView.swift
// Arrayground
//

import Foundation
import SwiftUI

struct HistoryView: View {
var index: Int
var historyItem: Entry
var curBuffer: String
var onMySubmit: (String) -> Void
@Binding var input: String
@Binding var ephemerals: [Int: [String]]
@Binding var editType: Behavior
@ObservedObject var viewModel: HistoryModel

var body: some View {
VStack(alignment: .leading) {
if editType == Behavior.inlineEdit {
TextField("Source", text: Binding(
get: {
if index < viewModel.history[curBuffer, default: []].count {
return self.viewModel.history[curBuffer, default: []][index].src
} else {
return ""
}
},
set: {
if index < viewModel.history[curBuffer, default: []].count {
self.viewModel.history[curBuffer, default: []][index].src = $0
ephemerals[index, default: []].append($0)
}
}
))
.onSubmit {
onMySubmit(self.viewModel.history[curBuffer, default: []][index].src)
for k in ephemerals.keys {
self.viewModel.history[curBuffer, default: []][k].src = ephemerals[k, default: []].first!
}
ephemerals = [:] // reset all virtual textfield edits
}
.font(Font.custom("BQN386 Unicode", size: 18))
.foregroundColor(.blue)
} else if editType == Behavior.duplicate {
VStack(spacing: 1) {
let tokens = historyItem.lang == .k
? tokenize(historyItem.src, parseK(historyItem.src))
: tokenize(historyItem.src, parseBQN(code: historyItem.src))
ForEach(Array(tokens.enumerated()), id: \.offset) { _, line in
HStack(spacing: 0) {
ForEach(line, id: \.id) { token in
Text(token.value)
.foregroundColor(tokenToColor(token.type))
.font(Font.custom("BQN386 Unicode", size: 18))
.onTapGesture {
self.input = historyItem.src
}
}
}.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
Text("\(trimLongText(historyItem.out))")
.font(Font.custom("BQN386 Unicode", size: 18))
.foregroundColor(historyItem.out.starts(with: "Error:") || historyItem.out.starts(with: "\"Error:") ? .red : .primary)
.multilineTextAlignment(.leading)
.onTapGesture {
self.input = historyItem.out
}
}.frame(maxWidth: .infinity, alignment: .leading)
}
}

0 comments on commit 42ed77d

Please sign in to comment.