-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathast-parse.js.html
181 lines (165 loc) · 5.13 KB
/
ast-parse.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.3.0-beta1">
<meta charset="utf-8">
<title>jetson 0.0.3 » Source: ast-parse.js</title>
<link rel="stylesheet" href="//brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="//brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="//brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">jetson 0.<wbr>0.<wbr>3</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: ast-parse.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>"use strict";
/**
* Takes in an array of nodes and applies methods onto them
*/
function ASTParse(formatNodes) {
this.formatNodes = formatNodes;
}
module.exports = ASTParse;
ASTParse.prototype.produce = function () {
var nextNode;
this.skipWhiteSpace();
while (nextNode = this.getNextNode()) {
switch (nextNode.nodeType) {
case "object":
return this.parseObject(nextNode);
break;
case "array":
return this.parseArray(nextNode);
break;
case "null":
case "true":
case "false":
case "number":
case "string":
case "template-string":
return nextNode.value;
break;
default:
throw "Found an unknown node";
}
}
this.skipWhiteSpace();
};
/**
* Return the next node to be parsed
*/
ASTParse.prototype.checkNextNode = function () {
return this.formatNodes[0];
};
/**
* Skips over passed nodeTypes
*/
ASTParse.prototype.skipNodeTypes = function (nodeTypes) {
var test = true;
while (test) {
var nextNode = this.checkNextNode();
if (nextNode &amp;&amp; nodeTypes.indexOf(nextNode.nodeType) !== -1) {
this.getNextNode();
} else {
test = false;
break;
}
}
};
ASTParse.prototype.skipWhiteSpace = function () {
this.skipNodeTypes(["whitespace", "multiline-comment"]);
};
ASTParse.prototype.parseObject = function () {
var nextNode;
var colon;
var objectOutput = {};
this.skipWhiteSpace();
while (nextNode = this.getNextNode()) {
if (nextNode.nodeType === "object" &amp;&amp; nextNode.type === "end") {
return objectOutput;
}
this.ignoreArraySeperator();
if (nextNode.nodeType !== "string") {
throw "Key of object needs to be a string";
}
this.skipWhiteSpace();
colon = this.getNextNode();
if (colon.nodeType !== "colon") {
throw "Colon was expected";
}
this.skipWhiteSpace();
objectOutput[nextNode.value] = this.parseValue();
this.ignoreArraySeperator();
}
};
ASTParse.prototype.parseValue = function () {
this.skipWhiteSpace();
var value = this.produce();
this.skipWhiteSpace();
return value;
};
ASTParse.prototype.ignoreObjectSeperator = function () {
this.skipNodeTypes(["whitespace", "comma", "multiline-comment"]);
};
ASTParse.prototype.ignoreArraySeperator = function () {
this.skipNodeTypes(["whitespace", "comma", "multiline-comment"]);
};
ASTParse.prototype.parseArray = function () {
var nextNode;
var arrayOutput = [];
this.skipWhiteSpace();
while (nextNode = this.checkNextNode()) {
if (nextNode.nodeType === "array" &amp;&amp; nextNode.type === "end") {
this.getNextNode();
return arrayOutput;
}
this.ignoreArraySeperator();
arrayOutput.push(this.parseValue());
this.ignoreArraySeperator();
}
return arrayOutput;
};
/**
* Fetch next node and return it
* The method is here in case we ever need to go backwards and not just shift
*/
ASTParse.prototype.getNextNode = function () {
return this.formatNodes.shift();
};</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.3.0-beta1 on February 14, 2015.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.cookie.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>