@@ -47,16 +47,14 @@ foreach ($argv as $loc => $a) {
47
47
}
48
48
}
49
49
50
- function has ($ o , &$ loc = null )
51
- {
50
+ function has ($ o , &$ loc = null ) {
52
51
global $ opts ;
53
52
if (!isset ($ opts [$ o ])) return false ;
54
53
$ loc = $ opts [$ o ];
55
54
return true ;
56
55
}
57
56
58
- function hasValue ($ o , &$ value = null )
59
- {
57
+ function hasValue ($ o , &$ value = null ) {
60
58
global $ argv ;
61
59
if (!has ($ o ,$ loc )) return false ;
62
60
if (!isset ($ argv [$ loc +1 ])) return false ;
@@ -136,9 +134,47 @@ if (!$fname = array_shift($argv)) {
136
134
exit (1 );
137
135
}
138
136
137
+ function dumpValue ($ node , $ depth = 0 ) {
138
+ if (is_object ($ node )) {
139
+ $ indent = str_repeat (" " , $ depth );
140
+ $ out = array ();
141
+ foreach ($ node ->props as $ prop ) {
142
+ $ out [] = $ indent . dumpValue ($ prop , $ depth + 1 );
143
+ }
144
+ $ out = implode ("\n" , $ out );
145
+ if (!empty ($ node ->tags )) {
146
+ $ out = "+ " .implode (", " , $ node ->tags )."\n" .$ out ;
147
+ }
148
+ return $ out ;
149
+ } elseif (is_array ($ node )) {
150
+ $ type = $ node [0 ];
151
+ if ($ type == "block " )
152
+ return dumpValue ($ node [1 ], $ depth );
153
+
154
+ $ out = array ();
155
+ foreach ($ node as $ value ) {
156
+ $ out [] = dumpValue ($ value , $ depth );
157
+ }
158
+ return "{ " .implode (", " , $ out )." } " ;
159
+ } else {
160
+ if (is_string ($ node ) && preg_match ("/[\s,]/ " , $ node )) {
161
+ return '" ' .$ node .'" ' ;
162
+ }
163
+ return $ node ; // normal value
164
+ }
165
+ }
166
+
139
167
try {
140
168
$ l = new lessc ($ fname );
141
- $ out = $ l ->parse ();
169
+ if (has ("T " ) || has ("X " )) {
170
+ $ t = $ l ->parseTree ();
171
+ if (has ("X " ))
172
+ $ out = print_r ($ t , 1 );
173
+ else
174
+ $ out = dumpValue ($ t )."\n" ;
175
+ } else {
176
+ $ out = $ l ->parse ();
177
+ }
142
178
143
179
if (!$ fout = array_shift ($ argv )) {
144
180
echo $ out ;
0 commit comments