-
Notifications
You must be signed in to change notification settings - Fork 125
Update RegExps in documentation_comment.dart #3571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -14,22 +14,19 @@ import 'package:meta/meta.dart'; | |
import 'package:path/path.dart' as p show Context; | ||
|
||
final _templatePattern = RegExp( | ||
r'[ ]*{@template\s+(.+?)}([\s\S]+?){@endtemplate}[ ]*(\n?)', | ||
multiLine: true); | ||
r'[ ]*\{@template\s+([^\s}].*?)\}([^]+?)\{@endtemplate\}[ ]*(\n?)'); | ||
final _htmlPattern = RegExp( | ||
r'[ ]*{@inject-html\s*}([\s\S]+?){@end-inject-html}[ ]*\n?', | ||
multiLine: true); | ||
r'[ ]*\{@inject-html\s*\}([^]+?)\{@end-inject-html\}[ ]*\n?'); | ||
|
||
/// Matches all tool directives (even some invalid ones). This is so | ||
/// we can give good error messages if the directive is malformed, instead of | ||
/// just silently emitting it as-is. | ||
final _basicToolPattern = RegExp( | ||
r'[ ]*{@tool\s+([^}]+)}\n?([\s\S]+?)\n?{@end-tool}[ ]*\n?', | ||
multiLine: true); | ||
r'[ ]*{@tool\s+([^\s}][^}]*)}\n?([^]+?)\n?{@end-tool}[ ]*\n?'); | ||
|
||
final _examplePattern = RegExp(r'{@example\s+([^}]+)}'); | ||
final _examplePattern = RegExp(r'{@example\s+([^\s}][^}]*)}'); | ||
|
||
final _macroRegExp = RegExp(r'{@macro\s+([^}]+)}'); | ||
final _macroRegExp = RegExp(r'{@macro\s+([^\s}][^}]*)}'); | ||
|
||
final _htmlInjectRegExp = RegExp(r'<dartdoc-html>([a-f0-9]+)</dartdoc-html>'); | ||
|
||
|
@@ -169,7 +166,7 @@ mixin DocumentationComment | |
'required', | ||
}; | ||
|
||
static final _nameBreak = RegExp('[\\s}]'); | ||
static final _nameBreak = RegExp(r'[\s}]'); | ||
|
||
// TODO(srawlins): Implement more checks; see | ||
// https://github.com/dart-lang/dartdoc/issues/1814. | ||
|
@@ -391,7 +388,7 @@ mixin DocumentationComment | |
/// Matches all youtube directives (even some invalid ones). This is so | ||
/// we can give good error messages if the directive is malformed, instead of | ||
/// just silently emitting it as-is. | ||
static final _basicYouTubePattern = RegExp(r'''{@youtube\s+([^}]+)}'''); | ||
static final _basicYouTubePattern = RegExp(r'{@youtube\s+([^\s}][^}]*)}'); | ||
|
||
/// Matches YouTube IDs from supported YouTube URLs. | ||
static final _validYouTubeUrlPattern = | ||
|
@@ -476,7 +473,7 @@ mixin DocumentationComment | |
/// Matches all animation directives (even some invalid ones). This is so we | ||
/// can give good error messages if the directive is malformed, instead of | ||
/// just silently emitting it as-is. | ||
static final _basicAnimationPattern = RegExp(r'''{@animation\s+([^}]+)}'''); | ||
static final _basicAnimationPattern = RegExp(r'{@animation\s+([^\s}][^}]*)}'); | ||
|
||
/// Matches valid JavaScript identifiers. | ||
static final _validIdPattern = RegExp(r'^[a-zA-Z_]\w*$'); | ||
|
@@ -675,8 +672,8 @@ mixin DocumentationComment | |
/// Match group 4 is the unquoted arg, if any. | ||
static final RegExp _argPattern = RegExp(r'([a-zA-Z\-_0-9]+=)?' // option name | ||
r'(?:' // Start a new non-capture group for the two possibilities. | ||
r'''(["'])((?:\\{2})*|(?:.*?[^\\](?:\\{2})*))\2|''' // with quotes. | ||
r'([^ ]+))'); // without quotes. | ||
r'''(["'])((?:[^\\\r\n]|\\.)*?)\2|''' // with quotes. | ||
r'(\S+))'); // without quotes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a change. It didn't seem reasonable to accept newlines or tabs as part of an unquoted argument. Matching non-whitespace seemed better than just non-space-char. |
||
|
||
/// Helper to process arguments given as a (possibly quoted) string. | ||
/// | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be equivalent, but simpler. The original RE stopped at the next quote not preceded by an odd number of backslashes.
The new one must match the character after a backslash as content, whether it's a backslash or not.
Effect should be the same, just much easier to read (IMO).