source_parser 1.1.2

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:

dependencies:
  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 LICENSE.md 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 https://github.com/dart-lang/language/issues/381)
  • 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

example/README.md

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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
14
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Sep 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:source_parser/source_parser.dart with components: io.

Dependencies

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