c2b0d7dd88
Closes #14602. As discussed in that issue, the existing `at` and `name` functions represent two different results with the empty string: 1. Matched the empty string. 2. Did not match anything. Consider the following example. This regex has two named matched groups, `key` and `value`. `value` is optional: ```rust // Matches "foo", "foo;v=bar" and "foo;v=". regex!(r"(?P<key>[a-z]+)(;v=(?P<value>[a-z]*))?"); ``` We can access `value` using `caps.name("value")`, but there's no way for us to distinguish between the `"foo"` and `"foo;v="` cases. Early this year, @BurntSushi recommended modifying the existing `at` and `name` functions to return `Option`, instead of adding new functions to the API. This is a [breaking-change], but the fix is easy: - `refs.at(1)` becomes `refs.at(1).unwrap_or("")`. - `refs.name(name)` becomes `refs.name(name).unwrap_or("")`. |
||
---|---|---|
.. | ||
.gitignore | ||
check.sh | ||
raw-string-literal-ambiguity.md | ||
README.md | ||
RustLexer.g4 | ||
verify.rs |
Reference grammar.
Uses antlr4 and a custom Rust tool to compare
ASTs/token streams generated. You can use the check-syntax
make target to
run all of the available tests.
To use manually:
antlr4 RustLexer.g4
javac *.java
rustc -O verify.rs
for file in ../*/**.rs; do
echo $file;
grun RustLexer tokens -tokens < $file | ./verify $file || break
done
Note That the ../*/**.rs
glob will match every *.rs
file in the above
directory and all of its recursive children. This is a zsh extension.