Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / rx.aug
1 (*
2 Module: Rx
3    Generic regexps to build lenses
4
5 Author: Raphael Pinson <raphink@gmail.com>
6
7 About: License
8   This file is licensed under the LGPL v2+, like the rest of Augeas.
9 *)
10
11
12 module Rx =
13
14 (* Group: Spaces *)
15 (* Variable: space
16    A mandatory space or tab *)
17 let space     = /[ \t]+/
18
19 (* Variable: opt_space
20    An optional space or tab *)
21 let opt_space = /[ \t]*/
22
23 (* Variable: cl
24    A continued line with a backslash *)
25 let cl = /[ \t]*\\\\\n[ \t]*/
26
27 (* Variable: cl_or_space
28    A <cl> or a <space> *)
29 let cl_or_space = cl | space
30
31 (* Variable: cl_or_opt_space
32    A <cl> or a <opt_space> *)
33 let cl_or_opt_space = cl | opt_space
34
35 (* Group: General strings *)
36
37 (* Variable: space_in
38    A string which does not start or end with a space *)
39 let space_in  = /[^ \r\t\n].*[^ \r\t\n]|[^ \t\n\r]/
40
41 (* Variable: no_spaces
42    A string with no spaces *)
43 let no_spaces = /[^ \t\r\n]+/
44
45 (* Variable: word
46    An alphanumeric string *)
47 let word       = /[A-Za-z0-9_.-]+/
48
49 (* Variable: integer
50    One or more digits *)
51 let integer    = /[0-9]+/
52
53 (* Variable: relinteger
54    A relative <integer> *)
55 let relinteger = /[-+]?[0-9]+/
56
57 (* Variable: relinteger_noplus
58    A relative <integer>, without explicit plus sign *)
59 let relinteger_noplus = /[-]?[0-9]+/
60
61 (* Variable: decimal
62    A decimal value (using ',' or '.' as a separator) *)
63 let decimal    = /[0-9]+([.,][0-9]+)?/
64
65 (* Variable: reldecimal
66    A relative <decimal> *)
67 let reldecimal    = /[+-]?[0-9]+([.,][0-9]+)?/
68
69 (* Variable: byte
70   A byte (0 - 255) *)
71 let byte = /25[0-5]?|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]/
72
73 (* Variable: hex
74    A hex value *)
75 let hex = /0x[0-9a-fA-F]+/
76
77 (* Variable: octal
78    An octal value *)
79 let octal = /0[0-7]+/
80
81 (* Variable: fspath
82    A filesystem path *)
83 let fspath    = /[^ \t\n]+/
84
85 (* Group: All but... *)
86 (* Variable: neg1
87    Anything but a space, a comma or a comment sign *)
88 let neg1      = /[^,# \n\t]+/
89
90 (*
91  * Group: IPs
92  * Cf. http://blog.mes-stats.fr/2008/10/09/regex-ipv4-et-ipv6/ (in fr)
93  *)
94
95 (* Variable: ipv4 *)
96 let ipv4 =
97   let dot     = "." in
98     byte . dot . byte . dot . byte . dot . byte
99
100 (* Variable: ipv6 *)
101 let ipv6 =
102   /(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})/
103   | /(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})/
104   | /(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})/
105   | /(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})/
106   | /(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})/
107   | /(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})/
108   | (    /([0-9A-Fa-f]{1,4}:){6}/
109            . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/
110            . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/
111     )
112   | (    /([0-9A-Fa-f]{1,4}:){0,5}:/
113            . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/
114            . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/
115     )
116   | (    /::([0-9A-Fa-f]{1,4}:){0,5}/
117            . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/
118            . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/
119     )
120   | (    /[0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}/
121            . /[0-9A-Fa-f]{1,4}/
122     )
123   | /(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})/
124   | /(([0-9A-Fa-f]{1,4}:){1,7}:)/
125
126
127 (* Variable: ip
128    An <ipv4> or <ipv6> *)
129 let ip        = ipv4 | ipv6
130
131
132 (* Variable: hostname
133    A valid RFC 1123 hostname *)
134 let hostname = /(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*(
135                   [A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/
136
137 (*
138  * Variable: device_name
139  * A Linux device name like eth0 or i2c-0. Might still be too restrictive
140  *)
141
142 let device_name = /[a-zA-Z0-9_?.+:!-]+/
143
144 (*
145  * Variable: email_addr
146  *    To be refined
147  *)
148 let email_addr = /[A-Za-z0-9_+.-]+@[A-Za-z0-9_.-]+/
149
150 (*
151  * Variable: iso_8601
152  *    ISO 8601 date time format
153  *)
154 let year = /[0-9]{4}/
155 let relyear = /[-+]?/ . year
156 let monthday = /W?[0-9]{2}(-?[0-9]{1,2})?/
157 let time =
158      let sep = /[T \t]/
159   in let digits = /[0-9]{2}(:?[0-9]{2}(:?[0-9]{2})?)?/
160   in let precis = /[.,][0-9]+/
161   in let zone = "Z" | /[-+]?[0-9]{2}(:?[0-9]{2})?/
162   in sep . digits . precis? . zone?
163 let iso_8601 = year . ("-"? . monthday . time?)?
164
165 (* Variable: url_3986
166    A valid RFC 3986 url - See Appendix B *)
167 let url_3986 = /(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/