main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
783 bytes
|
Line | |
---|
1 | import { visit } from "../traversal/visitor.mjs";
|
---|
2 | class SymbolicExpressionsVisitor {
|
---|
3 | result = '';
|
---|
4 | nestingLevel = 0;
|
---|
5 | enter(element) {
|
---|
6 | const {
|
---|
7 | element: elementName
|
---|
8 | } = element;
|
---|
9 | const capitalizedElementName = elementName.charAt(0).toUpperCase() + elementName.slice(1);
|
---|
10 | const indent = ' '.repeat(this.nestingLevel);
|
---|
11 | this.result += this.nestingLevel > 0 ? '\n' : '';
|
---|
12 | this.result += `${indent}(${capitalizedElementName}Element`;
|
---|
13 | this.nestingLevel += 1;
|
---|
14 | }
|
---|
15 | leave() {
|
---|
16 | this.nestingLevel -= 1;
|
---|
17 | this.result += ')';
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | // transforms ApiDOM into S-expressions (Symbolic Expressions)
|
---|
22 | const sexprs = element => {
|
---|
23 | const visitor = new SymbolicExpressionsVisitor();
|
---|
24 | visit(element, visitor);
|
---|
25 | return visitor.result;
|
---|
26 | };
|
---|
27 | export default sexprs; |
---|
Note:
See
TracBrowser
for help on using the repository browser.