jqueryplugingen 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +0 -156
- data/README.rdoc +15 -6
- data/jQuery-Plugin-Generator.tmproj +243 -46
- data/lib/jquery_plugin_gen/support/bundles.rake +2 -13
- data/lib/jquery_plugin_gen.rb +1 -1
- metadata +2 -158
- data/bundles/JavaScript jQuery.tmbundle/Commands/Documentation for Word : Selection.tmCommand +0 -68
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$ (Select DOM Element).tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$(this).tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_ajax(hash).tmSnippet +0 -28
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_ajaxError.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_ajaxSend.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_ajaxSetup.tmSnippet +0 -28
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_ajaxSuccess.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_get.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_getIfModified.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_getJSON.tmSnippet +0 -21
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_getScript.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_post.tmSnippet +0 -23
- data/bundles/JavaScript jQuery.tmbundle/Snippets/$_trim.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:checked.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:contains('test').tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:disabled.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:empty.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:enabled.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:eq(n).tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:even.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:first-child.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:first-of-type.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:first.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:gt(n).tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:hidden.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:last-child.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:last-of-type.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:last.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:lt(n).tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:not(s).tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:nth-child(n).tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:nth-last-child(n).tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:nth-of-type(n).tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:odd.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:only-child.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:only-of-type.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:parent.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:root.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/:visible.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/add.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/addClass.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/after.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/ajaxStart.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/ajaxStop.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/animate.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/append.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/appendTo.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/attr(hash).tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/attr.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/before.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/bind.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/blur.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/change.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/children.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/click.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/clone.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/contains.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/css(hash).tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/css.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/dblclick.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/each.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/end.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/error.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/fadeIn - with callback.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/fadeIn.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/fadeOut - with callback.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/fadeOut.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/fadeTo - with callback.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/fadeTo.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/filter.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/find.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/focus.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/get.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/height.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/hide - with callback.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/hide.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/hover.tmSnippet +0 -20
- data/bundles/JavaScript jQuery.tmbundle/Snippets/html.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/insertAfter.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/insertBefore.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/is.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/load (AHAH).tmSnippet +0 -21
- data/bundles/JavaScript jQuery.tmbundle/Snippets/load.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/loadIfModified.tmSnippet +0 -21
- data/bundles/JavaScript jQuery.tmbundle/Snippets/mousedown.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/mousemove.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/mouseout.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/mouseover.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/mouseup.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/next.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/not.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/one.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/parent.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/parents.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/prepend.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/prependTo.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/prev.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/ready.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/remove.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/removeAttr.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/removeClass.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/reset.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/resize.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/scroll.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/select.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/show - with callback.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/show.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/siblings.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/size.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/slideDown - with callback.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/slideDown.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/slideToggle.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/slideUp - with callback.tmSnippet +0 -19
- data/bundles/JavaScript jQuery.tmbundle/Snippets/slideUp.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/submit.tmSnippet +0 -18
- data/bundles/JavaScript jQuery.tmbundle/Snippets/text.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/toggle (show:hide).tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/toggle.tmSnippet +0 -21
- data/bundles/JavaScript jQuery.tmbundle/Snippets/toggleClass.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/trigger.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/unbind.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/val.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/width.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Snippets/wrap.tmSnippet +0 -16
- data/bundles/JavaScript jQuery.tmbundle/Syntaxes/jQuery (JavaScript).tmLanguage +0 -440
- data/bundles/JavaScript jQuery.tmbundle/info.plist +0 -387
- data/bundles/JavaScript.tmbundle/Commands/Copy as Bookmarklet to Clipboard.tmCommand +0 -54
- data/bundles/JavaScript.tmbundle/Commands/Documentation for Word.plist +0 -30
- data/bundles/JavaScript.tmbundle/Commands/New Function.tmCommand +0 -28
- data/bundles/JavaScript.tmbundle/Commands/New Method.tmCommand +0 -28
- data/bundles/JavaScript.tmbundle/Commands/Reformat Document : Selection.tmCommand +0 -50
- data/bundles/JavaScript.tmbundle/Preferences/Comments.tmPreferences +0 -36
- data/bundles/JavaScript.tmbundle/Preferences/JavaScript Indent.tmPreferences +0 -19
- data/bundles/JavaScript.tmbundle/Preferences/Symbol List Banned.tmPreferences +0 -17
- data/bundles/JavaScript.tmbundle/Preferences/Symbol List Class.tmPreferences +0 -21
- data/bundles/JavaScript.tmbundle/Preferences/Symbol List Instance.tmPreferences +0 -21
- data/bundles/JavaScript.tmbundle/Preferences/Symbol List Sub 1.tmPreferences +0 -21
- data/bundles/JavaScript.tmbundle/Preferences/Symbol List Sub 2.tmPreferences +0 -21
- data/bundles/JavaScript.tmbundle/Snippets/Get Elements.tmSnippet +0 -16
- data/bundles/JavaScript.tmbundle/Snippets/Object Method String.tmSnippet +0 -18
- data/bundles/JavaScript.tmbundle/Snippets/Object Method.tmSnippet +0 -18
- data/bundles/JavaScript.tmbundle/Snippets/Object Value JS.tmSnippet +0 -16
- data/bundles/JavaScript.tmbundle/Snippets/Object key /342/200/224 key: /"value/".tmSnippet" +0 -18
- data/bundles/JavaScript.tmbundle/Snippets/Prototype (proto).plist +0 -19
- data/bundles/JavaScript.tmbundle/Snippets/for (/342/200/246) {/342/200/246} (faster).tmSnippet" +0 -18
- data/bundles/JavaScript.tmbundle/Snippets/for (/342/200/246) {/342/200/246}.tmSnippet" +0 -18
- data/bundles/JavaScript.tmbundle/Snippets/function (fun).plist +0 -18
- data/bundles/JavaScript.tmbundle/Snippets/function.tmSnippet +0 -16
- data/bundles/JavaScript.tmbundle/Snippets/if ___ else.tmSnippet +0 -16
- data/bundles/JavaScript.tmbundle/Snippets/if.tmSnippet +0 -16
- data/bundles/JavaScript.tmbundle/Snippets/setTimeout function.tmSnippet +0 -16
- data/bundles/JavaScript.tmbundle/Support/dev_guru_index.gz +0 -0
- data/bundles/JavaScript.tmbundle/Support/lib/beautify.php +0 -557
- data/bundles/JavaScript.tmbundle/Syntaxes/JavaScript.plist +0 -712
- data/bundles/JavaScript.tmbundle/info.plist +0 -136
@@ -1,557 +0,0 @@
|
|
1
|
-
<?php // $Id: beautify.php 41 2008-02-19 04:55:10Z einars $
|
2
|
-
|
3
|
-
/*
|
4
|
-
|
5
|
-
JS Beautifier
|
6
|
-
|
7
|
-
(c) 2007, Einars "elfz" Lielmanis
|
8
|
-
|
9
|
-
http://elfz.laacz.lv/beautify/
|
10
|
-
|
11
|
-
|
12
|
-
You are free to use this in any way you want, in case you find this useful or working for you.
|
13
|
-
|
14
|
-
Usage:
|
15
|
-
require('beautify.php');
|
16
|
-
echo js_beautify($js_source_text);
|
17
|
-
|
18
|
-
*/
|
19
|
-
|
20
|
-
error_reporting(E_ALL);
|
21
|
-
ini_set('display_errors', 'on');
|
22
|
-
|
23
|
-
|
24
|
-
$n = 1;
|
25
|
-
define('IN_EXPR', ++$n);
|
26
|
-
define('IN_BLOCK', ++$n);
|
27
|
-
|
28
|
-
|
29
|
-
define('TK_UNKNOWN', ++$n);
|
30
|
-
define('TK_WORD', ++$n);
|
31
|
-
define('TK_START_EXPR', ++$n);
|
32
|
-
define('TK_END_EXPR', ++$n);
|
33
|
-
define('TK_START_BLOCK', ++$n);
|
34
|
-
define('TK_END_BLOCK', ++$n);
|
35
|
-
define('TK_END_COMMAND', ++$n);
|
36
|
-
define('TK_EOF', ++$n);
|
37
|
-
define('TK_STRING', ++$n);
|
38
|
-
|
39
|
-
define('TK_BLOCK_COMMENT', ++$n);
|
40
|
-
define('TK_COMMENT', ++$n);
|
41
|
-
|
42
|
-
define('TK_OPERATOR', ++$n);
|
43
|
-
|
44
|
-
// internal flags
|
45
|
-
define('PRINT_NONE', ++$n);
|
46
|
-
define('PRINT_SPACE', ++$n);
|
47
|
-
define('PRINT_NL', ++$n);
|
48
|
-
|
49
|
-
|
50
|
-
function js_beautify($js_source_text, $tab_size = 4)
|
51
|
-
{
|
52
|
-
global $output, $token_text, $last_type, $last_text, $in, $ins, $indent, $tab_string;
|
53
|
-
|
54
|
-
global $input, $input_length;
|
55
|
-
|
56
|
-
$tab_string = str_repeat(' ', $tab_size);
|
57
|
-
|
58
|
-
$input = $js_source_text;
|
59
|
-
$input_length = strlen($input);
|
60
|
-
|
61
|
-
$last_word = ''; // last TK_WORD passed
|
62
|
-
$last_type = TK_START_EXPR; // last token type
|
63
|
-
$last_text = ''; // last token text
|
64
|
-
$output = '';
|
65
|
-
|
66
|
-
// words which should always start on new line.
|
67
|
-
// simple hack for cases when lines aren't ending with semicolon.
|
68
|
-
// feel free to tell me about the ones that need to be added.
|
69
|
-
$line_starters = explode(',', 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function');
|
70
|
-
|
71
|
-
// states showing if we are currently in expression (i.e. "if" case) - IN_EXPR, or in usual block (like, procedure), IN_BLOCK.
|
72
|
-
// some formatting depends on that.
|
73
|
-
$in = IN_BLOCK;
|
74
|
-
$ins = array($in);
|
75
|
-
|
76
|
-
|
77
|
-
$indent = 0;
|
78
|
-
$pos = 0; // parser position
|
79
|
-
$in_case = false; // flag for parser that case/default has been processed, and next colon needs special attention
|
80
|
-
|
81
|
-
while (true) {
|
82
|
-
list($token_text, $token_type) = get_next_token($pos);
|
83
|
-
if ($token_type == TK_EOF) {
|
84
|
-
break;
|
85
|
-
}
|
86
|
-
|
87
|
-
// $output .= " [$token_type:$last_type]";
|
88
|
-
|
89
|
-
switch($token_type) {
|
90
|
-
|
91
|
-
case TK_START_EXPR:
|
92
|
-
|
93
|
-
in(IN_EXPR);
|
94
|
-
if ($last_type == TK_END_EXPR or $last_type == TK_START_EXPR) {
|
95
|
-
// do nothing on (( and )( and ][ and ]( ..
|
96
|
-
} elseif ($last_type != TK_WORD and $last_type != TK_OPERATOR) {
|
97
|
-
space();
|
98
|
-
} elseif (in_array($last_word, $line_starters) and $last_word != 'function') {
|
99
|
-
space();
|
100
|
-
}
|
101
|
-
token();
|
102
|
-
break;
|
103
|
-
|
104
|
-
case TK_END_EXPR:
|
105
|
-
|
106
|
-
token();
|
107
|
-
in_pop();
|
108
|
-
break;
|
109
|
-
|
110
|
-
case TK_START_BLOCK:
|
111
|
-
|
112
|
-
in(IN_BLOCK);
|
113
|
-
if ($last_type != TK_OPERATOR and $last_type != TK_START_EXPR) {
|
114
|
-
if ($last_type == TK_START_BLOCK) {
|
115
|
-
nl();
|
116
|
-
} else {
|
117
|
-
space();
|
118
|
-
}
|
119
|
-
}
|
120
|
-
token();
|
121
|
-
indent();
|
122
|
-
break;
|
123
|
-
|
124
|
-
case TK_END_BLOCK:
|
125
|
-
|
126
|
-
if ($last_type == TK_END_EXPR) {
|
127
|
-
unindent();
|
128
|
-
nl();
|
129
|
-
} elseif ($last_type == TK_END_BLOCK) {
|
130
|
-
unindent();
|
131
|
-
nl();
|
132
|
-
} elseif ($last_type == TK_START_BLOCK) {
|
133
|
-
// nothing
|
134
|
-
unindent();
|
135
|
-
} else {
|
136
|
-
unindent();
|
137
|
-
nl();
|
138
|
-
}
|
139
|
-
token();
|
140
|
-
in_pop();
|
141
|
-
break;
|
142
|
-
|
143
|
-
case TK_WORD:
|
144
|
-
|
145
|
-
if ($token_text == 'case' or $token_text == 'default') {
|
146
|
-
if ($last_text == ':') {
|
147
|
-
// switch cases following one another
|
148
|
-
remove_indent();
|
149
|
-
} else {
|
150
|
-
$indent--;
|
151
|
-
nl();
|
152
|
-
$indent++;
|
153
|
-
}
|
154
|
-
token();
|
155
|
-
$in_case = true;
|
156
|
-
break;
|
157
|
-
}
|
158
|
-
|
159
|
-
$prefix = PRINT_NONE;
|
160
|
-
if ($last_type == TK_END_BLOCK) {
|
161
|
-
if (!in_array($token_text, array('else', 'catch', 'finally'))) {
|
162
|
-
$prefix = PRINT_NL;
|
163
|
-
} else {
|
164
|
-
$prefix = PRINT_SPACE;
|
165
|
-
space();
|
166
|
-
}
|
167
|
-
} elseif ($last_type == TK_END_COMMAND && $in == IN_BLOCK) {
|
168
|
-
$prefix = PRINT_NL;
|
169
|
-
} elseif ($last_type == TK_END_COMMAND && $in == IN_EXPR) {
|
170
|
-
$prefix = PRINT_SPACE;
|
171
|
-
} elseif ($last_type == TK_WORD) {
|
172
|
-
if ($last_word == 'else') { // else if
|
173
|
-
$prefix = PRINT_SPACE;
|
174
|
-
} else {
|
175
|
-
$prefix = PRINT_SPACE;
|
176
|
-
}
|
177
|
-
} elseif ($last_type == TK_START_BLOCK) {
|
178
|
-
$prefix = PRINT_NL;
|
179
|
-
} elseif ($last_type == TK_END_EXPR) {
|
180
|
-
space();
|
181
|
-
}
|
182
|
-
|
183
|
-
if (in_array($token_text, $line_starters) or $prefix == PRINT_NL) {
|
184
|
-
|
185
|
-
if ($last_text == 'else') {
|
186
|
-
// no need to force newline on else break
|
187
|
-
// DONOTHING
|
188
|
-
space();
|
189
|
-
} elseif (($last_type == TK_START_EXPR or $last_text == '=') and $token_text == 'function') {
|
190
|
-
// no need to force newline on 'function': (function
|
191
|
-
// DONOTHING
|
192
|
-
} elseif ($last_type == TK_WORD and ($last_text == 'return' or $last_text == 'throw')) {
|
193
|
-
// no newline between 'return nnn'
|
194
|
-
space();
|
195
|
-
} else
|
196
|
-
if ($last_type != TK_END_EXPR) {
|
197
|
-
if (($last_type != TK_START_EXPR or $token_text != 'var') and $last_text != ':') {
|
198
|
-
// no need to force newline on 'var': for (var x = 0...)
|
199
|
-
if ($token_text == 'if' and $last_type == TK_WORD and $last_word == 'else') {
|
200
|
-
// no newline for } else if {
|
201
|
-
space();
|
202
|
-
} else {
|
203
|
-
nl();
|
204
|
-
}
|
205
|
-
}
|
206
|
-
}
|
207
|
-
} elseif ($prefix == PRINT_SPACE) {
|
208
|
-
space();
|
209
|
-
}
|
210
|
-
token();
|
211
|
-
$last_word = $token_text;
|
212
|
-
break;
|
213
|
-
|
214
|
-
case TK_END_COMMAND:
|
215
|
-
|
216
|
-
token();
|
217
|
-
break;
|
218
|
-
|
219
|
-
case TK_STRING:
|
220
|
-
|
221
|
-
if ($last_type == TK_START_BLOCK or $last_type == TK_END_BLOCK) {
|
222
|
-
nl();
|
223
|
-
} elseif ($last_type == TK_WORD) {
|
224
|
-
space();
|
225
|
-
}
|
226
|
-
token();
|
227
|
-
break;
|
228
|
-
|
229
|
-
case TK_OPERATOR:
|
230
|
-
$start_delim = true;
|
231
|
-
$end_delim = true;
|
232
|
-
|
233
|
-
if ($token_text == ':' and $in_case) {
|
234
|
-
token(); // colon really asks for separate treatment
|
235
|
-
nl();
|
236
|
-
$expecting_case = false;
|
237
|
-
break;
|
238
|
-
}
|
239
|
-
|
240
|
-
$in_case = false;
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
if ($token_text == ',') {
|
245
|
-
if ($last_type == TK_END_BLOCK) {
|
246
|
-
token();
|
247
|
-
nl();
|
248
|
-
} else {
|
249
|
-
if ($in == IN_BLOCK) {
|
250
|
-
token();
|
251
|
-
nl();
|
252
|
-
} else {
|
253
|
-
token();
|
254
|
-
space();
|
255
|
-
}
|
256
|
-
}
|
257
|
-
break;
|
258
|
-
} elseif ($token_text == '--' or $token_text == '++') { // unary operators special case
|
259
|
-
if ($last_text == ';') {
|
260
|
-
// space for (;; ++i)
|
261
|
-
$start_delim = true;
|
262
|
-
$end_delim = false;
|
263
|
-
} else {
|
264
|
-
$start_delim = false;
|
265
|
-
$end_delim = false;
|
266
|
-
}
|
267
|
-
} elseif ($token_text == '!' and $last_type == TK_START_EXPR) {
|
268
|
-
// special case handling: if (!a)
|
269
|
-
$start_delim = false;
|
270
|
-
$end_delim = false;
|
271
|
-
} elseif ($last_type == TK_OPERATOR) {
|
272
|
-
$start_delim = false;
|
273
|
-
$end_delim = false;
|
274
|
-
} elseif ($last_type == TK_END_EXPR) {
|
275
|
-
$start_delim = true;
|
276
|
-
$end_delim = true;
|
277
|
-
} elseif ($token_text == '.') {
|
278
|
-
// decimal digits or object.property
|
279
|
-
$start_delim = false;
|
280
|
-
$end_delim = false;
|
281
|
-
|
282
|
-
} elseif ($token_text == ':') {
|
283
|
-
// zz: xx
|
284
|
-
// can't differentiate ternary op, so for now it's a ? b: c; without space before colon
|
285
|
-
$start_delim = false;
|
286
|
-
}
|
287
|
-
if ($start_delim) {
|
288
|
-
space();
|
289
|
-
}
|
290
|
-
|
291
|
-
token();
|
292
|
-
|
293
|
-
if ($end_delim) {
|
294
|
-
space();
|
295
|
-
}
|
296
|
-
break;
|
297
|
-
|
298
|
-
case TK_BLOCK_COMMENT:
|
299
|
-
|
300
|
-
nl();
|
301
|
-
token();
|
302
|
-
nl();
|
303
|
-
break;
|
304
|
-
|
305
|
-
case TK_COMMENT:
|
306
|
-
|
307
|
-
//if ($last_type != TK_COMMENT) {
|
308
|
-
nl();
|
309
|
-
//}
|
310
|
-
token();
|
311
|
-
nl();
|
312
|
-
break;
|
313
|
-
|
314
|
-
case TK_UNKNOWN:
|
315
|
-
token();
|
316
|
-
break;
|
317
|
-
}
|
318
|
-
|
319
|
-
if ($token_type != TK_COMMENT) {
|
320
|
-
$last_type = $token_type;
|
321
|
-
$last_text = $token_text;
|
322
|
-
}
|
323
|
-
}
|
324
|
-
|
325
|
-
// clean empty lines from redundant spaces
|
326
|
-
$output = preg_replace('/^ +$/m', '', $output);
|
327
|
-
|
328
|
-
return $output;
|
329
|
-
}
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
function nl($ignore_repeated = true)
|
335
|
-
{
|
336
|
-
global $indent, $output, $tab_string;
|
337
|
-
|
338
|
-
$output = rtrim($output, ' '); // remove possible indent
|
339
|
-
|
340
|
-
if ($output == '') return; // no newline on start of file
|
341
|
-
|
342
|
-
if (substr($output, -1) != "\n" or !$ignore_repeated) {
|
343
|
-
$output .= "\n";
|
344
|
-
}
|
345
|
-
$output .= str_repeat($tab_string, $indent);
|
346
|
-
}
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
function space()
|
351
|
-
{
|
352
|
-
global $output;
|
353
|
-
|
354
|
-
if ($output and substr($output, -1) != ' ') { // prevent occassional duplicate space
|
355
|
-
$output .= ' ';
|
356
|
-
}
|
357
|
-
}
|
358
|
-
|
359
|
-
|
360
|
-
function token()
|
361
|
-
{
|
362
|
-
global $token_text, $output;
|
363
|
-
$output .= $token_text;
|
364
|
-
}
|
365
|
-
|
366
|
-
function indent()
|
367
|
-
{
|
368
|
-
global $indent;
|
369
|
-
$indent ++;
|
370
|
-
}
|
371
|
-
|
372
|
-
|
373
|
-
function unindent()
|
374
|
-
{
|
375
|
-
global $indent;
|
376
|
-
if ($indent) {
|
377
|
-
$indent --;
|
378
|
-
}
|
379
|
-
}
|
380
|
-
|
381
|
-
|
382
|
-
function remove_indent()
|
383
|
-
{
|
384
|
-
global $tab_string, $output;
|
385
|
-
$tab_string_len = strlen($tab_string);
|
386
|
-
if (substr($output, -$tab_string_len) == $tab_string) {
|
387
|
-
$output = substr($output, 0, -$tab_string_len);
|
388
|
-
}
|
389
|
-
}
|
390
|
-
|
391
|
-
|
392
|
-
function in($where)
|
393
|
-
{
|
394
|
-
global $ins, $in;
|
395
|
-
array_push($ins, $in);
|
396
|
-
$in = $where;
|
397
|
-
}
|
398
|
-
|
399
|
-
|
400
|
-
function in_pop()
|
401
|
-
{
|
402
|
-
global $ins, $in;
|
403
|
-
$in = array_pop($ins);
|
404
|
-
}
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
function make_array($str)
|
409
|
-
{
|
410
|
-
$res = array();
|
411
|
-
for ($i = 0; $i < strlen($str); $i++) {
|
412
|
-
$res[] = $str[$i];
|
413
|
-
}
|
414
|
-
return $res;
|
415
|
-
}
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
function get_next_token(&$pos)
|
420
|
-
{
|
421
|
-
global $last_type, $last_text;
|
422
|
-
global $whitespace, $wordchar, $punct;
|
423
|
-
global $input, $input_length;
|
424
|
-
|
425
|
-
|
426
|
-
if (!$whitespace) $whitespace = make_array("\n\r\t ");
|
427
|
-
if (!$wordchar) $wordchar = make_array('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$');
|
428
|
-
if (!$punct) $punct = explode(' ', '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |=');
|
429
|
-
|
430
|
-
$n_newlines = 0;
|
431
|
-
do {
|
432
|
-
if ($pos >= $input_length) {
|
433
|
-
return array('', TK_EOF);
|
434
|
-
}
|
435
|
-
$c = $input[$pos];
|
436
|
-
$pos += 1;
|
437
|
-
if ($c == "\n") {
|
438
|
-
nl($n_newlines == 0);
|
439
|
-
$n_newlines += 1;
|
440
|
-
}
|
441
|
-
} while (in_array($c, $whitespace));
|
442
|
-
|
443
|
-
if (in_array($c, $wordchar)) {
|
444
|
-
if ($pos < $input_length) {
|
445
|
-
while (in_array($input[$pos], $wordchar)) {
|
446
|
-
$c .= $input[$pos];
|
447
|
-
$pos += 1;
|
448
|
-
if ($pos == $input_length) break;
|
449
|
-
}
|
450
|
-
}
|
451
|
-
|
452
|
-
// small and surprisingly unugly hack for 1E-10 representation
|
453
|
-
if ($pos != $input_length and preg_match('/^\d+[Ee]$/', $c) and $input[$pos] == '-') {
|
454
|
-
$pos += 1;
|
455
|
-
list($next_word, $next_type) = get_next_token($pos);
|
456
|
-
$c .= '-' . $next_word;
|
457
|
-
return array($c, TK_WORD);
|
458
|
-
}
|
459
|
-
|
460
|
-
if ($c == 'in') { // hack for 'in' operator
|
461
|
-
return array($c, TK_OPERATOR);
|
462
|
-
}
|
463
|
-
return array($c, TK_WORD);
|
464
|
-
}
|
465
|
-
|
466
|
-
if ($c == '(' || $c == '[') {
|
467
|
-
return array($c, TK_START_EXPR);
|
468
|
-
}
|
469
|
-
|
470
|
-
if ($c == ')' || $c == ']') {
|
471
|
-
return array($c, TK_END_EXPR);
|
472
|
-
}
|
473
|
-
|
474
|
-
if ($c == '{') {
|
475
|
-
return array($c, TK_START_BLOCK);
|
476
|
-
}
|
477
|
-
|
478
|
-
if ($c == '}') {
|
479
|
-
return array($c, TK_END_BLOCK);
|
480
|
-
}
|
481
|
-
|
482
|
-
if ($c == ';') {
|
483
|
-
return array($c, TK_END_COMMAND);
|
484
|
-
}
|
485
|
-
|
486
|
-
if ($c == '/') {
|
487
|
-
// peek for comment /* ... */
|
488
|
-
if ($input[$pos] == '*') {
|
489
|
-
$comment = '';
|
490
|
-
$pos += 1;
|
491
|
-
if ($pos < $input_length){
|
492
|
-
while (!($input[$pos] == '*' && isset($input[$pos + 1]) && $input[$pos + 1] == '/') && $pos < $input_length) {
|
493
|
-
$comment .= $input[$pos];
|
494
|
-
$pos += 1;
|
495
|
-
if ($pos >= $input_length) break;
|
496
|
-
}
|
497
|
-
}
|
498
|
-
$pos +=2;
|
499
|
-
return array("/*$comment*/", TK_BLOCK_COMMENT);
|
500
|
-
}
|
501
|
-
// peek for comment // ...
|
502
|
-
if ($input[$pos] == '/') {
|
503
|
-
$comment = $c;
|
504
|
-
while ($input[$pos] != "\x0d" && $input[$pos] != "\x0a") {
|
505
|
-
$comment .= $input[$pos];
|
506
|
-
$pos += 1;
|
507
|
-
if ($pos >= $input_length) break;
|
508
|
-
}
|
509
|
-
$pos += 1;
|
510
|
-
return array($comment, TK_COMMENT);
|
511
|
-
}
|
512
|
-
|
513
|
-
}
|
514
|
-
|
515
|
-
if ($c == "'" || // string
|
516
|
-
$c == '"' || // string
|
517
|
-
($c == '/' &&
|
518
|
-
(($last_type == TK_WORD and $last_text == 'return') or ($last_type == TK_START_EXPR || $last_type == TK_END_BLOCK || $last_type == TK_OPERATOR || $last_type == TK_EOF || $last_type == TK_END_COMMAND)))) { // regexp
|
519
|
-
$sep = $c;
|
520
|
-
$c = '';
|
521
|
-
$esc = false;
|
522
|
-
|
523
|
-
if ($pos < $input_length) {
|
524
|
-
|
525
|
-
while ($esc || $input[$pos] != $sep) {
|
526
|
-
$c .= $input[$pos];
|
527
|
-
if (!$esc) {
|
528
|
-
$esc = $input[$pos] == '\\';
|
529
|
-
} else {
|
530
|
-
$esc = false;
|
531
|
-
}
|
532
|
-
$pos += 1;
|
533
|
-
if ($pos >= $input_length) break;
|
534
|
-
}
|
535
|
-
|
536
|
-
}
|
537
|
-
|
538
|
-
$pos += 1;
|
539
|
-
if ($last_type == TK_END_COMMAND) {
|
540
|
-
nl();
|
541
|
-
}
|
542
|
-
return array($sep . $c . $sep, TK_STRING);
|
543
|
-
}
|
544
|
-
|
545
|
-
if (in_array($c, $punct)) {
|
546
|
-
while ($pos < $input_length and in_array($c . $input[$pos], $punct)) {
|
547
|
-
$c .= $input[$pos];
|
548
|
-
$pos += 1;
|
549
|
-
if ($pos >= $input_length) break;
|
550
|
-
}
|
551
|
-
return array($c, TK_OPERATOR);
|
552
|
-
}
|
553
|
-
|
554
|
-
return array($c, TK_UNKNOWN);
|
555
|
-
}
|
556
|
-
|
557
|
-
?>
|