You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
818 B
32 lines
818 B
// 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); |
|
};
|
|
|