mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-23 12:49:40 +00:00
Add related classes
This commit is contained in:
parent
2e9a299851
commit
bbb86b44f0
60
js/src/core/directives.js
Normal file
60
js/src/core/directives.js
Normal file
@ -0,0 +1,60 @@
|
||||
/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
(the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
function Directives(start_block_pattern, end_block_pattern) {
|
||||
var directives_block_pattern = new RegExp(start_block_pattern.source + / beautify( \w+[:]\w+)+ /.source + end_block_pattern.source, 'g');
|
||||
var directive_pattern = / (\w+)[:](\w+)/g;
|
||||
|
||||
var directives_end_ignore_pattern = new RegExp('(?:[\\s\\S]*?)((?:' + start_block_pattern.source + '\\sbeautify\\signore:end\\s' + end_block_pattern.source + ')|$)', 'g');
|
||||
|
||||
this.get_directives = function(text) {
|
||||
if (!text.match(directives_block_pattern)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var directives = {};
|
||||
directive_pattern.lastIndex = 0;
|
||||
var directive_match = directive_pattern.exec(text);
|
||||
|
||||
while (directive_match) {
|
||||
directives[directive_match[1]] = directive_match[2];
|
||||
directive_match = directive_pattern.exec(text);
|
||||
}
|
||||
|
||||
return directives;
|
||||
};
|
||||
|
||||
this.readIgnored = function(input) {
|
||||
return input.readWhile(directives_end_ignore_pattern);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
module.exports.Directives = Directives;
|
72
js/src/core/tokenstream.js
Normal file
72
js/src/core/tokenstream.js
Normal file
@ -0,0 +1,72 @@
|
||||
/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
(the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
function TokenStream(parent_token) {
|
||||
// private
|
||||
this._tokens = [];
|
||||
this._tokens_length = this._tokens.length;
|
||||
this._position = 0;
|
||||
this._parent_token = parent_token;
|
||||
|
||||
this.restart = function() {
|
||||
this._position = 0;
|
||||
};
|
||||
|
||||
this.hasNext = function() {
|
||||
return this._position < this._tokens_length;
|
||||
};
|
||||
|
||||
this.next = function() {
|
||||
var val = null;
|
||||
if (this.hasNext()) {
|
||||
val = this._tokens[this._position];
|
||||
this._position += 1;
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
this.peek = function(index) {
|
||||
var val = null;
|
||||
index = index || 0;
|
||||
index += this._position;
|
||||
if (index >= 0 && index < this._tokens_length) {
|
||||
val = this._tokens[index];
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
this.add = function(token) {
|
||||
if (this._parent_token) {
|
||||
token.parent = this._parent_token;
|
||||
}
|
||||
this._tokens.push(token);
|
||||
this._tokens_length += 1;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.TokenStream = TokenStream;
|
27
js/src/css/tokenizer.js
Normal file
27
js/src/css/tokenizer.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
(the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
27
js/src/html/tokenizer.js
Normal file
27
js/src/html/tokenizer.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
(the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
Loading…
Reference in New Issue
Block a user