Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering interpolator #209

Merged
merged 24 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d7dc9d1
interpolator work
Apr 29, 2022
3ca41f9
created interpolator
Apr 29, 2022
0ef3e1b
adds interpolator
May 2, 2022
2d5906e
more application of render interpolator
May 3, 2022
4a8757e
Merge branch 'main' into interpolator
yisraelU May 3, 2022
b733dd7
modify method
May 3, 2022
811b231
Merge remote-tracking branch 'origin/interpolator' into interpolator
May 3, 2022
0726310
Merge branch 'main' into interpolator
yisraelU May 3, 2022
574dd2f
Merge remote-tracking branch 'origin/interpolator' into interpolator
yisraelU May 3, 2022
347b16e
renaming plus check in examples
yisraelU May 6, 2022
b81febd
added primitive Nothing , removed importsAndRender
yisraelU May 8, 2022
ad5f9b6
separation of ToLines and ToLine , generalization of WithValue
yisraelU May 9, 2022
8fe3733
revert build.sbt scalac config
yisraelU May 9, 2022
426bbfc
fixed bug with newline inytroduced when inferring ToLines from ToLine
yisraelU May 9, 2022
abb8393
Merge remote-tracking branch 'origin/interpolator' into interpolator
yisraelU May 9, 2022
0aa8b00
refactor args method
yisraelU May 10, 2022
9dcab6a
Merge branch 'main' into interpolator
yisraelU May 10, 2022
8c83909
Sync with main
Baccata May 10, 2022
d9e838c
Regenerate examples
Baccata May 10, 2022
ddfbe27
Headers + fmt
Baccata May 10, 2022
eb60e31
Fix ByteArray reference
Baccata May 10, 2022
48794ff
removed unused smithy4s.schema.Schema._ import from renderService me…
yisraelU May 10, 2022
8f8095e
add imports for smith primitive types Timestamp and document,
yisraelU May 10, 2022
067624a
Update build.sbt
Baccata May 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ lazy val codegen = projectMatrix
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
scalacOptions := scalacOptions.value
.filterNot(Seq("-Ywarn-value-discard", "-Wvalue-discard").contains)

)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package smithy4s.codegen

import cats.syntax.all._
import cats.~>
import smithy4s.codegen.Hint.Constraint
import smithy4s.codegen.Hint.Native
import smithy4s.codegen.Type.Alias
import smithy4s.codegen.Type.PrimitiveType
import smithy4s.codegen.TypedNode._
import smithy4s.codegen.Hint.Constraint

object CollisionAvoidance {
def apply(compilationUnit: CompilationUnit): CompilationUnit = {
Expand Down
1 change: 1 addition & 0 deletions modules/codegen/src/smithy4s/codegen/IR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ object Primitive {
case object BigDecimal extends Primitive { type T = scala.math.BigDecimal }
case object BigInteger extends Primitive { type T = scala.math.BigInt }
case object Document extends Primitive { type T = Node }
case object Nothing extends Primitive { type T = Nothing }
}

object Type {
Expand Down
44 changes: 44 additions & 0 deletions modules/codegen/src/smithy4s/codegen/LineSyntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2021 Disney Streaming
*
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://disneystreaming.github.io/TOST-1.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package smithy4s.codegen

import cats.implicits._
import smithy4s.codegen.WithValue.ToLineWithValue

object LineSyntax {
implicit class LineInterpolator(val sc: StringContext) extends AnyVal {
def line(renderables: ToLineWithValue[_]*): Line = {
renderAndCombine(renderables.toList)
}

private def renderAndCombine(
renderables: List[ToLineWithValue[_]]
): Line = {
def aux[A](binding: ToLineWithValue[A]): Line = {
val (imports, lines) = binding.render.tupled
Line(imports, lines.mkString(""))
}
val renderLines: List[Line] = renderables.map(r => aux(r))
sc.parts.toList
.map(Line(_))
.zipAll(renderLines, Line.empty, Line.empty)
.flatMap { case (a, b) => List(a, b) }
.combineAll
}

}
}
11 changes: 7 additions & 4 deletions modules/codegen/src/smithy4s/codegen/PartialBlock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package smithy4s.codegen

import cats.syntax.all._

class PartialBlock(s: String) {
def apply[A](inner: A)(implicit A: Renderable[A]): RenderResult =
class PartialBlock(l: Line) {
def apply[A](inner: A)(implicit A: ToLines[A]): Lines = {
val (imports, line) = l.tupled
A.render(inner)
.transformLines(lines => (s + " {") :: indent(lines) ::: "}" :: Nil)
.transformLines(lines => (line + " {") :: indent(lines) ::: "}" :: Nil)
daddykotex marked this conversation as resolved.
Show resolved Hide resolved
.addImports(imports)
}

def apply(inner: Lines*): RenderResult =
def apply(inner: LinesWithValue*): Lines =
apply(inner.toList.foldMap(_.render))

}
124 changes: 0 additions & 124 deletions modules/codegen/src/smithy4s/codegen/Renderable.scala

This file was deleted.

Loading