1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var Node = require('./node');
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var Feature = module.exports = function Feature(segs){
|
22 | Node.call(this);
|
23 | this.segments = segs;
|
24 | this.expr = null;
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | Feature.prototype.__proto__ = Node.prototype;
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | Feature.prototype.clone = function(parent){
|
41 | var clone = new Feature;
|
42 | clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); });
|
43 | if (this.expr) clone.expr = this.expr.clone(parent, clone);
|
44 | if (this.name) clone.name = this.name;
|
45 | clone.lineno = this.lineno;
|
46 | clone.column = this.column;
|
47 | clone.filename = this.filename;
|
48 | return clone;
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | Feature.prototype.toString = function(){
|
59 | if (this.expr) {
|
60 | return '(' + this.segments.join('') + ': ' + this.expr.toString() + ')';
|
61 | } else {
|
62 | return this.segments.join('');
|
63 | }
|
64 | };
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | Feature.prototype.toJSON = function(){
|
74 | var json = {
|
75 | __type: 'Feature',
|
76 | segments: this.segments,
|
77 | lineno: this.lineno,
|
78 | column: this.column,
|
79 | filename: this.filename
|
80 | };
|
81 | if (this.expr) json.expr = this.expr;
|
82 | if (this.name) json.name = this.name;
|
83 | return json;
|
84 | };
|