Skip to content

Commit

Permalink
Merge pull request #1 from IvanMathy/main
Browse files Browse the repository at this point in the history
Merge from main
  • Loading branch information
mmshivesh authored Nov 21, 2020
2 parents 35d34f3 + 5144567 commit 5a600ba
Show file tree
Hide file tree
Showing 28 changed files with 4,208 additions and 81 deletions.
16 changes: 8 additions & 8 deletions Boop/Boop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = RLZ8XBTX7G;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -758,7 +758,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
OTHER_CODE_SIGN_FLAGS = "--deep";
PRODUCT_BUNDLE_IDENTIFIER = com.OKatBest.Boop;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -775,7 +775,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -789,7 +789,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
OTHER_CODE_SIGN_FLAGS = "--deep";
PRODUCT_BUNDLE_IDENTIFIER = com.okatbest.boop;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -806,7 +806,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 16;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -819,7 +819,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
OTHER_CODE_SIGN_FLAGS = "--deep";
"OTHER_SWIFT_FLAGS[arch=*]" = "-D APPSTORE";
PRODUCT_BUNDLE_IDENTIFIER = com.OKatBest.Boop;
Expand All @@ -837,7 +837,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 16;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -850,7 +850,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
OTHER_CODE_SIGN_FLAGS = "--deep";
"OTHER_SWIFT_FLAGS[arch=*]" = "-D APPSTORE";
PRODUCT_BUNDLE_IDENTIFIER = com.okatbest.boop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/IvanMathy/savannakit",
"state": {
"branch": null,
"revision": "d0950476608b714f435c7026ab8c7f13b87e5e81",
"version": "0.14.2"
"revision": "bb51ee074152a7361e7085d10723f699c79fe673",
"version": "0.15.1"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions Boop/Boop/Assets.xcassets/Icons/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "icons8-elephant.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "icons8-pineapple.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "icons8-translation.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
14 changes: 13 additions & 1 deletion Boop/Boop/Controllers/PopoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PopoverViewController: NSViewController {
var didSomething = false

// Key codes:
let kVKTab = 0x30
// 125 is down arrow
// 126 is up
// 53 is escape
Expand All @@ -72,9 +73,20 @@ class PopoverViewController: NSViewController {

didSomething = true
}

let window = self.view.window

if theEvent.keyCode == kVKTab && self.enabled {
if window?.firstResponder is NSTextView &&
(window?.firstResponder as! NSTextView).delegate is SearchField {
let offset = theEvent.modifierFlags.contains(.shift) ? -1 : 1
let newSel = IndexSet([self.tableView.selectedRow + offset])
self.tableView.selectRowIndexes(newSel, byExtendingSelection: false)
self.tableView.scrollRowToVisible(self.tableView.selectedRow)
}
didSomething = true // prevent tabbing back into text document
}

if window?.firstResponder is NSTextView &&
(window?.firstResponder as! NSTextView).delegate is SearchField &&
theEvent.keyCode == 125 { // DOWN
Expand Down
42 changes: 17 additions & 25 deletions Boop/Boop/Editor/BoopLexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ class BoopLexer: RegexLexer {

func generators(source: String) -> [TokenGenerator] {

let standalonePrefix = "(?<=[\\s]|^|[\\(,:])"
let standaloneSuffix = "(?=[\\s\\?\\!,:\\)\\();]|$)"

let quoteLookahead = "(?=(?:(?:[^\"]*\"){2})*[^\"]*$)"

let quotes = "(\"|@\")(?:[^\"\\\\\\n]|\\\\.)*[^\"\\n]*(@\"|\")"
let number = "\\b(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)\\b"
let number = #"\b(?:0x[a-f0-9]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+\-]?\d+)?)\b"#


var generators = [TokenGenerator?]()
Expand All @@ -36,61 +30,59 @@ class BoopLexer: RegexLexer {

// Find common attributes

generators.append(regexToken(.attribute, "\(standalonePrefix)(\(commonAttributes.joined(separator: "|")))\(standaloneSuffix)", options: .caseInsensitive))
generators.append(regexToken(.attribute, #"\b(\#(commonAttributes.joined(separator: "|")))\b"#, options: .caseInsensitive))

generators.append(regexToken(.keyword, "\(standalonePrefix)(\(moreAttributes.joined(separator: "|")))\(standaloneSuffix)", options: .caseInsensitive))
generators.append(regexToken(.keyword, #"\b(\#(moreAttributes.joined(separator: "|")))\b"#, options: .caseInsensitive))


// Extras

let UTCDate = "(?:(Sun|Mon|Tue|Wed|Thu|Fri|Sat),\\s+)?(0[1-9]|[1-2]?[0-9]|3[01])\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(19[0-9]{2}|[2-9][0-9]{3})\\s+(2[0-3]|[0-1][0-9]):([0-5][0-9])(?::(60|[0-5][0-9]))?\\s+([-\\+][0-9]{2}[0-5][0-9]|(?:UT|GMT|(?:E|C|M|P)(?:ST|DT)|[A-IK-Z]))"

generators.append(regexToken(.number, "\(standalonePrefix)(\(UTCDate))\(standaloneSuffix)"))
generators.append(regexToken(.number, UTCDate))

// - Match MD5 strings
generators.append(regexToken(.keyword, "\(standalonePrefix)([a-f0-9]{32})\(standaloneSuffix)"))
generators.append(regexToken(.keyword, "[a-f0-9]{32}"))

// - Bootleg XML-like tags match:

generators.append(regexToken(.attribute, "(?m)\(quoteLookahead)<(?:.*?)\\b[^>]*\\/?>"))
generators.append(regexToken(.attribute, "<(?:.*?)\\b[^>]*\\/?>"))

// Strings

generators.append(regexToken(.string, quotes, options: [.dotMatchesLineSeparators, .caseInsensitive]))
// - Match JSON labels and generic parameters
generators.append(regexToken(.extra, #""([^"]+?)"\s*(?=:)"#, greedy: true))

generators.append(regexToken(.string, "`(?:[^`\\\\\\n]|\\\\.)*[^`\\n]*`", options: [.dotMatchesLineSeparators, .caseInsensitive]))
// Strings

generators.append(regexToken(.string, "'(?:[^\'\\\\\\n]|\\\\.)*[^\'\\n]*'", options: [.dotMatchesLineSeparators, .caseInsensitive]))
let quotes = #"(["'`])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1"#

generators.append(regexToken(.string, "(\"\"\")(.*?)(\"\"\")", options: [.dotMatchesLineSeparators, .caseInsensitive]))
generators.append(regexToken(.string, quotes, greedy: true))

// More Extras
generators.append(regexToken(.string, "(\"\"\")(.*?)(\"\"\")", options: [.dotMatchesLineSeparators, .caseInsensitive], greedy: true))

// - Match JSON labels and generic parameters
generators.append(regexToken(.extra, "(?m)\(quoteLookahead)(?=(?:[ {\\[]*))([^\\r\\n:\\s\\w]+?|\(quotes))\\s*(?=\\:(?!\\:))"))



// Comments

generators.append(regexToken(.comment, "\(quoteLookahead)//(.*)"))
generators.append(regexToken(.comment, #"(?=(\/\/.*))"#))

generators.append(regexToken(.comment, "\(quoteLookahead)/\\*.*?\\*/", options: [.dotMatchesLineSeparators, .caseInsensitive]))
generators.append(regexToken(.comment, #"(?=(\/\*[\s\S]*?(?:\*\/|$)))"#, options: [.dotMatchesLineSeparators], greedy: true))

generators.append(regexToken(.comment, "\(quoteLookahead)<\\!--[\\s\\S]*?(?:-\\->|$)", options: [.dotMatchesLineSeparators, .caseInsensitive]))
generators.append(regexToken(.comment, #"<!--[\s\S]*?-->"#, options: [.dotMatchesLineSeparators, .caseInsensitive], greedy: true))




return generators.compactMap( { $0 })
}

func regexToken(_ type: BoopToken.TokenType, _ pattern:String, options: NSRegularExpression.Options = .caseInsensitive) -> TokenGenerator? {
func regexToken(_ type: BoopToken.TokenType, _ pattern:String, options: NSRegularExpression.Options = .caseInsensitive, greedy: Bool = false) -> TokenGenerator? {
guard let regex = try? NSRegularExpression(pattern: pattern, options: options) else {
return nil
}
let generator = RegexTokenGenerator(regularExpression: regex, tokenTransformer: { (range) -> Token in
return BoopToken(type: type, range: range)
return BoopToken(type: type, range: range, greedy: greedy)
})
return TokenGenerator.regex(generator)
}
Expand Down
17 changes: 13 additions & 4 deletions Boop/Boop/Editor/BoopToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import Cocoa
import SavannaKit

class BoopToken: Token {
class BoopToken: Token, CustomStringConvertible {

public enum TokenType {


public enum TokenType: String {
case comment
case string
case attribute
Expand All @@ -26,15 +28,22 @@ class BoopToken: Token {
// Plain tokens are not even parsed in the first place.
var isPlain = false

var range: Range<String.Index>
var isActive = true
var isGreedy: Bool

var range: NSRange
var type: BoopToken.TokenType

init(type:TokenType, range: Range<String.Index>) {
init(type:TokenType, range: NSRange, greedy: Bool = false) {
self.range = range
self.type = type
self.isGreedy = greedy
}


var description: String {
return type.rawValue
}


}
6 changes: 3 additions & 3 deletions Boop/Boop/scripts/AndroidIOSStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{
"api":1,
"name":"Android Strings to iOS Localizables",
"description":"Connverts Android Strings to iOS localizables",
"description":"Converts Android Strings to iOS localizables",
"author":"Manuel Kunz (https://github.com/KunzManuel)",
"icon":"quote",
"tags":"string, android, ios"
"icon":"translation",
"tags":"string,android,ios"
}
**/

Expand Down
8 changes: 6 additions & 2 deletions Boop/Boop/scripts/CountCharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
}
**/


const { size } = require('@boop/lodash.boop')

function main(input) {

input.postInfo(`${input.text.length} characters`)
input.postInfo(`${size(input.text)} characters`)

}
}

20 changes: 20 additions & 0 deletions Boop/Boop/scripts/HTMLEncodeAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
{
"api":1,
"name":"HTML Encode all characters",
"description":"HTML Encodes every character in your text",
"author":"Ivan",
"icon":"HTML",
"tags":"html,encode,web,email",
"bias":-0.1
}
**/

function main(input) {
let str = input.text;
var out = "";
for (var i = 0; i < str.length; i++) {
out += `&#${str.charCodeAt(i)};`;
}
input.text = out;
}
4 changes: 2 additions & 2 deletions Boop/Boop/scripts/IOSAndroidStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"name":"iOS Localizables to Android Strings",
"description":"Converts iOS Localizables to Android Strings",
"author":"Manuel Kunz (https://github.com/KunzManuel)",
"icon":"quote",
"tags":"string, android, ios"
"icon":"translation",
"tags":"string,android,ios"
}
**/

Expand Down
21 changes: 21 additions & 0 deletions Boop/Boop/scripts/JSONtoYAML.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
{
"api":1,
"name":"JSON to YAML",
"description":"Converts JSON to YAML.",
"author":"Ivan",
"icon":"metamorphose",
"tags":"markup,convert"
}
**/

const yaml = require('@boop/js-yaml')

function main(input) {
try {
input.text = yaml.safeDump(JSON.parse(input.text))
}
catch(error) {
input.postError("Invalid JSON")
}
}
Loading

0 comments on commit 5a600ba

Please sign in to comment.