package wax-lib
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Libraries for Wax, a Rust-like syntax for WebAssembly
Install
dune-project
Dependency
Authors
Maintainers
Sources
wax-0.1.0.tbz
sha256=41b580846af8d41bdf6c3f005f62e38feda3e60fe2e9e4aa440db34ce515a153
sha512=4b3a181fcc7d743194a8647260870fb5190770066a197bcc48104c2b77fd40c643228b795c2bcd6b29a120820e969eb42a37a9bcec98b3f608d13f152d9f6579
doc/src/wax-lib.wax/lexer.ml.html
Source file lexer.ml
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356let white = [%sedlex.regexp? Plus (' ' | '\t')] let newline = [%sedlex.regexp? '\r' | '\n' | "\r\n"] let id_start_c = [%sedlex.regexp? 'a' .. 'z' | 'A' .. 'Z' | 0x80 .. 0x10FFFF] let id_cont_c = [%sedlex.regexp? 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | 0x80 .. 0x10FFFF | '\''] (* Coarse identifier rule: ASCII identifier characters plus any non-ASCII scalar. The strict Unicode XID check is done separately in [validate_identifier], keeping the large XID character classes out of the sedlex DFA. *) let ident = [%sedlex.regexp? id_start_c, Star id_cont_c | '_', Plus id_cont_c] (* Revalidate a coarsely-lexed identifier against the strict XID classes. ASCII characters accepted by the coarse rule are exactly the intended identifier characters, so only non-ASCII scalars need checking: the first against XID_Start, the rest against XID_Continue. Returns the byte offset and byte length of the first character that is not allowed, or [None] if the whole identifier is valid. *) let invalid_identifier_char s = let n = String.length s in let rec go i first = if i >= n then None else let d = String.get_utf_8_uchar s i in let len = Uchar.utf_decode_length d in let c = Uchar.to_int (Uchar.utf_decode_uchar d) in let ok = if c < 0x80 then true else if first then Wax_utils.Xid.is_xid_start c else Wax_utils.Xid.is_xid_continue c in if ok then go (i + len) false else Some (i, len) in go 0 true let validate_identifier s = invalid_identifier_char s = None let sign = [%sedlex.regexp? Opt ('+' | '-')] let digit = [%sedlex.regexp? '0' .. '9'] let hexdigit = [%sedlex.regexp? '0' .. '9' | 'a' .. 'f' | 'A' .. 'F'] let num = [%sedlex.regexp? digit, Star (Opt '_', digit)] let hexnum = [%sedlex.regexp? hexdigit, Star (Opt '_', hexdigit)] let int = [%sedlex.regexp? num | "0x", hexnum] let decfloat = [%sedlex.regexp? num, Opt ('.', Opt num), (('e' | 'E'), sign, num) | num, '.', Opt num] let hexfloat = [%sedlex.regexp? ( "0x", hexnum, Opt ('.', Opt hexnum), (('p' | 'P'), sign, num) | "0x", hexnum, '.', Opt hexnum )] let float = [%sedlex.regexp? decfloat | hexfloat | "nan:0x", hexnum] let stringchar = [%sedlex.regexp? ( Sub (any, (0 .. 31 | 0x7f | '"' | '\\')) | "\\t" | "\\n" | "\\r" | "\\'" | "\\\"" | "\\\\" | "\\u{", hexnum, "}" )] let stringelem = [%sedlex.regexp? stringchar | "\\x", hexdigit, hexdigit] let linechar = [%sedlex.regexp? Sub (any, (10 | 13))] let linecomment = [%sedlex.regexp? "//", Star linechar, (newline | eof)] let string_buffer = Buffer.create 256 let rec comment_rec lexbuf = match%sedlex lexbuf with | "*/" -> Buffer.add_string string_buffer "*/" | "/*" -> Buffer.add_string string_buffer "/*"; comment_rec lexbuf; comment_rec lexbuf | '*' | '/' | Plus (Sub (any, ('*' | '/'))) -> Buffer.add_string string_buffer (Sedlexing.Utf8.lexeme lexbuf); comment_rec lexbuf | _ -> raise (Wax_wasm.Parsing.Syntax_error ( Sedlexing.lexing_bytes_positions lexbuf, Wax_utils.Message.text (Printf.sprintf "Malformed comment.\n") )) let comment lexbuf = Buffer.add_string string_buffer "/*"; comment_rec lexbuf; let s = Buffer.contents string_buffer in Buffer.clear string_buffer; s let unicode_escape lexbuf s = match Wax_utils.Unicode.scalar_of_hex s with | Some u -> u | None -> raise (Wax_wasm.Parsing.Syntax_error ( Sedlexing.lexing_bytes_positions lexbuf, Wax_utils.Message.text (Printf.sprintf "Malformed Unicode escape.\n") )) let rec string lexbuf = match%sedlex lexbuf with | '"' -> let s = Buffer.contents string_buffer in Buffer.clear string_buffer; s | Plus (Sub (any, (0 .. 31 | 0x7f | '"' | '\\'))) -> Buffer.add_string string_buffer (Sedlexing.Utf8.lexeme lexbuf); string lexbuf | "\\t" -> Buffer.add_char string_buffer '\t'; string lexbuf | "\\n" -> Buffer.add_char string_buffer '\n'; string lexbuf | "\\r" -> Buffer.add_char string_buffer '\r'; string lexbuf | "\\'" -> Buffer.add_char string_buffer '\''; string lexbuf | "\\\"" -> Buffer.add_char string_buffer '"'; string lexbuf | "\\\\" -> Buffer.add_char string_buffer '\\'; string lexbuf | "\\x", hexdigit, hexdigit -> let s = String.sub (Sedlexing.Utf8.lexeme lexbuf) 2 2 in Buffer.add_char string_buffer (Char.chr (int_of_string ("0x" ^ s))); string lexbuf | "\\u{", hexnum, "}" -> let n = Sedlexing.Utf8.sub_lexeme lexbuf 3 (Sedlexing.lexeme_length lexbuf - 4) in Buffer.add_utf_8_uchar string_buffer (unicode_escape lexbuf n); string lexbuf | _ -> raise (Wax_wasm.Parsing.Syntax_error ( Sedlexing.lexing_bytes_positions lexbuf, Wax_utils.Message.text (Printf.sprintf "Malformed string.\n") )) let with_loc f lexbuf = let loc_start = Sedlexing.lexing_bytes_position_start lexbuf in let desc = f lexbuf in { Ast.desc; info = { Ast.loc_start; loc_end = Sedlexing.lexing_bytes_position_curr lexbuf }; } open Tokens let rec token_rec ctx lexbuf = match%sedlex