Name |
Ceylon representation of a Ceylon Abstract Syntax Tree |
---|---|
Backends | JVM JavaScript |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) |
Published | Dec 7, 2016 |
Stats |
Downloads (JVM): 242 Downloads (JS): 112 Source downloads: 223 |
Authors |
Lucas Werkmeister <mail@lucaswerkmeister.de> |
License | http://www.apache.org/licenses/LICENSE-2.0.html |
Description |
This module defines types for a Ceylon Abstract Syntax Tree (AST), a hierarchical and immutable data structure that represents a Ceylon program. Obtaining an ASTThere are two major ways to obtain an AST: Create it yourselfYou can of course construct the AST yourself.
To reduce the amount of boilerplate code necessary, we strongly recommend
using the [[ baseExpression("null") instead of BaseExpression(MemberNameWithTypeArguments(LIdentifier("null"))) Parse itThe [[ If you have a node from the RedHat AST, you can also convert it using that module. Operating on an ASTAnalyze itYou can analyze an AST node (and its child nodes) using the variable Integer elseIfCount = 0; that.visit { object visitor satisfies Visitor { shared actual void visitElseClause(ElseClause that) { if (that.child is IfElse) { elseIfCount++; } super.visitElseClause(that); } } };
Attaching additional informationYou can also attach your analysis results to the AST nodes.
To do this, you first need to create a shared Key<Token[]> tokensKey = ScopedKey<Token[]>(`module my.parser`, "tokens"); (We recommend the use of Then, you can attach information using node.put(tokensKey, tokens) and later retrieve it with assert (exists tokens = node.get(tokensKey)); The key is typed, so you don’t lose typing information (except about the presence of the attached information). Edit itSince the AST is immutable, you can’t edit it directly.
However, you can easily obtain an edited copy using the that.transform { object transformer satisfies Editor { shared actual ElseClause transformElseClause(ElseClause that) { if (is IfElse ifElse = that.child) { return that.copy { child = Block([ifElse]); }; } else { return super.transformElseClause(that); } } } };
Consuming an ASTYou can also transform your AST into something completely different
using the A
|
Dependencies | |
Usage |
import ceylon.ast.core "1.3.1"; |
Module links |
Members Imported By Home Code repository Issue tracker Browse Download .car Download .js Download source archive Download module documentation View API documentation |