MCPcopy Create free account
hub / github.com/QuiltMC/chasm / Node

Class Node

chassembly/src/main/java/org/quiltmc/chasm/lang/api/ast/Node.java:19–67  ·  view source on GitHub ↗

The base class used to represent Nodes in the abstract syntax tree. This class can be extended by an execution environment if it requires special behaviour for custom nodes.

Source from the content-addressed store, hash-verified

17 * This class can be extended by an execution environment if it requires special behaviour for custom nodes.
18 */
19public abstract class Node {
20 private final Metadata metadata = new Metadata();
21
22 @ApiStatus.OverrideOnly
23 public abstract void resolve(Resolver resolver);
24
25 public abstract Node evaluate(Evaluator evaluator);
26
27 public abstract void render(Renderer renderer, StringBuilder builder, int currentIndentationMultiplier);
28
29 public Metadata getMetadata() {
30 return metadata;
31 }
32
33 /**
34 * Parse a given file into a {@link Node}.
35 *
36 * @param path Path to a valid source file containing a single node.
37 * @return The node parsed from the given source file.
38 * @throws IOException If there is an error reading the file.
39 * @throws ParseException If the source contains syntax errors.
40 */
41 public static Node parse(Path path) throws IOException {
42 Parser parser = new Parser(path);
43 return parser.file();
44 }
45
46 /**
47 * Parse a given {@link String} into a {@link Node}.
48 *
49 * @param string A string containing a single node.
50 * @return The node parsed from the given source file.
51 * @throws ParseException If the source contains syntax errors.
52 */
53 public static Node parse(String string) {
54 Parser parser = new Parser(string);
55 return parser.file();
56 }
57
58 /**
59 * Writes this node to a file.
60 */
61 public void write(Path path) throws IOException {
62 Renderer renderer = Renderer.builder().build();
63 StringBuilder sb = new StringBuilder();
64 render(renderer, sb, 1);
65 Files.write(path, sb.toString().getBytes()); // what about utf16 support?
66 }
67}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected