-
Notifications
You must be signed in to change notification settings - Fork 12
/
parse.js
32 lines (28 loc) · 818 Bytes
/
parse.js
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
// Parse patterns in string form into the form we use for interpreting
// (and later, for compiling).
'use strict';
var ast = require('./pattern');
var parser = require('./parser');
function parse_pattern(string) {
var segments = parser.parse(string);
for (var i=0, len = segments.length; i < len; i++) {
var s = segments[i];
if (s.string != undefined) {
segments[i] = ast.string(s.string);
}
else if (s.value != undefined) {
segments[i] = ast.value(s.value, s.size, s.specifiers);
}
else if (s.name != undefined) {
segments[i] = ast.variable(s.name, s.size, s.specifiers);
}
else {
throw "Unknown segment " + s;
}
}
return segments;
}
module.exports.parse = function() {
var str = [].join.call(arguments, ',');
return parse_pattern(str);
};