forked from pstodulka/swift-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swiftParser.js
87 lines (71 loc) · 2.38 KB
/
swiftParser.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
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
// Generated by CoffeeScript 1.7.1
(function() {
var FieldParser, SwiftParser, block1Parser, block2Parser, finParser, fs, main, mtParser;
fs = require('fs');
finParser = require("./finParser.js");
mtParser = require("./mtParser.js");
block1Parser = require('./block1Parser');
block2Parser = require('./block2Parser');
FieldParser = require('./FieldRegexpFactory').FieldParser;
SwiftParser = (function() {
function SwiftParser(fieldPatterns) {
this.fieldPatterns = fieldPatterns;
if (fieldPatterns == null) {
this.fieldPatterns = JSON.parse(fs.readFileSync(__dirname + '/metadata/patterns.json'));
}
this.fieldParser = new FieldParser(this.fieldPatterns);
}
SwiftParser.prototype.process = function(swiftMessage) {
var ast, field, fieldCode, parsedField, _i, _len, _ref, _ref1;
ast = finParser.parse(swiftMessage);
ast.block1 = block1Parser.parse(ast.block1.content[0]);
ast.block2 = block2Parser.parse(ast.block2.content[0]);
ast.block4.fields = mtParser.parse(ast.block4.content[0]);
_ref = ast.block4.fields;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
field = _ref[_i];
fieldCode = field.type + ((_ref1 = field.option) != null ? _ref1 : "");
parsedField = this.fieldParser.parse(fieldCode, field.fieldValue);
field.ast = parsedField;
}
return ast;
};
SwiftParser.prototype.parse = function(swiftMessage, callback) {
var ast, e;
try {
ast = this.process(swiftMessage);
return callback(null, ast);
} catch (_error) {
e = _error;
return callback(e, null);
}
};
return SwiftParser;
})();
module.exports.SwiftParser = SwiftParser;
main = function() {
var filename;
if (process.argv.length !== 3) {
console.log("Usage: node swiftParser <swift file>");
return;
}
filename = process.argv[2];
return fs.readFile(filename, "ASCII", function(err, content) {
var parser;
if ((err != null)) {
throw err;
}
parser = new SwiftParser();
return parser.parse(content, function(err, ast) {
if ((err != null)) {
throw err;
}
return console.log(JSON.stringify(ast, null, 2));
});
});
};
if (require.main === module) {
main();
}
}).call(this);
//# sourceMappingURL=swiftParser.map