source_parser 1.0.6 source_parser: ^1.0.6 copied to clipboard
A project for parsing existing Dart code. You can then modify this parsed structure to modify any Dart source code.
import 'package:source_parser/source_parser.dart';
void main() async {
print ('First parse example:');
print ('-------------------------');
parse_string();
print ('-------------------------\n');
print ('Second parse example:');
print ('-------------------------');
parse_file_sync();
print ('-------------------------\n');
print ('Third parse example:');
print ('-------------------------');
await parse_file_async();
print ('-------------------------\n');
}
// This parses this example file asynchronously and prints the parsed string (syntactically the same)
Future<void> parse_file_async() async {
Parser parser = Parser();
await parser.parse('example.dart');
print (parser.toString().trim());
}
// This parses this example file sychronously and prints the parsed string (syntactically the same)
void parse_file_sync() {
Parser parser = Parser()..parseSync('example.dart');
print (parser.toString().trim());
}
// This parses a string sychronously and prints the parsed string (syntactically the same)
void parse_string() {
Parser parser = Parser()..parseStr('class Test {}');
print (parser.toString().trim());
}