Skip to content

Commit

Permalink
Misc fixes for top-repos
Browse files Browse the repository at this point in the history
* Better specify availability condition arguments (int.int.int is now
legal, other literals are not) (Fixes #17)
* Allow protocol composition types anywhere we allow implicitly
unwrapped types (Fixes #18)
* Allow subscripts to have more than one argument (Fixes #22)
* Add support for property wrapper projections (Fixes #23)
* Let protocol property requirements specify mutation modifiers
(Fixes #24)
* Support annotations on parameters (Fixes #26)
  • Loading branch information
alex-pinkus committed Oct 16, 2021
1 parent 646e346 commit a885807
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 56 deletions.
79 changes: 72 additions & 7 deletions corpus/classes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class GenericSubscript {
(parameter (simple_identifier) (user_type (type_identifier)))
(optional_type (user_type (type_identifier)))
(computed_getter
(getter_specifier)
(statements
(control_transfer_statement
(call_expression (simple_identifier)
Expand All @@ -173,6 +174,7 @@ class GenericSubscript {
(simple_identifier)
(navigation_suffix (simple_identifier))))))))))
(computed_setter
(setter_specifier)
(statements
(assignment
(directly_assignable_expression
Expand All @@ -195,6 +197,44 @@ class GenericSubscript {
(parameter (simple_identifier) (user_type (type_identifier) (type_arguments (user_type (type_identifier)))))
(user_type (type_identifier) (type_arguments (user_type (type_identifier))))
(statements (control_transfer_statement (simple_identifier)))))))
===
Subscript with multiple arguments
===

public subscript<D>(_ value: D, arg2: Arg2) -> D where D: Decodable {
return value
}

---

(source_file
(subscript_declaration
(modifiers
(visibility_modifier))
(type_parameters
(type_parameter
(type_identifier)))
(external_parameter_name)
(parameter
(simple_identifier)
(user_type
(type_identifier)))
(parameter
(simple_identifier)
(user_type
(type_identifier)))
(user_type
(type_identifier))
(type_constraints
(type_constraint
(inheritance_constraint
(identifier
(simple_identifier))
(user_type
(type_identifier)))))
(statements
(control_transfer_statement
(simple_identifier)))))

==================
Inheritance
Expand Down Expand Up @@ -277,14 +317,14 @@ class SomethingElse: ThingProvider {
(type_annotation
(user_type (type_identifier)))
(computed_property
(computed_getter (statements (simple_identifier)))
(computed_setter (simple_identifier))))
(computed_getter (getter_specifier) (statements (simple_identifier)))
(computed_setter (setter_specifier) (simple_identifier))))
(property_declaration
(value_binding_pattern (non_binding_pattern (simple_identifier)))
(type_annotation (user_type (type_identifier)))
(computed_property
(computed_getter (statements (simple_identifier)))
(computed_setter (statements (assignment (directly_assignable_expression (simple_identifier)) (simple_identifier))))))))
(computed_getter (getter_specifier) (statements (simple_identifier)))
(computed_setter (setter_specifier) (statements (assignment (directly_assignable_expression (simple_identifier)) (simple_identifier))))))))
(class_declaration
(type_identifier)
(inheritance_specifier (user_type (type_identifier)))
Expand All @@ -300,6 +340,31 @@ class SomethingElse: ThingProvider {
(statements (call_expression (simple_identifier) (call_suffix (value_arguments)))))
(control_transfer_statement (simple_identifier)))))
(function_declaration (simple_identifier) (function_body)))))
===
Protocol composition types
===

var propertyMap: NodePropertyMap & KeypathSearchable {
return transformProperties
}

---

(source_file
(property_declaration
(value_binding_pattern
(non_binding_pattern
(simple_identifier)))
(type_annotation
(user_type
(type_identifier))
(user_type
(type_identifier)))
(computed_property
(statements
(control_transfer_statement
(simple_identifier))))))

==================
Structs
==================
Expand All @@ -323,7 +388,7 @@ struct Adder {
(type_annotation
(user_type (type_identifier))))
(function_declaration
(modifiers (function_modifier))
(modifiers (mutation_modifier))
(simple_identifier)
(function_body
(statements
Expand All @@ -342,7 +407,7 @@ protocol Fallible {
}

public protocol FooProvider {
var foo: String { get }
var foo: String { nonmutating get }
}

protocol Wrapper {
Expand All @@ -367,7 +432,7 @@ protocol Wrapper {
(protocol_property_declaration
(value_binding_pattern (non_binding_pattern (simple_identifier)))
(type_annotation (user_type (type_identifier)))
(protocol_property_requirements))))
(protocol_property_requirements (getter_specifier (mutation_modifier))))))
(protocol_declaration
(type_identifier)
(protocol_body
Expand Down
22 changes: 22 additions & 0 deletions corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,25 @@ foo.doSomething(a)?
(call_suffix (value_arguments (value_argument (simple_identifier)))))
(navigation_suffix (simple_identifier)))
(call_suffix (value_arguments (value_argument (simple_identifier))))))

===
Property wrapper projections
===

Image.url(url, isLoaded: $done)

---

(source_file
(call_expression
(navigation_expression
(simple_identifier)
(navigation_suffix
(simple_identifier)))
(call_suffix
(value_arguments
(value_argument
(simple_identifier))
(value_argument
(simple_identifier)
(simple_identifier))))))
3 changes: 2 additions & 1 deletion corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main(args: [String]) {}

func maybe_main(args: Maybe<String>) {}

func convert(args: [String: Int]) {}
func convert(@Arg args: [String: Int]) {}

func sum(a: Int, b: Int!) { return a + b }

Expand All @@ -77,6 +77,7 @@ func sum(a: Int, b: Int!) { return a + b }
(function_body))
(function_declaration
(simple_identifier)
(attribute (user_type (type_identifier)))
(parameter
(simple_identifier)
(dictionary_type (user_type (type_identifier)) (user_type (type_identifier))))
Expand Down
6 changes: 3 additions & 3 deletions corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ if #available(iOS 14.0, *) {
doSomething()
}

if #available(iOS 13.0, *) {
if #available(macOS 10.12.0, *) {
return 3
} else {
return 0
Expand All @@ -503,11 +503,11 @@ if #available(iOS 13.0, *) {
(source_file
(if_expression (availability_condition
(identifier (simple_identifier))
(real_literal))
(integer_literal) (integer_literal))
(statements (call_expression (simple_identifier) (call_suffix (value_arguments)))))
(if_expression (availability_condition
(identifier (simple_identifier))
(real_literal))
(integer_literal) (integer_literal) (integer_literal))
(statements (control_transfer_statement (integer_literal)))
(statements (control_transfer_statement (integer_literal)))))

50 changes: 31 additions & 19 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ module.exports = grammar({
choice(
LEXICAL_IDENTIFIER,
token(seq("`", LEXICAL_IDENTIFIER, "`")),
/\$[0-9]+/
/\$[0-9]+/,
token(seq("$", LEXICAL_IDENTIFIER))
),

identifier: ($) => sep1($.simple_identifier, $._dot_operator),
Expand Down Expand Up @@ -236,9 +237,9 @@ module.exports = grammar({

type_annotation: ($) => seq(":", $._possibly_implicitly_unwrapped_type),

// This is only legal in a few positions
// Superset of legal type declarations, including implicitly unwrapped types and protocol composition types.
_possibly_implicitly_unwrapped_type: ($) =>
seq($._type, optional(token.immediate("!"))),
seq(sep1($._type, "&"), optional(token.immediate("!"))),

_type: ($) =>
prec.right(
Expand Down Expand Up @@ -618,7 +619,7 @@ module.exports = grammar({
seq("(", optional($.lambda_function_type_parameters), ")")
),
optional($.throws_modifier),
optional(seq($._arrow_operator, $._return_type))
optional(seq($._arrow_operator, $._possibly_implicitly_unwrapped_type))
),

lambda_function_type_parameters: ($) => sep1($._lambda_parameter, ","),
Expand Down Expand Up @@ -837,7 +838,8 @@ module.exports = grammar({
")"
),

_availability_argument: ($) => seq($.identifier, $._basic_literal),
_availability_argument: ($) =>
seq($.identifier, sep1($.integer_literal, ".")),

////////////////////////////////
// Declarations - https://docs.swift.org/swift-book/ReferenceManual/Declarations.html
Expand Down Expand Up @@ -891,7 +893,7 @@ module.exports = grammar({
),

protocol_property_requirements: ($) =>
seq("{", repeat(choice("get", "set")), "}"),
seq("{", repeat(choice($.getter_specifier, $.setter_specifier)), "}"),

property_declaration: ($) =>
prec.right(
Expand Down Expand Up @@ -940,16 +942,15 @@ module.exports = grammar({
optional($.type_parameters),
$._function_value_parameters,
optional($.throws_modifier),
optional(seq($._arrow_operator, $._return_type)),
optional(
seq($._arrow_operator, $._possibly_implicitly_unwrapped_type)
),
optional($.type_constraints)
)
),

function_body: ($) => $._block,

// When there's more than one item it's technically a "protocol composition type" but I won't tell if you don't
_return_type: ($) => sep1($._possibly_implicitly_unwrapped_type, "&"),

class_declaration: ($) =>
prec.right(
choice(
Expand Down Expand Up @@ -1010,7 +1011,12 @@ module.exports = grammar({
choice($.inheritance_constraint, $.equality_constraint),

inheritance_constraint: ($) =>
seq(repeat($.attribute), $.identifier, ":", $._type),
seq(
repeat($.attribute),
$.identifier,
":",
$._possibly_implicitly_unwrapped_type
),

equality_constraint: ($) =>
seq(repeat($.attribute), $.identifier, choice("=", "=="), $._type),
Expand All @@ -1022,6 +1028,7 @@ module.exports = grammar({

_function_value_parameter: ($) =>
seq(
optional($.attribute),
optional(alias($.simple_identifier, $.external_parameter_name)),
$.parameter,
optional(seq($._equal_sign, $._expression))
Expand Down Expand Up @@ -1142,10 +1149,10 @@ module.exports = grammar({
optional($.modifiers),
"subscript",
optional($.type_parameters),
"(",
$._function_value_parameter,
")",
optional(seq($._arrow_operator, $._return_type)),
$._function_value_parameters,
optional(
seq($._arrow_operator, $._possibly_implicitly_unwrapped_type)
),
optional($.type_constraints),
"{",
choice(
Expand All @@ -1166,15 +1173,18 @@ module.exports = grammar({
"}"
),

computed_getter: ($) => seq("get", optional($._block)),
computed_getter: ($) => seq($.getter_specifier, optional($._block)),

computed_setter: ($) =>
seq(
"set",
$.setter_specifier,
optional(seq("(", $.simple_identifier, ")")),
optional($._block)
),

getter_specifier: ($) => seq(optional($.mutation_modifier), "get"),
setter_specifier: ($) => seq(optional($.mutation_modifier), "set"),

operator_declaration: ($) =>
seq(
choice("prefix", "infix", "postfix"),
Expand Down Expand Up @@ -1287,6 +1297,7 @@ module.exports = grammar({
$.member_modifier,
$.visibility_modifier,
$.function_modifier,
$.mutation_modifier,
$.property_modifier,
$.inheritance_modifier,
$.parameter_modifier
Expand All @@ -1305,8 +1316,9 @@ module.exports = grammar({

type_parameter_modifiers: ($) => repeat1($.attribute),

function_modifier: ($) =>
choice("infix", "postfix", "prefix", "mutating", "nonmutating"),
function_modifier: ($) => choice("infix", "postfix", "prefix"),

mutation_modifier: ($) => choice("mutating", "nonmutating"),

property_modifier: ($) =>
choice(
Expand Down
26 changes: 0 additions & 26 deletions script-data/known_failures.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
Alamofire/Example/Source/AppDelegate.swift
Alamofire/Tests/SessionManagerTests.swift
Alamofire/Tests/TLSEvaluationTests.swift
lottie-ios/lottie-swift/src/Private/LayerContainers/Utility/LayerTransformNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/ModifierNodes/TrimPathNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/RenderContainers/GroupNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/PathNodes/EllipseNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/PathNodes/PolygonNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/PathNodes/RectNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/PathNodes/ShapeNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/PathNodes/StarNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/Text/TextAnimatorNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/RenderNodes/GradientFillNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/RenderNodes/StrokeNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/RenderNodes/FillNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Nodes/RenderNodes/GradientStrokeNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/RenderLayers/ShapeRenderLayer.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Protocols/RenderNode.swift
lottie-ios/lottie-swift/src/Private/NodeRenderSystem/Protocols/AnimatorNode.swift
lottie-ios/lottie-swift/src/Private/Model/Extensions/KeyedDecodingContainerExtensions.swift
lottie-ios/lottie-swift/src/Private/Utility/Primitives/BezierPath.swift
lottie-ios/lottie-swift/src/Private/Utility/Primitives/CompoundBezierPath.swift
vapor/Tests/VaporTests/ApplicationTests.swift
vapor/Sources/Vapor/Middleware/CORSMiddleware.swift
vapor/Sources/Vapor/Response/Response.swift
vapor/Sources/Vapor/Content/ContentConfig.swift
vapor/Sources/Vapor/Content/ContentContainer.swift
vapor/Sources/Vapor/Content/QueryContainer.swift
vapor/Sources/Vapor/Request/Request.swift
Kingfisher/Demo/Demo/Kingfisher-Demo/SwiftUIViews/ListDemo.swift
Kingfisher/Sources/General/KFOptionsSetter.swift
Kingfisher/Sources/Extensions/UIButton+Kingfisher.swift
Kingfisher/Sources/SwiftUI/ImageBinder.swift
Kingfisher/Sources/SwiftUI/KFImageOptions.swift
shadowsocks/ShadowsocksX-NG/ServerProfile.swift
Carthage/Source/carthage/Outdated.swift
Carthage/Source/carthage/Archive.swift
Expand All @@ -55,8 +31,6 @@ Carthage/Tests/CarthageKitTests/XcodeSpec.swift
Moya/Tests/MoyaTests/TestHelpers.swift
Moya/Sources/Moya/Plugins/NetworkLoggerPlugin.swift
Moya/Sources/Moya/Response.swift
ObjectMapper/Tests/ObjectMapperTests/MappableTypesWithTransformsTests.swift
ObjectMapper/[email protected]
ObjectMapper/Sources/HexColorTransform.swift
ObjectMapper/Sources/Map.swift
ObjectMapper/Sources/ToJSON.swift

0 comments on commit a885807

Please sign in to comment.