main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
954 bytes
|
Line | |
---|
1 | var Token = require('../../tokenizer/token');
|
---|
2 |
|
---|
3 | var serializeBody = require('../../writer/one-time').body;
|
---|
4 | var serializeRules = require('../../writer/one-time').rules;
|
---|
5 |
|
---|
6 | function removeDuplicates(tokens) {
|
---|
7 | var matched = {};
|
---|
8 | var moreThanOnce = [];
|
---|
9 | var id, token;
|
---|
10 | var body, bodies;
|
---|
11 |
|
---|
12 | for (var i = 0, l = tokens.length; i < l; i++) {
|
---|
13 | token = tokens[i];
|
---|
14 | if (token[0] != Token.RULE) { continue; }
|
---|
15 |
|
---|
16 | id = serializeRules(token[1]);
|
---|
17 |
|
---|
18 | if (matched[id] && matched[id].length == 1) { moreThanOnce.push(id); } else { matched[id] = matched[id] || []; }
|
---|
19 |
|
---|
20 | matched[id].push(i);
|
---|
21 | }
|
---|
22 |
|
---|
23 | for (i = 0, l = moreThanOnce.length; i < l; i++) {
|
---|
24 | id = moreThanOnce[i];
|
---|
25 | bodies = [];
|
---|
26 |
|
---|
27 | for (var j = matched[id].length - 1; j >= 0; j--) {
|
---|
28 | token = tokens[matched[id][j]];
|
---|
29 | body = serializeBody(token[2]);
|
---|
30 |
|
---|
31 | if (bodies.indexOf(body) > -1) { token[2] = []; } else { bodies.push(body); }
|
---|
32 | }
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | module.exports = removeDuplicates;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.