-
Notifications
You must be signed in to change notification settings - Fork 2
Migrating to 0.9
Dylan Halperin edited this page May 9, 2021
·
6 revisions
A lot changed in 0.9. Some huge features were implemented, but doing so required rewriting most of the library from the ground up. Some classes/methods are gone, some are refactored, some are renamed. I tried to ease the pain by providing old values/aliases as deprecated versions of themselves, but coverage isn't 100%.
These are the changes that will almost-certainly break something for you.
- Any
XML
-prefixed class or value has been renamed to useXml
(with lower-case "ml") -
XMLSplitter(...)
becomesSplitter.xml(...)
-
JsonSplitter(...)
becomesSplitter.json(...)
- Combining parsers is no longer done via
(p1 and p2 and p3).as(f)
. Instead,import cats.syntax.apply._
and do(p1, p2, p3).mapN(f)
. Theand
and~
methods onParser
are completely gone. TheParserCombination
classes are completely gone.
- All of the
XML
-prefixed classes and type aliases now useXml
as the prefix instead. The old aliases are available but deprecated.-
XMLParser
renamed toXmlParser
-
XMLTransformer
renamed to `XmlTransformer -
XMLSplitter
renamed toXmlSplitter
-
XMLContextMatcher
renamed toXmlContextMatcher
-
-
SingleElementContextMatcher
renamed toElemContextMatcher
- Most of the
XML*
andJson*
classes are now only type aliases; their member methods have been moved to*Ops
implicit classes defined in the respectivexml
andjson
package objects. - The "companion" objects for
XMLParser
andXMLSplitter
no longer exist. The functionality from those objects has moved to implicit classes that wrap the newParserApplyWithBoundInput
andSplitterApplyWithBoundInput
classes, which are intermediate objects that you get fromParser.apply[In]
andSplitter.apply[In]
respectively. At a source level, it should be pretty much the same as before, aside from the XML->Xml rename (i.e. you still callXmlParser.forText
).-
XMLSplitter.apply
replaced withSplitter.xml
-
JsonSplitter.apply
replaced withSplitter.json
-
- The
xml
andjson
package objects are now the only source of implicits that you used to be able to import individually from objects likeImplicits
orContextMatcherSyntax
. The scaladoc for those packages breaks things down into categories so it should be relatively easy to follow when reading the docs. -
XMLSplitter#asText
renamed totext
.asText
is still available, but deprecated. - Removed the
first
,firstOption
,firstNotNull
,asListOf
helpers from the Splitter classes. They existed as a convenience which allowed you to express "how many" of the substreams you wanted to consume, before attaching a parser to those substreams. This ended up being confusing since it allowed you to do the same thing in multiple ways, without really removing any meaningful amount of boilerplate. If you had code likeXMLSplitter(...).first.as[T]
, rearrange it toSplitter.xml(...).as[T].parseFirst
. -
XmlParser.forMandatoryAttribute
is still available, but now there's a shorter alternative alias:XmlParser.attr
. -
XmlParser.forOptionalAttribute
is still available, but now there's a shorter alternative alias:XmlParser.attrOpt
. - The XmlParser attribute-parser constructors now accept a generic
[N: AsQName]
instead of having overloads forString
and javax'sQName
class.
- Splitter's
as
now takes specifically aParser[In, Out]
instead of aContext => Parser[In, Out]
. Parser is no longer a function that returns itself. - Splitter's
map
now takes specifically aContext => Parser[In, Out]
. If you were passing a Parser instead of a function, use the newjoinBy
method.
- Transformer's
parseForeach
renamed toparseTap
- Transformer's
parseFirstOption
renamed toparseFirstOpt
- Transformer's
parallel
renamed tomerge
- Transformer's
parallelEither
renamed tomergeEither
- Transformer's
parseWith
renamed tointo
.- Removed the
parseWith
signature that took a "debug name" - use.into(...).withName(...)
instead - Deprecated the
>>
operator version of this method
- Removed the
- Transformer's
andThen
renamed tothrough
- Deprecated the
>>
operator version of this method
- Deprecated the
- Transformer's
sink
renamed todrain
- Some of the less-common Transformer member methods have been removed in favor of using
.through(Transformer.thatKindOfMethod)
-
.drop(n)
becomes.through(Transformer.drop(n))
-
.dropWhile(f)
becomes.through(Transformer.dropWhile(f))
-
.take(n)
becomes.through(Transformer.take(n))
-
.takeWhile(f)
becomes.through(Transformer.takeWhile(f))
-
.withSideEffect(f)
becomes.through(Transformer.tap(f))
-
- Transformer's
flatten
removed (from both the trait and the companion object). UsemapFlatten(identity)
instead - Transformer's
wrapSafe
andunwrapSafe
are removed (from both the trait and the companion object). Catching errors should be the responsibility of the underlying Parser, not the Transformer. - Transformer's
transform
method now only accepts anIterator[In]
instead of aConsumableLike[*, In]
. Opening and closing the underlying iterator is not the Transformer's responsibility. You can use the "parser backend" to obtain an Iterator wrapped in a Resource, e.g.JavaxSource.syncIO.iteratorResource(source)
-
Transformer.parallel
removed from the companion object; use themerge
member method on Transformer instead -
Transformer.parallelEither
removed removed from the companion object; use themergeEither
member method on Transformer instead -
Transformer.sideEffect
renamed toTransformer.tap
-
Parser.constant
renamed toParser.pure
-
Parser.foreach
renamed toParser.tap
-
Parser.firstOption
renamed toParser.firstOpt
- A handful of new Parser constructor methods are available on the
Parser
companion object - The
and
and~
methods are removed entirely. Now thatParser
isApplicative
, you can create a tuple of Parsers and usemapN
(which comes fromcats.syntax.apply
) to combine parsers. -
Parser[In, Out]
no longer extendsAny => Parser[In, Out]
- Parser's
parse
method now operates in terms of the newParsable
typeclass.ConsumableLike
has been removed.- Parser now also has a
parseF
method which lifts execution into a givenF[_]
effect context - One major consequence of this change is that you can no longer directly call
parse
on an InputStream or Reader; you must first wrap that stream/reader in acats.effect.Resource
to encapsulate the open/close semantics.
- Parser now also has a
- Previously, XML and JSON support was entirely done via an import to
io.dylemma.spac.xml._
orio.dylemma.spac.json._
. Now, you need to additionally import a "parser backend" to provide the necessary implicits to let you do things likeparser.parse(someFile)
. To get the old behavior, you'll need to add your choice of dependency and import from its respective*Support
object:- For XML, add the
xml-spac-javax
library, andimport io.dylemma.spac.xml.JavaxSupport._
- For JSON, add the
json-spac-jackson
library, andimport io.dylemma.spac.json.JacksonSupport._
- For XML, add the
- You may instead choose to import the new
fs2-data
based parser backends:- For XML, add the
xml-spac-fs2-data
library, andimport io.dylemma.spac.xml.Fs2DataSupport._
- For JSON, add the
json-spac-fs2-data
library, andimport io.dylemma.spac.json.Fs2DataSupport._
- For XML, add the