regexToken: -> switch when match = REGEX_ILLEGAL.exec @chunk @error "regular expressions cannot begin with #{match[2]}", offset: match.index + match[1].length when match = @matchWithInterpolations HEREGEX, '///' {tokens, index} = match comments = [] while matchedComment = HEREGEX_COMMENT.exec @chunk[0...index] {index: commentIndex} = matchedComment [fullMatch, leadingWhitespace, comment] = matchedComment comments.push {comment, offsetInChunk: commentIndex + leadingWhitespace.length} commentTokens = flatten( for commentOpts in comments @commentToken commentOpts.comment, Object.assign commentOpts, heregex: yes, returnCommentTokens: yes ) when match = REGEX.exec @chunk [regex, body, closed] = match @validateEscapes body, isRegex: yes, offsetInChunk: 1 index = regex.length prev = @prev() if prev if prev.spaced and prev[0] in CALLABLE return 0 if not closed or POSSIBLY_DIVISION.test regex else if prev[0] in NOT_REGEX return 0 @error 'missing / (unclosed regex)' unless closed else return 0 [flags] = REGEX_FLAGS.exec @chunk[index..] end = index + flags.length origin = @makeToken 'REGEX', null, length: end switch when not VALID_FLAGS.test flags @error "invalid regular expression flags #{flags}", offset: index, length: flags.length when regex or tokens.length is 1 delimiter = if body then '/' else '///' body ?= tokens[0][1] @validateUnicodeCodePointEscapes body, {delimiter} @token 'REGEX', "/#{body}/#{flags}", {length: end, origin, data: {delimiter}} else @token 'REGEX_START', '(', {length: 0, origin, generated: yes} @token 'IDENTIFIER', 'RegExp', length: 0, generated: yes @token 'CALL_START', '(', length: 0, generated: yes @mergeInterpolationTokens tokens, {double: yes, heregex: {flags}, endOffset: end - flags.length, quote: '///'}, (str) => @validateUnicodeCodePointEscapes str, {delimiter} if flags @token ',', ',', offset: index - 1, length: 0, generated: yes @token 'STRING', '"' + flags + '"', offset: index, length: flags.length @token ')', ')', offset: end, length: 0, generated: yes @token 'REGEX_END', ')', offset: end, length: 0, generated: yes
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4