-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update regex literal lexing and emission
Update the lexing implementation to defer to the regex library, which will pass back the pointer from to resume lexing, and update the emission to call the new `Regex(_regexString:version:)` overload, that will accept the regex string with delimiters. Because this uses the library's lexing implementation, the delimiters are now `'/.../'` and `'|...|'` instead of plain `'...'`.
- Loading branch information
1 parent
300cbab
commit 128f5d4
Showing
18 changed files
with
174 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,6 @@ | ||
import ExperimentalRegexBridging | ||
|
||
public func experimental_regex_strawperson( | ||
_ ptr: UnsafePointer<CChar>? | ||
) -> UnsafePointer<CChar>? { | ||
guard let s = ptr else { return nil } | ||
|
||
func makeError(_ str: String) -> UnsafePointer<CChar>? { | ||
let count = str.utf8.count + 1 | ||
return str.withCString { | ||
assert($0[count-1] == 0) | ||
let ptr = UnsafeMutablePointer<CChar>.allocate(capacity: count) | ||
ptr.initialize(from: $0, count: count) | ||
return UnsafePointer(ptr) | ||
} | ||
} | ||
|
||
let str = String(cString: s) | ||
do { | ||
let _ = try parse(str, .traditional) | ||
return nil | ||
} catch { | ||
return makeError( | ||
"cannot parse regular expression: \(String(describing: error))") | ||
} | ||
} | ||
|
||
public func registerRegexParser() { | ||
Parser_registerParseRegexStrawperson({ experimental_regex_strawperson($0) }) | ||
Parser_registerRegexLiteralParsingFn(libswiftParseRegexLiteral) | ||
Parser_registerRegexLiteralLexingFn(libswiftLexRegexLiteral) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing | ||
// REQUIRES: libswift | ||
|
||
_ = 'abc' | ||
_ = '/abc/' | ||
|
||
_ = ('[*', '+]', '.]') | ||
_ = ('/[*/', '/+]/', '/.]/') | ||
// expected-error@-1 {{cannot parse regular expression}} | ||
|
||
_ = '\w+' | ||
_ = '\'\\' | ||
_ = '/\w+/' | ||
_ = '/\'\\/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing | ||
// REQUIRES: libswift | ||
|
||
// Note there is purposefully no trailing newline here. | ||
// expected-error@+1 {{unterminated regex literal}} | ||
var unterminated = '/xy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing | ||
// REQUIRES: libswift | ||
|
||
let s = '\\'' // expected-error {{unterminated regex literal}} | ||
let s = '/\\/''/ // expected-error {{unterminated regex literal}} | ||
|
||
// expected-error@+1 {{unterminated regex literal}} | ||
var unterminated = 'xy | ||
var unterminated = '/xy |
Oops, something went wrong.