Skip to content

Commit

Permalink
Generic ReturnEvent production
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Podsiadlo committed Oct 15, 2021
1 parent 75ba5bd commit b22aab6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ private enum Production:
case ParseSequenceEntryOpt

case ParseFlowNode
case ParseFlowPairKey
case ParseFlowPairValue

case ParseFlowMappingStart
case ParseFlowMappingEnd
Expand All @@ -48,9 +46,11 @@ private enum Production:
case ParseFlowSeqEnd
case ParseFlowSeqEntry
case ParseFlowSeqEntryOpt
case ParseFlowSeqPairKey
case ParseFlowSeqPairValue
case ParseFlowSeqComma

case AddMappingEnd
case ReturnEvent(produceEvent: Token => Event)

/**
* Parser takes a stream of [[Token]]s and produces a series of serialization [[Event]]s. Parsing can fail due to ill-formed input.
Expand Down Expand Up @@ -313,7 +313,7 @@ final class ParserImpl private (in: Tokenizer) extends Parser:

def parseFlowSeqEntry() = token.kind match
case TokenKind.MappingKey =>
productions.prependAll(ParseFlowPairKey :: ParseFlowSeqComma :: Nil)
productions.prependAll(ParseFlowSeqPairKey :: ParseFlowSeqComma :: Nil)
Right(Event.MappingStart(Some(token.pos)))
case _ =>
productions.prependAll(ParseFlowNode :: ParseFlowSeqComma :: Nil)
Expand All @@ -330,7 +330,11 @@ final class ParserImpl private (in: Tokenizer) extends Parser:
def parseFlowPairKey() = token.kind match
case TokenKind.MappingKey =>
in.popToken()
productions.prependAll(ParseFlowNode :: ParseFlowPairValue :: AddMappingEnd :: Nil)
productions.prependAll(
ParseFlowNode :: ParseFlowSeqPairValue :: ReturnEvent(t =>
Event.MappingEnd(Some(t.pos))
) :: Nil
)
getNextEventImpl()
case _ =>
Left(ParseError.from(TokenKind.MappingKey, token))
Expand Down Expand Up @@ -404,10 +408,10 @@ final class ParserImpl private (in: Tokenizer) extends Parser:
case ParseFlowSeqEntryOpt => parseFlowSeqEntryOpt()
case ParseFlowSeqComma => parseFlowSeqComma()

case ParseFlowPairKey => parseFlowPairKey()
case ParseFlowPairValue => parseFlowPairValue()
case ParseFlowSeqPairKey => parseFlowPairKey()
case ParseFlowSeqPairValue => parseFlowPairValue()

case AddMappingEnd => Right(Event.MappingEnd(Some(token.pos)))
case ReturnEvent(produceEvent) => Right(produceEvent(token))
end getNextEventImpl
end ParserImpl

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ private[yaml] class Scanner(str: String) extends Tokenizer {
case Some(':') if in.peekNext().exists(_ == ',') => sb.result()
case Some(char) if !ctx.isAllowedSpecialCharacter(char) => sb.result()
case Some(' ') if in.peekNext() == Some('#') => sb.result()
// case Some(_) if in.peekNext().exists(_ == ',') => sb.result()
case _ if in.isNewline =>
skipUntilNextChar()
sb.append(' ')
Expand Down

0 comments on commit b22aab6

Please # to comment.