ngast 2.1.4 copy "ngast: ^2.1.4" to clipboard
ngast: ^2.1.4 copied to clipboard

Parser and utilities for AngularDart templates

ngast #

Pub Package Build Status Gitter

Parser and utilities for AngularDart templates.

Usage #

Currently in development and not stable.

import 'package:ngast/ngast.dart';

main() {
  // Create an AST tree by parsing an AngularDart template.
  var tree = parse('<button [title]="someTitle">Hello</button>');

  // Print to console.
  print(tree);

  // Output:
  // [
  //    ElementAst <button> {
  //      properties=
  //        PropertyAst {
  //          title="ExpressionAst {someTitle}"}
  //          childNodes=TextAst {Hello}
  //      }
  //    }
  // ]
}

Additional flags can be passed to change the behavior of the parser:

Data type Name Description Default Value
String sourceUrl String describing the path of the HTML string.
bool desugar Enabled desugaring of banana-syntax, star syntax, and pipes. true
bool parseExpressions Parses Dart expressions raises exceptions if occurred. true
ExceptionHandler exceptionHandler Switch to 'new RecoveringExceptionHandler()' to enable error recovery. ThrowingExceptionHandler

When using RecoveringExceptionHandler, the accumulated exceptions can be accessed through the RecoveringExceptionHandler object. Refer to the following example:

void parse(String content, String sourceUrl) {
  var exceptionHandler = new RecoveringExceptionHandler();
  var asts = parse(
    content,
    sourceUrl: sourceUrl,
    desugar: false,
    parseExpressions: false,
    exceptionHandler: exceptionHandler,
  );
  for (AngularParserException e in exceptionHandler.exceptions) {
    // Do something with exception.
  }
}
2
likes
130
points
4.58k
downloads

Publisher

verified publisherangulardart.xyz

Weekly Downloads

Parser and utilities for AngularDart templates

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

charcode, collection, meta, source_span, string_scanner

More

Packages that depend on ngast