-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20c1bf1
commit 9420577
Showing
8 changed files
with
188 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'src/dart_model.dart'; | ||
|
||
/// Converts [template] to a mix of `Identifier` and `String`. | ||
/// | ||
/// References of the form `{{uri#name}}` become [QualifiedName] wrapped in | ||
/// [Code.qualifiedName], everything else becomes [ResolvedCode]. | ||
List<Code> expandTemplate(String template) { | ||
final result = <Code>[]; | ||
var index = 0; | ||
while (index < template.length) { | ||
final start = template.indexOf('{{', index); | ||
if (start == -1) { | ||
result.add( | ||
Code.resolvedCode(ResolvedCode(code: template.substring(index)))); | ||
break; | ||
} | ||
result.add(Code.resolvedCode( | ||
ResolvedCode(code: template.substring(index, start)))); | ||
final end = template.indexOf('}}', start); | ||
if (end == -1) { | ||
throw ArgumentError('Unmatched opening brace: $template'); | ||
} | ||
final name = template.substring(start + 2, end); | ||
final parts = name.split('#'); | ||
if (parts.length != 2) { | ||
throw ArgumentError('Expected "uri#name" in: $name'); | ||
} | ||
result | ||
.add(Code.qualifiedName(QualifiedName(uri: parts[0], name: parts[1]))); | ||
index = end + 2; | ||
} | ||
return result; | ||
} |
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