├── CONTRIBUTORS.txt ├── README.md ├── LICENSE.txt └── syntax.r /CONTRIBUTORS.txt: -------------------------------------------------------------------------------- 1 | In alphabetical order: 2 | 3 | Andreas Bolka 4 | Ladislav Mecir 5 | Steeve 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project aims to produce a formal specification of [REBOL][1] syntax. The 2 | method of specification used is REBOL 3's variant of the [PARSE dialect][2]. 3 | 4 | [1]: http://www.rebol.com/ 5 | [2]: http://www.rebol.com/r3/docs/concepts/parsing-summary.html 6 | 7 | This project is very much a work in progress. So be aware that many datatypes 8 | or lexical intricacies are missing. What already exists may as well be buggy or 9 | even flat out wrong. 10 | 11 | Patches and suggestions are very much welcome. 12 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 The rebol-syntax contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /syntax.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | Purpose: { 3 | A formal description of the REBOL syntax. 4 | 5 | value-syntax ; update when adding a new syntax type 6 | implicit-block 7 | block-syntax 8 | paren-syntax 9 | comment-syntax 10 | integer-syntax 11 | decimal-syntax 12 | char-syntax 13 | string-syntax 14 | binary-syntax 15 | tuple-syntax 16 | word-syntax 17 | issue-syntax 18 | tag-syntax 19 | email-syntax 20 | url-syntax 21 | file-syntax 22 | time-syntax 23 | } 24 | License: { 25 | Copyright (c) 2012 The rebol-syntax contributors 26 | 27 | Permission is hereby granted, free of charge, to any person 28 | obtaining a copy of this software and associated documentation 29 | files (the "Software"), to deal in the Software without 30 | restriction, including without limitation the rights to use, 31 | copy, modify, merge, publish, distribute, sublicense, and/or 32 | sell copies of the Software, and to permit persons to whom the 33 | Software is furnished to do so, subject to the following 34 | conditions: 35 | 36 | The above copyright notice and this permission notice shall be 37 | included in all copies or substantial portions of the 38 | Software. 39 | 40 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 41 | KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 42 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 43 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 44 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 46 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 47 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | } 49 | ] 50 | 51 | alternative-syntax: func [ 52 | {defines (or documents) an alternative syntax} 53 | 'syntax-ids [word! block!] {the id/ids of syntaxes using the alternative} 54 | 'syntax-element [set-word!] 55 | spec 56 | ][ 57 | ; don't do anything at present 58 | ; this way it serves for documentation 59 | ] 60 | 61 | value-syntax: [ 62 | block-syntax 63 | | paren-syntax 64 | | integer-syntax 65 | | decimal-syntax 66 | | char-syntax 67 | | string-syntax 68 | | binary-syntax 69 | | tuple-syntax 70 | | word-syntax 71 | | issue-syntax 72 | | tag-syntax 73 | | email-syntax 74 | | url-syntax 75 | | file-syntax 76 | | time-syntax 77 | ] 78 | 79 | implicit-block: [ 80 | any [ 81 | whitespace 82 | | comment-syntax 83 | | value-syntax not #"/" 84 | | end-load 85 | ] 86 | ] 87 | 88 | block-syntax: [#"[" implicit-block #"]"] 89 | paren-syntax: [#"(" implicit-block #")"] 90 | 91 | non-lf: complement charset [#"^/"] 92 | comment-syntax: [#";" any non-lf #"^/"] 93 | 94 | end-load: [#"^@" to end] 95 | 96 | whitespace: charset [#"^A" - #" " #"^(7F)"] 97 | 98 | sign: [#"+" | #"-"] 99 | digit: charset [#"0" - #"9"] 100 | thousand-separator: [#"'"] 101 | termination-char: union whitespace charset "()[]^"{}/^@;" 102 | termination: [end | and termination-char] 103 | integer-syntax: [opt sign digit any [digit | thousand-separator] termination] 104 | 105 | decimal-separator: [#"." | #","] 106 | e-part: [[#"e" | #"E"] opt sign some digit] 107 | decimal-syntax: [ 108 | opt sign [ 109 | digit any [digit | thousand-separator] [ 110 | e-part | decimal-separator any [digit | thousand-separator] 111 | ] | decimal-separator digit any [digit | thousand-separator] opt e-part 112 | ] termination 113 | ] 114 | 115 | ; see the decimal in path issue: http://issue.cc/r3/1904 116 | alternative-syntax A111 decimal-syntax: [ 117 | opt sign [ 118 | digit any [digit | thousand-separator] [ 119 | e-part | decimal-separator any [digit | thousand-separator] 120 | ] | decimal-separator digit any [digit | thousand-separator] opt e-part 121 | ] termination not #"/" 122 | ] 123 | 124 | hex-digit: charset [#"0" - #"9" #"a" - #"f" #"A" - #"F"] 125 | quoted-char: complement charset [#"^/" #"^"" #"^^"] 126 | non-open: complement charset [#"("] 127 | caret-notation: [ 128 | #"^^" [ 129 | non-open 130 | | #"(" [ 131 | 0 4 hex-digit 132 | | "line" 133 | | "tab" 134 | | "page" 135 | | "back" 136 | | "null" 137 | | "escape" 138 | ] #")" 139 | ] 140 | ] 141 | alternative-syntax R2 caret-notation: [ 142 | #"^^" [ 143 | non-open 144 | | #"(" [ 145 | 0 2 hex-digit 146 | | "line" 147 | | "tab" 148 | | "page" 149 | | "back" 150 | | "null" 151 | | "escape" 152 | ] #")" 153 | ] 154 | ] 155 | char-syntax: [ 156 | "#^"" 157 | [quoted-char | caret-notation] 158 | #"^"" 159 | ] 160 | 161 | quoted-string: [ 162 | #"^"" 163 | any [quoted-char | caret-notation] 164 | #"^"" 165 | ] 166 | 167 | braced-char: complement charset [#"{" #"}" #"^^"] 168 | braced-string: [ 169 | #"{" 170 | any [braced-char | caret-notation | braced-string] 171 | #"}" 172 | ] 173 | 174 | string-syntax: [quoted-string | braced-string] 175 | 176 | binary-2: ["2#{" any [8 [any whitespace [#"0" | #"1"]]] any whitespace #"}"] 177 | binary-16: [opt "16" "#{" any [2 [any whitespace hex-digit]] any whitespace #"}"] 178 | digit-64: charset [#"A" - #"Z" #"a" - #"y" #"0" - #"9" #"+" #"/"] 179 | wsd-64: [any whitespace digit-64] 180 | ws=: [any whitespace #"="] 181 | binary-64: [ 182 | "64#{" 183 | [ 184 | 2 wsd-64 any [4 wsd-64] 2 ws= 185 | | 3 wsd-64 any [4 wsd-64] ws= 186 | | any [4 wsd-64] 187 | ] 188 | any whitespace #"}" 189 | ] 190 | binary-syntax: [binary-2 | binary-16 | binary-64] 191 | 192 | tuple-syntax: [ 193 | [some digit 2 9 [#"." any digit] | #"." some digit 1 8 [#"." any digit]] 194 | termination 195 | ] 196 | 197 | ; invalid path issue: http://issue.cc/r3/1905 198 | 199 | ; words containing the slash character are exceptional: 200 | ; they can contain only slashes 201 | ; they do not have a lit-word syntax 202 | ; they do not have a set-word syntax 203 | ; they do not have a get-word syntax 204 | ; they do not have a refinement syntax 205 | ; they do not have a path syntax 206 | slash-word: [some #"/"] 207 | 208 | ; words containing #"<" or #"> are exceptional: 209 | ; there are only a few words like this 210 | ; the words don't have a set-word syntax 211 | ; the words don't have a refinement syntax 212 | more-less-word: [ 213 | [ 214 | #"<" 215 | | #">" 216 | | "<=" 217 | | ">=" 218 | | "<>" 219 | | ">>" 220 | | "<<" 221 | ] 222 | ] 223 | 224 | ; the :x:y get-words don't have a word-syntax 225 | 226 | ; the //x refinements don't have a word-syntax 227 | 228 | extra-word-char: union termination-char charset ":/#$%<>@\," 229 | word-char: complement extra-word-char 230 | 231 | ; words starting with #"+" or #"-" are exceptional: 232 | ; the second character cannot be a digit 233 | ; if the second character is #".", the third character cannot be a digit 234 | ; the second character cannot be the apostrophe 235 | ; they do not have a refinement syntax 236 | 237 | ; words starting with #"." are exceptional: 238 | ; the second character cannot be a digit 239 | ; they do not have a refinement syntax 240 | ; word followed by a tag http://issue.cc/r3/1903 241 | word-syntax: [ 242 | [ 243 | [ 244 | slash-word 245 | | more-less-word 246 | | sign 247 | ] termination 248 | | opt sign [#"." | not #"'" and word-char] not digit any word-char 249 | [ 250 | termination 251 | | and [ 252 | #"<" not termination 253 | not [ 254 | #"#" | #"$" | #"%" | #"(" | #")" | #"," | #"<" | #"=" 255 | | #">" | #"\" | #":" 256 | ] 257 | ] 258 | ] 259 | ] 260 | ] 261 | 262 | alternative-syntax simplified word-syntax: [ 263 | [ 264 | slash-word 265 | | more-less-word 266 | | and word-char opt sign [#"." | not #"'"] not digit any word-char 267 | ] 268 | termination 269 | ] 270 | 271 | issue-char: complement union charset "@$%:<>\#" termination-char 272 | alternative-syntax R2 issue-char: complement union charset "@" termination-char 273 | 274 | issue-syntax: [#"#" some issue-char termination] 275 | alternative-syntax R2 issue-syntax: [#"#" any issue-char termination] 276 | 277 | tag-char-beg: complement union whitespace charset {=<>"^@} 278 | tag-char: complement charset {">^@} 279 | 280 | tag-syntax: [ 281 | #"<" 282 | [not #"]" tag-char-beg | quoted-string] 283 | any [some tag-char | quoted-string] 284 | #">" 285 | termination 286 | ] 287 | alternative-syntax R2 tag-syntax: [ 288 | #"<" 289 | [tag-char-beg | quoted-string] any [some tag-char | quoted-string] 290 | #">" 291 | termination 292 | ] 293 | 294 | escape-uri: [#"%" 2 hex-digit] 295 | email-char: complement union charset {%@:} termination-char 296 | email-esc: [email-char | escape-uri] 297 | email-syntax: [ 298 | [ 299 | #":" any [email-esc | #":" ] #"@" any [email-esc | #":" ] 300 | | not #"<" some email-esc #"@" any email-esc 301 | ] 302 | termination 303 | ] 304 | 305 | url-syntax: [ 306 | not [digit | #"'" | #"." digit | sign] word-char 307 | any [escape-uri | not termination-char not #":" skip] 308 | #":" 309 | any [escape-uri | #"/" | not termination-char skip] 310 | ] 311 | 312 | file-char: complement union charset {%:@} termination-char 313 | file-char/#"/": true ;** #"/" added 314 | file-syntax: [ 315 | #"%" [ 316 | quoted-string 317 | | any [file-char | escape-uri] ;** fail on ^ char 318 | ] termination 319 | ] 320 | alternative-syntax R2 file-syntax: [ 321 | #"%" [ 322 | quoted-string 323 | | some [file-char | escape-uri | #"^^"] ;** ^ valid char 324 | ] termination 325 | ] 326 | 327 | time-syntax: [ 328 | [ 329 | and [#":" digit] ; :## 330 | | sign ; +:, -: 331 | | opt sign some digit : +-##: 332 | ] 333 | 1 2 [ 334 | #":" not #"." [ 335 | opt #"+" any digit #"." any digit not #":" ; :+##.## 336 | | #"-" any #"0" #"." any digit not #":" ; :-00.##: 337 | | opt #"+" some digit ; :+##: 338 | | #"+" ; :+: 339 | | #"-" any #"0" ; :-00:, :-: 340 | ] 341 | ] termination 342 | ] 343 | 344 | month-names: [ 345 | "January" | "Januar" | "Janua" | "Janu" | "Jan" | 346 | "February" | "Februar" | "Februa" | "Febru" | "Febr" | "Feb" | 347 | "March" | "Marc" | "Mar" | 348 | "April" | "Apri" | "Apr" | 349 | "May" | 350 | "June" | "Jun" | 351 | "July" | "Jul" | 352 | "August" | "Augus" | "Augu" | "Aug" | 353 | "September" | "Septembe" | "Septemb" | "Septem" | "Septe" | "Sept" | "Sep" | 354 | "October" | "Octobe" | "Octob" | "Octo" | "Oct" | 355 | "November" | "Novembe" | "Novemb" | "Novem" | "Nove" | "Nov" | 356 | "December" | "Decembe" | "Decemb" | "Decem" | "Dece" | "Dec" 357 | ] --------------------------------------------------------------------------------