-
Notifications
You must be signed in to change notification settings - Fork 50
/
Rfc5234.scala
112 lines (94 loc) · 3.05 KB
/
Rfc5234.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (c) 2021 Typelevel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package cats.parse
/** Parsers for the common rules of RFC5234. These rules are
* referenced by several RFCs.
*
* @see [[https://tools.ietf.org/html/rfc5234]]
*/
object Rfc5234 {
/** A-Z and a-z, without diacritics
*/
val alpha: Parser[Char] =
Parser.charIn('A' to 'Z') | Parser.charIn('a' to 'z')
/** `0` or `1`
*/
val bit: Parser[Char] =
Parser.charIn('0' to '1')
/** any 7-bit US-ASCII character, excluding NUL
*/
val char: Parser[Char] =
Parser.charIn(0x01.toChar to 0x7f.toChar)
/** carriage return
*/
val cr: Parser[Unit] =
Parser.char('\r')
/** linefeed
*/
val lf: Parser[Unit] =
Parser.char('\n')
/** Internet standard newline */
val crlf: Parser[Unit] =
Parser.string("\r\n")
/** controls */
val ctl: Parser[Char] =
Parser.charIn(0x7f, (0x00.toChar to 0x1f.toChar): _*)
/** `0` to `9`
*/
val digit: Parser[Char] =
Numbers.digit
/** double quote (`"`)
*/
val dquote: Parser[Unit] =
Parser.char('"')
/** hexadecimal digit, case insensitive
*/
val hexdig: Parser[Char] =
digit | Parser.ignoreCaseCharIn('A' to 'F')
/** horizontal tab
*/
val htab: Parser[Unit] =
Parser.char('\t')
/** space */
val sp: Parser[Unit] =
Parser.char(' ')
/** white space (space or horizontal tab) */
val wsp: Parser[Unit] = sp | htab
/** linear white space.
*
* Use of this rule permits lines containing only white space that
* are no longer legal in mail headers and have caused
* interoperability problems in other contexts.
*
* Do not use when defining mail headers and use with caution in
* other contexts.
*/
val lwsp: Parser0[Unit] =
Parser.repAs0[Unit, List[Unit]](wsp.orElse(crlf *> wsp)).void
/** 8 bits of data
*/
val octet: Parser[Char] =
Parser.charIn(0x00.toChar to 0xff.toChar)
/** visible (printing) characters
*/
val vchar: Parser[Char] =
Parser.charIn(0x21.toChar to 0x7e.toChar)
}