Skip to content

Commit

Permalink
Merge branch 'master' into aot-online
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jun 18, 2021
2 parents 46ba80d + 451c82d commit b340c28
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 308 deletions.
1 change: 1 addition & 0 deletions lib/dartdoc.dart
Expand Up @@ -23,6 +23,7 @@ import 'package:dartdoc/src/logging.dart';
import 'package:dartdoc/src/markdown_processor.dart' show markdownStats;
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/package_meta.dart';
import 'package:dartdoc/src/tool_definition.dart';
import 'package:dartdoc/src/tool_runner.dart';
import 'package:dartdoc/src/tuple.dart';
import 'package:dartdoc/src/utils.dart';
Expand Down
Binary file modified lib/resources/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 26 additions & 5 deletions lib/src/comment_references/model_comment_reference.dart
Expand Up @@ -15,6 +15,7 @@ abstract class ModelCommentReference {
bool get allowDefaultConstructor;
String get codeRef;
bool get hasConstructorHint;
bool get hasCallableHint;
List<String> get referenceBy;
Element get staticElement;

Expand All @@ -32,22 +33,42 @@ abstract class ModelCommentReference {
/// information needed for Dartdoc. Drops link to the [CommentReference]
/// and [ResourceProvider] after construction.
class _ModelCommentReferenceImpl implements ModelCommentReference {
bool _allowDefaultConstructor;
@override
bool get allowDefaultConstructor {
if (parsed.length >= 2) {
return parsed[parsed.length - 2] == parsed[parsed.length - 1];
if (_allowDefaultConstructor == null) {
_allowDefaultConstructor = false;
var foundFirst = false;
String checkText;
// Check for two identically named identifiers at the end of the
// parse list, skipping over any junk or other nodes.
for (var node in parsed.reversed.whereType<IdentifierNode>()) {
if (foundFirst) {
if (checkText == node.text) {
_allowDefaultConstructor = true;
}
break;
} else {
foundFirst = true;
checkText = node.text;
}
}
}
return false;
return _allowDefaultConstructor;
}

@override
final String codeRef;

@override
bool get hasConstructorHint =>
bool get hasCallableHint =>
parsed.isNotEmpty &&
(parsed.first is ConstructorHintStartNode ||
parsed.last is ConstructorHintEndNode);
parsed.last is CallableHintEndNode);

@override
bool get hasConstructorHint =>
parsed.isNotEmpty && parsed.first is ConstructorHintStartNode;

@override
List<String> get referenceBy => parsed
Expand Down
45 changes: 27 additions & 18 deletions lib/src/comment_references/parser.dart
Expand Up @@ -133,7 +133,7 @@ class CommentReferenceParser {
if (suffixResult.type == _SuffixResultType.notSuffix) {
// Invalid trailing junk; reject the reference.
return [];
} else if (suffixResult.type == _SuffixResultType.parsedConstructorHint) {
} else if (suffixResult.type == _SuffixResultType.parsedCallableHint) {
children.add(suffixResult.node);
}

Expand All @@ -142,7 +142,6 @@ class CommentReferenceParser {
}

static const _constructorHintPrefix = 'new';

static const _ignorePrefixes = ['const', 'final', 'var'];

/// Implement parsing a prefix to a comment reference.
Expand All @@ -153,17 +152,19 @@ class CommentReferenceParser {
///
/// <constructorPrefixHint> ::= 'new '
///
/// <leadingJunk> ::= ('const' | 'final' | 'var' | 'operator')(' '+)
/// <leadingJunk> ::= ('const' | 'final' | 'var')(' '+)
/// ```
_PrefixParseResult _parsePrefix() {
if (_atEnd) {
return _PrefixParseResult.endOfFile;
}
if (_tryMatchLiteral(_constructorHintPrefix)) {
if (_tryMatchLiteral(_constructorHintPrefix,
requireTrailingNonidentifier: true)) {
return _PrefixParseResult.ok(
ConstructorHintStartNode(_constructorHintPrefix));
}
if (_ignorePrefixes.any((p) => _tryMatchLiteral(p))) {
if (_ignorePrefixes
.any((p) => _tryMatchLiteral(p, requireTrailingNonidentifier: true))) {
return _PrefixParseResult.junk;
}

Expand Down Expand Up @@ -234,10 +235,10 @@ class CommentReferenceParser {
IdentifierNode(codeRef.substring(startIndex, _index)));
}

static const _constructorHintSuffix = '()';
static const _callableHintSuffix = '()';

/// ```text
/// <suffix> ::= <constructorPostfixHint>
/// <suffix> ::= <callableHintSuffix>
/// | <trailingJunk>
///
/// <trailingJunk> ::= '<'<CHARACTER>*'>'
Expand All @@ -246,18 +247,18 @@ class CommentReferenceParser {
/// | '?'
/// | '!'
///
/// <constructorPostfixHint> ::= '()'
/// <callableHintSuffix> ::= '()'
/// ```
_SuffixParseResult _parseSuffix() {
var startIndex = _index;
_walkPastWhitespace();
if (_atEnd) {
return _SuffixParseResult.missing;
}
if (_tryMatchLiteral(_constructorHintSuffix)) {
if (_tryMatchLiteral(_callableHintSuffix)) {
if (_atEnd) {
return _SuffixParseResult.ok(
ConstructorHintEndNode(codeRef.substring(startIndex, _index)));
CallableHintEndNode(codeRef.substring(startIndex, _index)));
}
return _SuffixParseResult.notSuffix;
}
Expand All @@ -278,10 +279,12 @@ class CommentReferenceParser {

/// Advances [_index] on match, preserves on non-match.
bool _tryMatchLiteral(String characters,
{bool acceptTrailingWhitespace = true}) {
{bool acceptTrailingWhitespace = true,
bool requireTrailingNonidentifier = false}) {
assert(acceptTrailingWhitespace != null);
if (characters.length + _index > _referenceLength) return false;
for (var startIndex = _index;
int startIndex;
for (startIndex = _index;
_index - startIndex < characters.length;
_index++) {
if (codeRef.codeUnitAt(_index) !=
Expand All @@ -290,6 +293,12 @@ class CommentReferenceParser {
return false;
}
}
if (requireTrailingNonidentifier) {
if (_atEnd || !_nonIdentifierChars.contains(_thisChar)) {
_index = startIndex;
return false;
}
}
if (acceptTrailingWhitespace) _walkPastWhitespace();
return true;
}
Expand Down Expand Up @@ -386,10 +395,10 @@ enum _SuffixResultType {
junk, // Found known types of junk it is OK to ignore.
missing, // There is no suffix here. Same as EOF as this is a suffix.
notSuffix, // Found something, but not a valid suffix.
parsedConstructorHint, // Parsed a [ConstructorHintEndNode].
parsedCallableHint, // Parsed a [CallableHintEndNode].
}

/// The result of attempting to parse a prefix to a comment reference.
/// The result of attempting to parse a suffix to a comment reference.
class _SuffixParseResult {
final _SuffixResultType type;

Expand All @@ -398,7 +407,7 @@ class _SuffixParseResult {
const _SuffixParseResult._(this.type, this.node);

factory _SuffixParseResult.ok(CommentReferenceNode node) =>
_SuffixParseResult._(_SuffixResultType.parsedConstructorHint, node);
_SuffixParseResult._(_SuffixResultType.parsedCallableHint, node);

static const _SuffixParseResult junk =
_SuffixParseResult._(_SuffixResultType.junk, null);
Expand Down Expand Up @@ -426,14 +435,14 @@ class ConstructorHintStartNode extends CommentReferenceNode {
String toString() => 'ConstructorHintStartNode["$text"]';
}

class ConstructorHintEndNode extends CommentReferenceNode {
class CallableHintEndNode extends CommentReferenceNode {
@override
final String text;

ConstructorHintEndNode(this.text);
CallableHintEndNode(this.text);

@override
String toString() => 'ConstructorHintEndNode["$text"]';
String toString() => 'CallableHintEndNode["$text"]';
}

/// Represents an identifier.
Expand Down

0 comments on commit b340c28

Please sign in to comment.