source_parser 1.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

source_parser #

This is an API designed to parse dart code and generate an intuitive tree for editing dart source code directly. It will open a text file (typically a .dart file) and parse it according to the dart grammar (v2.2).

NOTE: The format the parser outputs is syntactically the same as as any code parsed, but it will almost certainly change the format. It is not recommended to use this this parser to overwrite any files you may have written by hand (it will remove all comments).

Getting Started #

The project is written in Dart, and can be imported as a standard Dart library. Thus, simply add it to your pubspec.yaml like so:

  source_parser: ^1.1.2

Then import it into whatever code you are using by importing:

import 'package:source_parser/source_parser.dart';

Prerequisites #

The only prerequisite should be Dart version >=2.2.0

License #

This project is licensed under the BSD 3-Clause "New" or "Revised" License - see the file for details

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog.

[1.1.2] - 2019-07-08

Changed #

  • Made tests a dev_dependancy
  • Formatted code

[1.1.1] - 2019-07-08

Changed #

  • Exposed the new elements class as part of the library

[1.1.0] - 2019-07-08

NOTE: This update will break code if you are accessing map, set, or list literals due to grammar changes with Dart v2.3 (see here)

Added #

  • Elements class (plus dependencies) for set and map literals

Changed #

  • Updated the grammar to reflect the changes in Dart v2.3 (see here)
  • Fixed bug where constructor invocations caused an exception
  • Small format changes from health suggestions
  • Removed illegal test cases for list literal
  • Updated pubspec dependency versions
  • Updated KNOWN_ERRORS.txt
  • Updated the README

[1.0.6] - 2019-06-24

Changed #

  • Updated Homepage link to GitHub repository in pubspec.yaml
  • Applied dartfmt to remaining classes

[1.0.5] - 2019-06-24

Changed #

  • Fixed bug with AssignableExpression and increment operators (see
  • Removed test cases from arguments, expressions, primary, and selectors that were not actually allowed in dart lang
  • Applied dartdoc style to comments
  • Applied dartfmt to all classes
  • Updated KNOWN_ERRORS.txt
  • Updated the README

[1.0.4] - 2019-06-13

Changed #

  • Made the main source_parser.dart script export generic ParserType and exceptions
  • Updated the README

[1.0.3] - 2019-06-06

Changed #

  • Made the main source_parser.dart script export all necessary scripts
  • Fixed bug with FunctionSignature being declared in two separate places

[1.0.2] - 2019-06-06

Added #

  • examples folder containing a basic example using the parser

Changed #

  • Made many style changes to improve pub score

[1.0.1] - 2019-06-06

Changed #

  • Made naming changes to match the changes necessary for the package to be uploaded

Removed #

  • Removed outdated example code

[1.0.0] - 2019-06-06

Added #

  • The first initial commit containing required code for parsing


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);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  source_parser: ^1.1.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:source_parser/source_parser.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 25, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
validators ^2.0.0 2.0.0+1
Dev dependencies
pedantic ^1.8.0+1
test ^1.6.3