dart library
Dart grammar, strongly typed AST models, and parser based on the Dart programming language specification.
Supports modern Dart 3.x features including records, patterns, switch expressions, enhanced enums, extension types, class modifiers, and null safety.
For example:
final unit = parseDart('void main() => print("Hello, Dart!");');
print(unit.declarations.first);
Classes
- AnnotationNode
-
An annotation / metadata (
@deprecated,@override,@Route('/path')). - ArgumentNode
-
A function call argument (
exprorname: expr). - AssertInitializerNode
-
An assert statement in an initializer list (
assert(...)). - AssertStatementNode
-
An assert statement (
assert(cond, message);). - AwaitExpressionNode
-
An await expression (
await expr). - BinaryExpressionNode
-
A binary expression (
a + b,x && y,a = b). - BlockFunctionBodyNode
-
A block function body (
{ ... }). - BlockStatementNode
-
A block statement (
{ ... }). - BooleanLiteralNode
-
A boolean literal (
true,false). - BreakStatementNode
-
A break statement (
break [label];). - CascadeExpressionNode
-
A cascade expression (
a..b()..c = 1). - CastPatternNode
-
A cast pattern (
pattern as Type). - CatchClauseNode
- A catch or on clause in a try statement.
- ClassDeclarationNode
- A class declaration.
- CollectionElementNode
- Base class for collection literal elements.
- CollectionLiteralNode
- A collection literal (List, Set, or Map).
- CombinatorNode
-
Base class for import/export combinators (
showandhide). - CompilationUnitNode
- A complete Dart compilation unit (source file).
- ConditionalExpressionNode
-
A ternary conditional expression (
a ? b : c). - ConfigurationUriNode
-
A conditional configuration in a configurable URI (
if (dart.library.io) 'foo.dart'). - ConstantPatternNode
- A constant pattern (literal, identifier, const expression).
- ConstructorDeclarationNode
- A constructor declaration.
- ConstructorInitializerNode
- Base class for constructor initializer list entries.
- ContinueStatementNode
-
A continue statement (
continue [label];). - DartGrammarDefinition
- Complete grammar and parser definition for the Dart programming language.
- DartNode
- Base class for all Dart AST nodes.
- DeclarationNode
- Base class for all top-level and class-level declarations.
- DirectiveNode
- Base class for library directives.
- DoubleLiteralNode
-
A double literal (
3.14,1e-5). - DoWhileStatementNode
- A do-while loop.
- EmptyFunctionBodyNode
-
An empty / native / abstract function body (
;). - EmptyStatementNode
-
An empty statement (
;). - EnumConstantNode
- An enum constant entry.
- EnumDeclarationNode
-
An enum declaration (
enum Foo { a, b; void bar() {} }). - ExportDirectiveNode
-
An export directive (
export 'foo.dart' show a, b;). - ExpressionElementNode
-
An expression element in a collection (
[a, b]or[?a, ?b]). - ExpressionFunctionBodyNode
-
An expression (arrow) function body (
=> expr;). - ExpressionNode
- Base class for expressions.
- ExpressionStatementNode
-
An expression statement (
expr;). - ExtensionDeclarationNode
-
An extension declaration (
extension Foo<T> on Bar { ... }). - ExtensionTypeDeclarationNode
-
An extension type declaration (
extension type Foo(int i) { ... }). - FieldDeclarationNode
- A field or top-level variable declaration.
- FieldInitializerNode
-
A field initializer in an initializer list (
field = exprorthis.field = expr). - ForElementNode
-
A traditional for-element in a collection (
for (init; cond; update) element). - ForInElementNode
-
A for-in element in a collection (
for (var x in iterable) element). - ForInStatementNode
-
A for-in loop (
for (var x in iterable) body). - ForPartsClassic
-
Traditional for-loop parts (
init; cond; updates). - ForPartsIn
-
For-in loop parts (
variable/pattern in iterable). - ForStatementNode
-
A traditional for loop (
for (init; cond; update) body). - FunctionBodyNode
- Base class for function bodies.
- FunctionDeclarationNode
- A function or method declaration.
- FunctionDeclarationStatementNode
-
A function declaration statement (
void foo() {}). - FunctionExpressionNode
-
An anonymous function / lambda expression (
(x) => x + 1or(x) { ... }). - FunctionTypedParameterNode
-
A function-typed formal parameter (
void callback(int x)). - FunctionTypeNode
-
A function type (
int Function(String)). - HideCombinatorNode
-
A hide combinator (
hide a, b). - IdentifierNode
- An identifier expression.
- IfElementNode
-
An if-element in a collection (
if (c) a else borif (x case p) a). - IfNullExpressionNode
-
An if-null expression (
a ?? b). - IfStatementNode
-
An if statement, with optional pattern matching (
if (x case int y) ...). - ImportDirectiveNode
-
An import directive (
import 'foo.dart' deferred as f show a, b;). - IndexExpressionNode
-
An index expression (
a[0]ora?[0]). - IntegerLiteralNode
-
An integer literal (
42,0xCAFE). - InterpolatedStringNode
-
An interpolated string (
'hello $name'). - InvocationExpressionNode
-
An invocation expression (
foo(1, a: 2)orbar<T>()). - LabeledStatementNode
-
A labeled statement (
label: statement). - LibraryDirectiveNode
-
A library directive (
library;orlibrary foo.bar;). - ListPatternNode
-
A list pattern (
[a, b, ...rest]). -
LiteralNode<
T> - Base class for literal values.
- LogicalPatternNode
-
A logical-and or logical-or pattern (
p1 && p2,p1 || p2). - MapEntryElementNode
-
A key-value pair element in a map (
{'k': v}or{?k: ?v}). - MapPatternEntryNode
- A key-value pair in a map pattern.
- MapPatternNode
-
A map pattern (
{'k': v}). - MixinDeclarationNode
- A mixin declaration.
- NamedTypeNode
-
A named type (
int,List<String>,prefix.Class?). - NullAssertPatternNode
-
A null-assert pattern (
pattern!). - NullCheckPatternNode
-
A null-check pattern (
pattern?). - NullLiteralNode
-
A null literal (
null). - ObjectPatternNode
-
An object pattern (
Point(x: var x, y: 0)). - ParameterNode
- Base class for parameters.
- ParenthesizedExpressionNode
-
A parenthesized expression (
(expr)). - ParenthesizedPatternNode
-
A parenthesized pattern (
(pattern)). - PartDirectiveNode
-
A part directive (
part 'foo.dart';). - PartOfDirectiveNode
-
A part-of directive (
part of foo;orpart of 'foo.dart';). - PatternFieldNode
- A field within an object or record pattern.
- PatternNode
- Base class for Dart 3 patterns.
- PatternVariableDeclarationStatementNode
-
A pattern variable declaration statement (
var (a, b) = pair;). - PropertyAccessNode
-
A property access expression (
a.bora?.b). - RecordLiteralFieldNode
- A field within a record literal.
- RecordLiteralNode
-
A record literal (
(1, 2)or(a: 1, b: 2)). - RecordPatternNode
-
A record pattern (
(a, b),(name: a)). - RecordTypeFieldNode
- A field inside a record type.
- RecordTypeNode
-
A record type (
(int, String),({int a, String b})). - RedirectingConstructorInitializerNode
-
A redirecting constructor call in an initializer list (
this(...)orthis.named(...)). - RelationalPatternNode
-
A relational pattern (
> 5,<= 10). - RestPatternNode
-
A rest element in a list pattern (
...or...rest). - RethrowStatementNode
-
A rethrow statement (
rethrow;). - ReturnStatementNode
-
A return statement (
return expr;). - ShowCombinatorNode
-
A show combinator (
show a, b). - SimpleParameterNode
- A simple parameter.
- SpreadElementNode
-
A spread element in a collection (
...listor...?list). - StatementNode
- Base class for statements.
- StringLiteralNode
-
A string literal (
'hello',"world",r'raw'). - SuperConstructorInitializerNode
-
A super constructor call in an initializer list (
super(...)orsuper.named(...)). - SuperExpressionNode
-
A
superexpression. - SwitchExpressionCaseNode
-
A case in a switch expression (
pattern [when guard] => body). - SwitchExpressionNode
-
A switch expression (
switch (x) { 1 => 'a', _ => 'b' }). - SwitchPatternCaseNode
- A case group in a switch statement.
- SwitchStatementNode
- A switch statement.
- SymbolLiteralNode
-
A symbol literal (
#foo). - ThisExpressionNode
-
A
thisexpression. - ThrowExpressionNode
-
A throw expression (
throw expr). - TryStatementNode
- A try-catch-finally statement.
- TypeAliasDeclarationNode
-
A type alias declaration (
typedef Name<T> = Type;). - TypeCastExpressionNode
-
A type cast expression (
a as T). - TypeNode
- Base class for type annotations.
- TypeParameterNode
-
A generic type parameter declaration (
T extends Object). - TypeTestExpressionNode
-
A type test expression (
a is Tora is! T). - UnaryExpressionNode
-
A prefix or postfix unary expression (
-a,!b,c++,d--). - VariableDeclarationStatementNode
-
A variable declaration statement (
var x = 1;,int a, b;). - VariableDeclaratorNode
-
An individual variable declarator with an optional initializer (
name = value). - VariablePatternNode
-
A variable pattern (
var x,final int x,int x). - WhileStatementNode
- A while loop.
- WildcardPatternNode
-
A wildcard pattern (
_orint _). - YieldStatementNode
-
A yield statement (
yield expr;oryield* expr;).
Functions
-
parseDart(
String input) → CompilationUnitNode -
Parses the
inputDart source code into a CompilationUnitNode.