com.github.rockjam.httpaste.parsing.UriParser.scala Maven / Gradle / Ivy
The newest version!
package com.github.rockjam.httpaste.parsing
import fastparse.all._
object UriParser {
val parser: Parser[URI] = {
val alfa = CharIn('a' to 'z')
val alfaUpper = CharIn('A' to 'Z')
val num = CharIn('0' to '9')
val alfaNum = alfa | alfaUpper | num
// val reserved = CharIn(Seq('/', ':', '.'))
val pctEncoded = CharIn('0' to '9', 'A' to 'F', Seq('%'))
val scheme = ("https" | "http").!
val `hier-part` = "//".? ~ (alfaNum | CharIn("./()_-")).rep(min = 1).!
val queryString = (pctEncoded | alfaNum | CharIn(".=")).rep(min = 1).!
val fragment = AnyChar.rep(min = 1).!
((scheme ~ ":").? ~ `hier-part` ~ ("?" ~ queryString).? ~ ("#" ~ fragment).?)
.map(URI.tupled)
}
}