Skip to content

Commit

Permalink
Explicit apply and tupled
Browse files Browse the repository at this point in the history
  • Loading branch information
daddykotex committed Dec 19, 2023
1 parent f803a72 commit d8759a4
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 59 deletions.
2 changes: 1 addition & 1 deletion modules/compiler-core/src/internals/recursion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private[compiler] object recursion {
type PatternWithLabel[T] = WithLabel[Pattern[T]]
implicit val patternWithLabelTraverse : Traverse[PatternWithLabel] = Traverse[WithLabel].compose[Pattern]

refoldPar[F, PatternWithLabel, A, B](unfold, fold.tupled)(a)
refoldPar[F, PatternWithLabel, A, B](unfold, (fold.apply _).tupled)(a)
}

}
2 changes: 1 addition & 1 deletion modules/formatter/src/parsers/ControlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ object ControlParser {
}

val control_section: Parser0[ControlSection] =
control_statement.rep0.map(ControlSection)
control_statement.rep0.map(ControlSection(_))

}
2 changes: 1 addition & 1 deletion modules/formatter/src/parsers/MetadataParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object MetadataParser {
}

val metadata_section: Parser0[MetadataSection] =
metadata_statement.rep0.map(MetadataSection)
metadata_statement.rep0.map(MetadataSection(_))
}

/*
Expand Down
31 changes: 15 additions & 16 deletions modules/formatter/src/parsers/NodeParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ object NodeParser {
}

val escaped_char: Parser[EscapedChar] =
escape *> (Parser.charIn(escapeChars).map(CharCase) | unicode_escape)
escape *> (Parser.charIn(escapeChars).map(CharCase(_)) | unicode_escape)
val quoted_char: Parser[QuotedChar] =
qChar.backtrack.map(SimpleCharCase) |
escaped_char.backtrack.map(EscapedCharCase) |
qChar.backtrack.map(SimpleCharCase(_)) |
escaped_char.backtrack.map(EscapedCharCase(_)) |
nl.as(NewLineCase)

val three_dquotes: Parser[Unit] = dquote *> dquote *> dquote
Expand All @@ -66,17 +66,17 @@ object NodeParser {
}
val text_block: Parser[TextBlock] =
((three_dquotes ~ sp0 *> nl) *> text_block_content.rep0 <* three_dquotes)
.map(TextBlock)
.map(TextBlock(_))
val quoted_text: Parser[QuotedText] =
(dquote *> quoted_char.rep0 <* dquote).map(QuotedText)
val node_string_value: Parser[NodeStringValue] = shape_id.backtrack.map(
ShapeIdCase
) | text_block.backtrack.map(TextBlockCase) | quoted_text.backtrack
.map(QuotedTextCase)
(dquote *> quoted_char.rep0 <* dquote).map(QuotedText(_))
val node_string_value: Parser[NodeStringValue] =
shape_id.backtrack.map(ShapeIdCase(_)) |
text_block.backtrack.map(TextBlockCase(_)) |
quoted_text.backtrack.map(QuotedTextCase(_))
val node_keywords: Parser[NodeKeyword] =
Parser.stringIn(Set("true", "false", "null")).map(NodeKeyword)
Parser.stringIn(Set("true", "false", "null")).map(NodeKeyword(_))

val frac: Parser[Frac] = Parser.char('.') *> digit.rep.string.map(Frac)
val frac: Parser[Frac] = Parser.char('.') *> digit.rep.string.map(Frac(_))
val exp: Parser[Exp] =
(Parser.charIn('e', 'E') ~ opParser.? ~ digit.rep.string)
.map { case ((a, b), c) =>
Expand All @@ -92,10 +92,9 @@ object NodeParser {
nodeArray.backtrack | nodeObject.backtrack | number.backtrack | node_keywords.backtrack | node_string_value.backtrack
)

val node_object_key: Parser[NodeObjectKey] = quoted_text.backtrack
.map(
NodeObjectKey.QuotedTextNok
) | identifier.map(NodeObjectKey.IdentifierNok)
val node_object_key: Parser[NodeObjectKey] =
quoted_text.backtrack.map(NodeObjectKey.QuotedTextNok(_)) |
identifier.map(NodeObjectKey.IdentifierNok(_))

lazy val node_object_kvp: Parser[NodeObjectKeyValuePair] =
((node_object_key ~ ws <* colon) ~ ws ~ node_value).map {
Expand All @@ -109,7 +108,7 @@ object NodeParser {
}

val nodeArray: Parser[NodeArray] = {
val valueP = (node_value ~ ws).map(NodeArrayValue.tupled)
val valueP = (node_value ~ ws).map((NodeArrayValue.apply _).tupled)
((openSquare *> ws ~ valueP.backtrack.rep0) <* (ws ~ closeSquare))
.map { case (whitespace, maybeTuple) =>
NodeArray(whitespace, maybeTuple)
Expand Down
12 changes: 6 additions & 6 deletions modules/formatter/src/parsers/ShapeIdParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ import cats.parse.Rfc5234.{alpha, digit}
object ShapeIdParser {
val underscore: Parser[Underscore] = Parser.charIn('_').as(Underscore)
val identifier_chars: Parser[IdentifierChar] =
(Parser.charIn('_') | digit | alpha).map(IdentifierChar)
(Parser.charIn('_') | digit | alpha).map(IdentifierChar(_))
val identifier_start: Parser[IdentifierStart] =
(underscore.rep0.with1 ~ alpha).map(IdentifierStart.tupled)
(underscore.rep0.with1 ~ alpha).map((IdentifierStart.apply _).tupled)
val identifier: Parser[Identifier] =
(identifier_start ~ identifier_chars.rep0).map(Identifier.tupled)
(identifier_start ~ identifier_chars.rep0).map((Identifier.apply _).tupled)
val shape_id_member: Parser[ShapeIdMember] =
(Parser.char('$') *> identifier).map(ShapeIdMember)
(Parser.char('$') *> identifier).map(ShapeIdMember(_))
val namespace: Parser[Namespace] =
(identifier ~ (Parser.charIn('.') *> identifier).rep0)
.map(Namespace.tupled)
.map((Namespace.apply _).tupled)
val absolute_root_shape_id: Parser[AbsoluteRootShapeId] =
((namespace <* Parser.char('#')) ~ identifier)
.map { case (ns, id) => AbsoluteRootShapeId.apply(ns, id) }
Expand All @@ -51,7 +51,7 @@ object ShapeIdParser {
.eitherOr(identifier)
.map(either => RootShapeId(either.swap))
val shape_id: Parser[ShapeId] =
(root_shape_id ~ shape_id_member.backtrack.?).map(ShapeId.tupled)
(root_shape_id ~ shape_id_member.backtrack.?).map((ShapeId.apply _).tupled)
}

/*
Expand Down
36 changes: 16 additions & 20 deletions modules/formatter/src/parsers/ShapeParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object ShapeParser {
val enumTypeNames: Set[String] = Set("enum", "intEnum")

val simple_type_name: Parser[SimpleTypeName] =
Parser.stringIn(simpleNames).map(SimpleTypeName)
Parser.stringIn(simpleNames).map(SimpleTypeName(_))
val enum_type_name: Parser[String] = Parser.stringIn(enumTypeNames)

// see comments on ValueAssignment
Expand Down Expand Up @@ -134,12 +134,10 @@ object ShapeParser {

val explicit_list_member: Parser[ExplicitListMember] =
Parser.string("member") *> sp0 *> Parser.charIn(':') *> sp0 *> shape_id
.map(
ExplicitListMember
)
.map(ExplicitListMember(_))

val elided_list_member: Parser[ElidedListMember] =
shape_id_member.map(ElidedListMember)
shape_id_member.map(ElidedListMember(_))

val list_member: Parser[ListMember] =
(trait_statements.with1.soft ~ (explicit_list_member.backtrack | elided_list_member))
Expand Down Expand Up @@ -173,17 +171,15 @@ object ShapeParser {

object map_parsers {
val elided_map_key: Parser[ElidedMapKey] =
shape_id_member.map(ElidedMapKey)
shape_id_member.map(ElidedMapKey(_))
val explicit_map_key: Parser[ExplicitMapKey] =
Parser.string("key") *> sp0 *> colon *> sp0 *> shape_id.map(
ExplicitMapKey
)
Parser.string("key") *> sp0 *> colon *> sp0 *>
shape_id.map(ExplicitMapKey(_))
val elided_map_value: Parser[ElidedMapValue] =
shape_id_member.map(ElidedMapValue)
shape_id_member.map(ElidedMapValue(_))
val explicit_map_value: Parser[ExplicitMapValue] =
Parser.string("value") *> sp0 *> colon *> sp0 *> shape_id.map(
ExplicitMapValue
)
Parser.string("value") *> sp0 *> colon *> sp0 *>
shape_id.map(ExplicitMapValue(_))
val map_value: Parser[MapValue] =
(trait_statements.?.with1.soft ~ (explicit_map_value.backtrack | elided_map_value))
.map { case (traits, member) =>
Expand All @@ -210,9 +206,9 @@ object ShapeParser {
object structure_parsers {
val explicit_structure_member: Parser[ExplicitStructureMember] =
((identifier <* sp0 <* Parser.charIn(':') <* sp0) ~ shape_id)
.map(ExplicitStructureMember.tupled)
.map((ExplicitStructureMember.apply _).tupled)
val elided_structure_member: Parser[ElidedStructureMember] =
(Parser.charIn('$') *> identifier).map(ElidedStructureMember)
(Parser.charIn('$') *> identifier).map(ElidedStructureMember(_))
val structure_member: Parser[StructureMember] = {
((explicit_structure_member.backtrack | elided_structure_member) ~ value_assigments.backtrack.?)
.map { case (member, va) =>
Expand All @@ -231,7 +227,7 @@ object ShapeParser {
}
val structure_resource: Parser[StructureResource] =
(sp0.with1 *> Parser.string("for") *> sp0 *> shape_id)
.map(StructureResource)
.map(StructureResource(_))
val structure_statement: Parser[StructureStatement] = (Parser.string(
"structure"
) *> sp0 *> identifier ~ structure_resource.backtrack.? ~ mixinBT.? ~ ws ~ structure_members)
Expand All @@ -243,7 +239,7 @@ object ShapeParser {
object union_parsers {
val union_member: Parser[UnionMember] =
(structure_parsers.explicit_structure_member | structure_parsers.elided_structure_member)
.map(UnionMember)
.map(UnionMember(_))
val union_members: Parser[UnionMembers] =
(openCurly *> ws ~ (trait_statements.with1 ~ union_member ~ ws).rep0 <* closeCurly)
.map { case (ws0, members) =>
Expand Down Expand Up @@ -347,8 +343,8 @@ object ShapeParser {
}
}
val shape_statement_or_apply: Parser[ShapeStatementsCase] =
shape_statement.map(ShapeStatementCase) |
apply_statement.map(ApplyStatementCase)
shape_statement.map(ShapeStatementCase(_)) |
apply_statement.map(ApplyStatementCase(_))

// The optional trailing BR is not in the spec but it exists in a lot of
// files.
Expand All @@ -366,7 +362,7 @@ object ShapeParser {
(Parser.string("use") *> sp *> absolute_root_shape_id ~ br).map {
case (arsi, br) => UseStatement(arsi, br)
}
val use_section: Parser0[UseSection] = use_statement.rep0.map(UseSection)
val use_section: Parser0[UseSection] = use_statement.rep0.map(UseSection(_))
val shape_section: Parser0[ShapeSection] =
(namespace_statement ~ use_section ~ shape_statements.?).?.map { op =>
ShapeSection(op.map { case ((ns, use), ss) =>
Expand Down
13 changes: 7 additions & 6 deletions modules/formatter/src/parsers/SmithyTraitParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ object SmithyTraitParser {
// TraitStructureKvp *(*WS TraitStructureKvp)
val trait_structure: Parser[TraitStructure] =
(trait_structure_kvp ~ (ws.with1 ~ trait_structure_kvp).backtrack.rep0)
.map(TraitStructure.tupled)
.map((TraitStructure.apply _).tupled)

// trait_structure / node_value
val strait_body_value: Parser0[SmithyTraitBodyValue] =
trait_structure.backtrack.map(SmithyTraitStructureCase) | node_value.map(
NodeValueCase
)
trait_structure.backtrack.map(SmithyTraitStructureCase(_)) |
node_value.map(NodeValueCase(_))
// "(" ws trait_body_value ws ")"
val strait_body: Parser0[TraitBody] =
((openParentheses *> ws ~ strait_body_value.? ~ ws) <* closeParentheses)
Expand All @@ -54,7 +53,9 @@ object SmithyTraitParser {
}
// "@" shape_id [trait_body]
val strait: Parser[SmithyTrait] =
Parser.char('@') *> (shape_id ~ strait_body.?).map { SmithyTrait.tupled }
Parser.char('@') *> (shape_id ~ strait_body.?).map {
(SmithyTrait.apply _).tupled
}
// *(ws trait) ws
val trait_statements: Parser0[TraitStatements] =
((ws.with1 ~ strait).backtrack.rep0 ~ ws).map { case (traits, ws) =>
Expand All @@ -73,7 +74,7 @@ object SmithyTraitParser {
ApplyStatementBlock(a, b, c)
}
val apply_statement: Parser[ApplyStatement] =
apply_block.backtrack.eitherOr(apply_singular).map(ApplyStatement)
apply_block.backtrack.eitherOr(apply_singular).map(ApplyStatement(_))

}

Expand Down
2 changes: 1 addition & 1 deletion modules/formatter/src/parsers/WhitespaceParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ object WhitespaceParser {
.rep0
.map(_.flatMap(_.swap.toOption.flatMap(_.swap.toOption)))
.map(_.flatMap(_.toOption))
.map(Whitespace)
.map(Whitespace(_))

}
6 changes: 3 additions & 3 deletions modules/json-schema/src/internals/Extractors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private[json_schema] object Extractors {
else Some(PDouble)

val (typedMin, typedMax): (Double, Double) = prim match {
case Some(PInt) => (Int.MinValue, Int.MaxValue)
case Some(PInt) => (Int.MinValue.toDouble, Int.MaxValue.toDouble)
case _ => (Double.MinValue, Double.MaxValue)
}

Expand Down Expand Up @@ -127,7 +127,7 @@ private[json_schema] object Extractors {
// type: string
case (s: StringSchema) =>
val pattern =
Option(s.getPattern()).map(_.pattern()).map(Hint.Pattern)
Option(s.getPattern()).map(_.pattern()).map(Hint.Pattern(_))
val max = Option(s.getMaxLength()).map(n => n.longValue())
val min = Option(s.getMinLength()).map(n => n.longValue())
val length =
Expand Down Expand Up @@ -296,7 +296,7 @@ private[json_schema] object Extractors {
case other => other
}
.map(GetExtensions.anyToNode)
.map(Hint.DefaultValue)
.map(Hint.DefaultValue(_))
List(description, default, current, target).flatten ++ extensions
}

Expand Down
2 changes: 1 addition & 1 deletion modules/json-schema/src/internals/JsonSchemaToIModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private class JsonSchemaToIModel[F[_]: Parallel: TellShape: TellError](
private implicit class WithDescriptionSyntax(p: OpenApiPattern[Local]) {
def withDescription(local: Local): OpenApiPattern[Local] = {
val maybeDesc =
Option(local.schema.getDescription()).map(Hint.Description).toList
Option(local.schema.getDescription()).map(Hint.Description(_)).toList
p.mapContext(_.addHints(maybeDesc, retainTopLevel = true))
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/readme-validator/src/ReadmeParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ object ReadmeParser {
val openapiSection =
sectionParser(openapiHeader, smithyHeader)
.map(_.map(_.head))
.map(Example.OpenApi.tupled)
.map(Example.(OpenApi.apply _).tupled)
val jsonSection =
sectionParser(jsonHeader, smithyHeader)
.map(_.map(_.head))
.map(Example.JsonSchema.tupled)
.map(Example.(JsonSchema.apply _).tupled)
val protoSection =
sectionParser(smithyHeader, protoHeader)
.map(_.map(_.head))
.map(Example.Proto.tupled)
.map(Example.(Proto.apply _).tupled)
val section = openapiSection.backtrack
.orElse(jsonSection)
.backtrack
Expand Down

0 comments on commit d8759a4

Please sign in to comment.