source_parser 1.1.2

A project for parsing existing Dart code. You can then modify this parsed structure to modify any Dart source code.

Examples

Using the Parser object lets you parse either a string or a file (sync or async). Here is an example of each: These examples can also be seen in the example.dart script.

File async:

import 'package:source_parser/dart_parser.dart';

void main() async {
  Parser parser = Parser();
  await parser.parse('example.dart');
  print (parser);
}

File sync:

import 'package:source_parser/dart_parser.dart';

void main() {
  Parser parser = Parser()..parseSync('example.dart');
  print (parser);
}

String (always sync):

import 'package:source_parser/dart_parser.dart';

void main() {
  Parser parser = Parser()..parseStr('class Test {}');
  print (parser);
}