All Projects → dart-archive → angular_ast

dart-archive / angular_ast

Licence: BSD-3-Clause license
DEPRECATED - development moved to share angular repo

Programming Languages

dart
5743 projects
HTML
75241 projects
shell
77523 projects

angular_ast

Parser and utilities for AngularDart templates.

This package is platform agnostic (no HTML or Dart VM dependencies).

Usage

Currently in development and not stable.

import 'package:angular_ast/angular_ast.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:

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

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.
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].