1   // $ANTLR 3.5.2 org/daisy/pipeline/css/sass/impl/SassDocumentation.g 2025-01-27 18:34:25
2    package org.daisy.pipeline.css.sass.impl; 
3   
4   import org.antlr.runtime.*;
5   import java.util.Stack;
6   import java.util.List;
7   import java.util.ArrayList;
8   
9   /**
10   * Parses a SCSS file and extracts information about variables. It
11   * does this by parsing variable declarations and their preceding
12   * comments. The comments are expected to be in a specific format that
13   * is a subset of Doxygen.
14   *
15   * The information gathering could later be extended to other elements
16   * such as functions and mixins.
17   */
18  @SuppressWarnings("all")
19  public class SassDocumentationParser extends Parser {
20  	public static final String[] tokenNames = new String[] {
21  		"<invalid>", "<EOR>", "<DOWN>", "<UP>", "ANY", "APOS", "AT", "BANG", "COLON", 
22  		"COMMA", "COMMENT", "COMMENT_MACR", "DEFAULT", "DOLLAR", "ESCAPE_CHAR", 
23  		"IDENT", "IDENT_START", "IMPORT", "LCURLY", "LINE_COMMENT", "MEDIA", "MINUS", 
24  		"NAME_CHAR", "NEWLINE_CHAR", "NON_ASCII", "QUOT", "RCURLY", "S", "SEMICOLON", 
25  		"SPACE_CHAR", "STRING", "STRING_CHAR", "STRING_MACR", "URI", "URI_CHAR", 
26  		"URI_MACR", "VAR_DECL", "XML_COMMENT_CLOSE", "XML_COMMENT_OPEN"
27  	};
28  	public static final int EOF=-1;
29  	public static final int ANY=4;
30  	public static final int APOS=5;
31  	public static final int AT=6;
32  	public static final int BANG=7;
33  	public static final int COLON=8;
34  	public static final int COMMA=9;
35  	public static final int COMMENT=10;
36  	public static final int COMMENT_MACR=11;
37  	public static final int DEFAULT=12;
38  	public static final int DOLLAR=13;
39  	public static final int ESCAPE_CHAR=14;
40  	public static final int IDENT=15;
41  	public static final int IDENT_START=16;
42  	public static final int IMPORT=17;
43  	public static final int LCURLY=18;
44  	public static final int LINE_COMMENT=19;
45  	public static final int MEDIA=20;
46  	public static final int MINUS=21;
47  	public static final int NAME_CHAR=22;
48  	public static final int NEWLINE_CHAR=23;
49  	public static final int NON_ASCII=24;
50  	public static final int QUOT=25;
51  	public static final int RCURLY=26;
52  	public static final int S=27;
53  	public static final int SEMICOLON=28;
54  	public static final int SPACE_CHAR=29;
55  	public static final int STRING=30;
56  	public static final int STRING_CHAR=31;
57  	public static final int STRING_MACR=32;
58  	public static final int URI=33;
59  	public static final int URI_CHAR=34;
60  	public static final int URI_MACR=35;
61  	public static final int VAR_DECL=36;
62  	public static final int XML_COMMENT_CLOSE=37;
63  	public static final int XML_COMMENT_OPEN=38;
64  
65  	// delegates
66  	public Parser[] getDelegates() {
67  		return new Parser[] {};
68  	}
69  
70  	// delegators
71  
72  
73  	public SassDocumentationParser(TokenStream input) {
74  		this(input, new RecognizerSharedState());
75  	}
76  	public SassDocumentationParser(TokenStream input, RecognizerSharedState state) {
77  		super(input, state);
78  	}
79  
80  	@Override public String[] getTokenNames() { return SassDocumentationParser.tokenNames; }
81  	@Override public String getGrammarFileName() { return "org/daisy/pipeline/css/sass/impl/SassDocumentation.g"; }
82  
83  
84  
85  	    private boolean isScss;
86  	    private java.net.URI base;
87  	    private java.util.Collection<org.daisy.pipeline.css.Medium> media;
88  	    private SassAnalyzer analyzer;
89  
90  	    private org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(getClass());
91  
92  	    /**
93  	     * @param base for resolving imports
94  	     * @param analyzer for handling imports
95  	     */
96  	    public SassDocumentationParser init(boolean isScss,
97  	                                        java.net.URI base,
98  	                                        java.util.Collection<org.daisy.pipeline.css.Medium> media,
99  	                                        SassAnalyzer analyzer) {
100 	        this.isScss = isScss;
101 	        this.base = base;
102 	        this.media = media;
103 	        this.analyzer = analyzer;
104 	        return this;
105 	    }
106 
107 	    private boolean matchingMedia(String mediaQuery) {
108 	        return com.google.common.collect.Iterables.any(media, m -> m.matches(mediaQuery));
109 	    }
110 
111 
112 
113 	// $ANTLR start "start"
114 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:49:1: start : variables ;
115 	public final void start() throws RecognitionException {
116 		try {
117 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:49:7: ( variables )
118 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:49:9: variables
119 			{
120 			pushFollow(FOLLOW_variables_in_start44);
121 			variables();
122 			state._fsp--;
123 
124 			}
125 
126 		}
127 		catch (RecognitionException re) {
128 			reportError(re);
129 			recover(input,re);
130 		}
131 		finally {
132 			// do for sure before leaving
133 		}
134 	}
135 	// $ANTLR end "start"
136 
137 
138 
139 	// $ANTLR start "variables"
140 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:51:1: variables returns [java.util.Collection<SassVariable> vars] : (c= comment | (n= VAR_DECL v= variable_value ( DEFAULT ( S )? )? SEMICOLON ) |vars_from_import= import_rule |vars_inside_media= media_rule | rule_block |~ ( COMMENT | VAR_DECL | IMPORT | MEDIA | LCURLY | RCURLY | S ) | S )* ;
141 	public final java.util.Collection<SassVariable> variables() throws RecognitionException {
142 		java.util.Collection<SassVariable> vars = null;
143 
144 
145 		Token n=null;
146 		Comment c =null;
147 		String v =null;
148 		java.util.Collection<SassVariable> vars_from_import =null;
149 		java.util.Collection<SassVariable> vars_inside_media =null;
150 
151 
152 		    Comment lastComment = null;
153 		    vars = new java.util.ArrayList<>();
154 		    boolean isDefault = false;
155 
156 		try {
157 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:57:5: ( (c= comment | (n= VAR_DECL v= variable_value ( DEFAULT ( S )? )? SEMICOLON ) |vars_from_import= import_rule |vars_inside_media= media_rule | rule_block |~ ( COMMENT | VAR_DECL | IMPORT | MEDIA | LCURLY | RCURLY | S ) | S )* )
158 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:57:7: (c= comment | (n= VAR_DECL v= variable_value ( DEFAULT ( S )? )? SEMICOLON ) |vars_from_import= import_rule |vars_inside_media= media_rule | rule_block |~ ( COMMENT | VAR_DECL | IMPORT | MEDIA | LCURLY | RCURLY | S ) | S )*
159 			{
160 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:57:7: (c= comment | (n= VAR_DECL v= variable_value ( DEFAULT ( S )? )? SEMICOLON ) |vars_from_import= import_rule |vars_inside_media= media_rule | rule_block |~ ( COMMENT | VAR_DECL | IMPORT | MEDIA | LCURLY | RCURLY | S ) | S )*
161 			loop3:
162 			while (true) {
163 				int alt3=8;
164 				switch ( input.LA(1) ) {
165 				case COMMENT:
166 					{
167 					alt3=1;
168 					}
169 					break;
170 				case VAR_DECL:
171 					{
172 					alt3=2;
173 					}
174 					break;
175 				case IMPORT:
176 					{
177 					alt3=3;
178 					}
179 					break;
180 				case MEDIA:
181 					{
182 					alt3=4;
183 					}
184 					break;
185 				case LCURLY:
186 					{
187 					alt3=5;
188 					}
189 					break;
190 				case ANY:
191 				case APOS:
192 				case AT:
193 				case BANG:
194 				case COLON:
195 				case COMMA:
196 				case COMMENT_MACR:
197 				case DEFAULT:
198 				case DOLLAR:
199 				case ESCAPE_CHAR:
200 				case IDENT:
201 				case IDENT_START:
202 				case LINE_COMMENT:
203 				case MINUS:
204 				case NAME_CHAR:
205 				case NEWLINE_CHAR:
206 				case NON_ASCII:
207 				case QUOT:
208 				case SEMICOLON:
209 				case SPACE_CHAR:
210 				case STRING:
211 				case STRING_CHAR:
212 				case STRING_MACR:
213 				case URI:
214 				case URI_CHAR:
215 				case URI_MACR:
216 				case XML_COMMENT_CLOSE:
217 				case XML_COMMENT_OPEN:
218 					{
219 					alt3=6;
220 					}
221 					break;
222 				case S:
223 					{
224 					alt3=7;
225 					}
226 					break;
227 				}
228 				switch (alt3) {
229 				case 1 :
230 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:57:9: c= comment
231 					{
232 					pushFollow(FOLLOW_comment_in_variables71);
233 					c=comment();
234 					state._fsp--;
235 
236 					 lastComment = c; 
237 					}
238 					break;
239 				case 2 :
240 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:58:9: (n= VAR_DECL v= variable_value ( DEFAULT ( S )? )? SEMICOLON )
241 					{
242 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:58:9: (n= VAR_DECL v= variable_value ( DEFAULT ( S )? )? SEMICOLON )
243 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:58:10: n= VAR_DECL v= variable_value ( DEFAULT ( S )? )? SEMICOLON
244 					{
245 					n=(Token)match(input,VAR_DECL,FOLLOW_VAR_DECL_in_variables86); 
246 					 isDefault = false; 
247 					pushFollow(FOLLOW_variable_value_in_variables92);
248 					v=variable_value();
249 					state._fsp--;
250 
251 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:58:61: ( DEFAULT ( S )? )?
252 					int alt2=2;
253 					int LA2_0 = input.LA(1);
254 					if ( (LA2_0==DEFAULT) ) {
255 						alt2=1;
256 					}
257 					switch (alt2) {
258 						case 1 :
259 							// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:58:62: DEFAULT ( S )?
260 							{
261 							match(input,DEFAULT,FOLLOW_DEFAULT_in_variables95); 
262 							 isDefault = true;
263 							// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:58:91: ( S )?
264 							int alt1=2;
265 							int LA1_0 = input.LA(1);
266 							if ( (LA1_0==S) ) {
267 								alt1=1;
268 							}
269 							switch (alt1) {
270 								case 1 :
271 									// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:58:91: S
272 									{
273 									match(input,S,FOLLOW_S_in_variables99); 
274 									}
275 									break;
276 
277 							}
278 
279 							}
280 							break;
281 
282 					}
283 
284 					match(input,SEMICOLON,FOLLOW_SEMICOLON_in_variables104); 
285 					}
286 
287 
288 					            String name = n.getText().substring(1, n.getText().length() - 1).trim();
289 					            if (isDefault)
290 					                vars.add(new SassVariable(name, lastComment, v, analyzer.datatypes));
291 					            else
292 					                vars.add(new SassVariable(name, v));
293 					            lastComment = null;
294 					        
295 					}
296 					break;
297 				case 3 :
298 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:67:9: vars_from_import= import_rule
299 					{
300 					pushFollow(FOLLOW_import_rule_in_variables126);
301 					vars_from_import=import_rule();
302 					state._fsp--;
303 
304 
305 					            vars.addAll(vars_from_import);
306 					            lastComment = null;
307 					        
308 					}
309 					break;
310 				case 4 :
311 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:71:9: vars_inside_media= media_rule
312 					{
313 					pushFollow(FOLLOW_media_rule_in_variables140);
314 					vars_inside_media=media_rule();
315 					state._fsp--;
316 
317 
318 					            if (vars_inside_media != null)
319 					                vars.addAll(vars_inside_media);
320 					            lastComment = null;
321 					        
322 					}
323 					break;
324 				case 5 :
325 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:76:9: rule_block
326 					{
327 					pushFollow(FOLLOW_rule_block_in_variables152);
328 					rule_block();
329 					state._fsp--;
330 
331 					 lastComment = null; 
332 					}
333 					break;
334 				case 6 :
335 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:77:9: ~ ( COMMENT | VAR_DECL | IMPORT | MEDIA | LCURLY | RCURLY | S )
336 					{
337 					if ( (input.LA(1) >= ANY && input.LA(1) <= COMMA)||(input.LA(1) >= COMMENT_MACR && input.LA(1) <= IDENT_START)||input.LA(1)==LINE_COMMENT||(input.LA(1) >= MINUS && input.LA(1) <= QUOT)||(input.LA(1) >= SEMICOLON && input.LA(1) <= URI_MACR)||(input.LA(1) >= XML_COMMENT_CLOSE && input.LA(1) <= XML_COMMENT_OPEN) ) {
338 						input.consume();
339 						state.errorRecovery=false;
340 					}
341 					else {
342 						MismatchedSetException mse = new MismatchedSetException(null,input);
343 						throw mse;
344 					}
345 					 lastComment = null; 
346 					}
347 					break;
348 				case 7 :
349 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:78:9: S
350 					{
351 					match(input,S,FOLLOW_S_in_variables191); 
352 					}
353 					break;
354 
355 				default :
356 					break loop3;
357 				}
358 			}
359 
360 			}
361 
362 		}
363 		catch (RecognitionException re) {
364 			reportError(re);
365 			recover(input,re);
366 		}
367 		finally {
368 			// do for sure before leaving
369 		}
370 		return vars;
371 	}
372 	// $ANTLR end "variables"
373 
374 
375 
376 	// $ANTLR start "variable_value"
377 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:82:1: variable_value returns [String value] : (t=~ ( DEFAULT | SEMICOLON ) )+ ;
378 	public final String variable_value() throws RecognitionException {
379 		String value = null;
380 
381 
382 		Token t=null;
383 
384 
385 		    value = "";
386 
387 		try {
388 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:89:5: ( (t=~ ( DEFAULT | SEMICOLON ) )+ )
389 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:89:7: (t=~ ( DEFAULT | SEMICOLON ) )+
390 			{
391 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:89:7: (t=~ ( DEFAULT | SEMICOLON ) )+
392 			int cnt4=0;
393 			loop4:
394 			while (true) {
395 				int alt4=2;
396 				int LA4_0 = input.LA(1);
397 				if ( ((LA4_0 >= ANY && LA4_0 <= COMMENT_MACR)||(LA4_0 >= DOLLAR && LA4_0 <= S)||(LA4_0 >= SPACE_CHAR && LA4_0 <= XML_COMMENT_OPEN)) ) {
398 					alt4=1;
399 				}
400 
401 				switch (alt4) {
402 				case 1 :
403 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:89:9: t=~ ( DEFAULT | SEMICOLON )
404 					{
405 					t=input.LT(1);
406 					if ( (input.LA(1) >= ANY && input.LA(1) <= COMMENT_MACR)||(input.LA(1) >= DOLLAR && input.LA(1) <= S)||(input.LA(1) >= SPACE_CHAR && input.LA(1) <= XML_COMMENT_OPEN) ) {
407 						input.consume();
408 						state.errorRecovery=false;
409 					}
410 					else {
411 						MismatchedSetException mse = new MismatchedSetException(null,input);
412 						throw mse;
413 					}
414 					 value += t.getText(); 
415 					}
416 					break;
417 
418 				default :
419 					if ( cnt4 >= 1 ) break loop4;
420 					EarlyExitException eee = new EarlyExitException(4, input);
421 					throw eee;
422 				}
423 				cnt4++;
424 			}
425 
426 			}
427 
428 
429 			    value = value.trim();
430 
431 		}
432 		catch (RecognitionException re) {
433 			reportError(re);
434 			recover(input,re);
435 		}
436 		finally {
437 			// do for sure before leaving
438 		}
439 		return value;
440 	}
441 	// $ANTLR end "variable_value"
442 
443 
444 
445 	// $ANTLR start "comment"
446 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:92:1: comment returns [Comment comment] : c= COMMENT ;
447 	public final Comment comment() throws RecognitionException {
448 		Comment comment = null;
449 
450 
451 		Token c=null;
452 
453 		try {
454 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:93:5: (c= COMMENT )
455 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:93:7: c= COMMENT
456 			{
457 			c=(Token)match(input,COMMENT,FOLLOW_COMMENT_in_comment268); 
458 
459 			          String text = c.getText();
460 			          comment = new Comment(text.substring(2, text.length() - 2), c.getCharPositionInLine());
461 			      
462 			}
463 
464 		}
465 		catch (RecognitionException re) {
466 			reportError(re);
467 			recover(input,re);
468 		}
469 		finally {
470 			// do for sure before leaving
471 		}
472 		return comment;
473 	}
474 	// $ANTLR end "comment"
475 
476 
477 
478 	// $ANTLR start "import_rule"
479 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:99:1: import_rule returns [java.util.Collection<SassVariable> vars] : ( IMPORT ( S )? u= import_uri ( ( S )? COMMA ( S )? u= import_uri )* ( S )? (q= media )? SEMICOLON ) ;
480 	public final java.util.Collection<SassVariable> import_rule() throws RecognitionException {
481 		java.util.Collection<SassVariable> vars = null;
482 
483 
484 		java.net.URI u =null;
485 		String q =null;
486 
487 
488 		    vars = new java.util.ArrayList<>();
489 		    java.util.List<java.net.URI> imports = new java.util.ArrayList<>();
490 		    String mediaQuery = null;
491 
492 		try {
493 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:105:5: ( ( IMPORT ( S )? u= import_uri ( ( S )? COMMA ( S )? u= import_uri )* ( S )? (q= media )? SEMICOLON ) )
494 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:105:7: ( IMPORT ( S )? u= import_uri ( ( S )? COMMA ( S )? u= import_uri )* ( S )? (q= media )? SEMICOLON )
495 			{
496 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:105:7: ( IMPORT ( S )? u= import_uri ( ( S )? COMMA ( S )? u= import_uri )* ( S )? (q= media )? SEMICOLON )
497 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:105:8: IMPORT ( S )? u= import_uri ( ( S )? COMMA ( S )? u= import_uri )* ( S )? (q= media )? SEMICOLON
498 			{
499 			match(input,IMPORT,FOLLOW_IMPORT_in_import_rule297); 
500 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:106:8: ( S )?
501 			int alt5=2;
502 			int LA5_0 = input.LA(1);
503 			if ( (LA5_0==S) ) {
504 				alt5=1;
505 			}
506 			switch (alt5) {
507 				case 1 :
508 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:106:8: S
509 					{
510 					match(input,S,FOLLOW_S_in_import_rule306); 
511 					}
512 					break;
513 
514 			}
515 
516 			pushFollow(FOLLOW_import_uri_in_import_rule311);
517 			u=import_uri();
518 			state._fsp--;
519 
520 			 imports.add(u); 
521 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:107:8: ( ( S )? COMMA ( S )? u= import_uri )*
522 			loop8:
523 			while (true) {
524 				int alt8=2;
525 				int LA8_0 = input.LA(1);
526 				if ( (LA8_0==S) ) {
527 					int LA8_1 = input.LA(2);
528 					if ( (LA8_1==COMMA) ) {
529 						alt8=1;
530 					}
531 
532 				}
533 				else if ( (LA8_0==COMMA) ) {
534 					alt8=1;
535 				}
536 
537 				switch (alt8) {
538 				case 1 :
539 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:107:9: ( S )? COMMA ( S )? u= import_uri
540 					{
541 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:107:9: ( S )?
542 					int alt6=2;
543 					int LA6_0 = input.LA(1);
544 					if ( (LA6_0==S) ) {
545 						alt6=1;
546 					}
547 					switch (alt6) {
548 						case 1 :
549 							// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:107:9: S
550 							{
551 							match(input,S,FOLLOW_S_in_import_rule323); 
552 							}
553 							break;
554 
555 					}
556 
557 					match(input,COMMA,FOLLOW_COMMA_in_import_rule326); 
558 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:107:18: ( S )?
559 					int alt7=2;
560 					int LA7_0 = input.LA(1);
561 					if ( (LA7_0==S) ) {
562 						alt7=1;
563 					}
564 					switch (alt7) {
565 						case 1 :
566 							// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:107:18: S
567 							{
568 							match(input,S,FOLLOW_S_in_import_rule328); 
569 							}
570 							break;
571 
572 					}
573 
574 					pushFollow(FOLLOW_import_uri_in_import_rule333);
575 					u=import_uri();
576 					state._fsp--;
577 
578 					 imports.add(u); 
579 					}
580 					break;
581 
582 				default :
583 					break loop8;
584 				}
585 			}
586 
587 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:108:8: ( S )?
588 			int alt9=2;
589 			int LA9_0 = input.LA(1);
590 			if ( (LA9_0==S) ) {
591 				alt9=1;
592 			}
593 			switch (alt9) {
594 				case 1 :
595 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:108:8: S
596 					{
597 					match(input,S,FOLLOW_S_in_import_rule346); 
598 					}
599 					break;
600 
601 			}
602 
603 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:108:11: (q= media )?
604 			int alt10=2;
605 			int LA10_0 = input.LA(1);
606 			if ( ((LA10_0 >= ANY && LA10_0 <= COLON)||(LA10_0 >= COMMENT && LA10_0 <= IMPORT)||(LA10_0 >= LINE_COMMENT && LA10_0 <= RCURLY)||LA10_0==SPACE_CHAR||(LA10_0 >= STRING_CHAR && LA10_0 <= STRING_MACR)||(LA10_0 >= URI_CHAR && LA10_0 <= XML_COMMENT_OPEN)) ) {
607 				alt10=1;
608 			}
609 			switch (alt10) {
610 				case 1 :
611 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:108:12: q= media
612 					{
613 					pushFollow(FOLLOW_media_in_import_rule352);
614 					q=media();
615 					state._fsp--;
616 
617 					 mediaQuery = q; 
618 					}
619 					break;
620 
621 			}
622 
623 			match(input,SEMICOLON,FOLLOW_SEMICOLON_in_import_rule365); 
624 			}
625 
626 
627 			           if (matchingMedia(mediaQuery))
628 			               for (java.net.URI i : imports)
629 			                   try {
630 			                       java.net.URL url; {
631 			                           try {
632 			                               if (base != null)
633 			                                   i = org.daisy.common.file.URLs.resolve(base, i);
634 			                               url = org.daisy.common.file.URLs.asURL(i);
635 			                           } catch (RuntimeException e) {
636 			                               throw new java.io.IOException(e);
637 			                           }
638 			                       }
639 			                       vars.addAll(
640 			                           analyzer.getVariableDeclarations(
641 			                               new cz.vutbr.web.csskit.antlr.CSSSource(url,
642 			                                                                       java.nio.charset.StandardCharsets.UTF_8,
643 			                                                                       null)));
644 			                   } catch (java.io.IOException e) {
645 			                       logger.warn("Could not import stylesheet; skipping: " + i, e);
646 			                   }
647 			       
648 			}
649 
650 		}
651 		catch (RecognitionException re) {
652 			reportError(re);
653 			recover(input,re);
654 		}
655 		finally {
656 			// do for sure before leaving
657 		}
658 		return vars;
659 	}
660 	// $ANTLR end "import_rule"
661 
662 
663 
664 	// $ANTLR start "media_rule"
665 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:133:1: media_rule returns [java.util.Collection<SassVariable> vars] : ( MEDIA ( S )? q= media LCURLY v= variables RCURLY ) ;
666 	public final java.util.Collection<SassVariable> media_rule() throws RecognitionException {
667 		java.util.Collection<SassVariable> vars = null;
668 
669 
670 		String q =null;
671 		java.util.Collection<SassVariable> v =null;
672 
673 		try {
674 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:134:5: ( ( MEDIA ( S )? q= media LCURLY v= variables RCURLY ) )
675 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:134:7: ( MEDIA ( S )? q= media LCURLY v= variables RCURLY )
676 			{
677 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:134:7: ( MEDIA ( S )? q= media LCURLY v= variables RCURLY )
678 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:134:8: MEDIA ( S )? q= media LCURLY v= variables RCURLY
679 			{
680 			match(input,MEDIA,FOLLOW_MEDIA_in_media_rule390); 
681 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:134:14: ( S )?
682 			int alt11=2;
683 			int LA11_0 = input.LA(1);
684 			if ( (LA11_0==S) ) {
685 				alt11=1;
686 			}
687 			switch (alt11) {
688 				case 1 :
689 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:134:14: S
690 					{
691 					match(input,S,FOLLOW_S_in_media_rule392); 
692 					}
693 					break;
694 
695 			}
696 
697 			pushFollow(FOLLOW_media_in_media_rule397);
698 			q=media();
699 			state._fsp--;
700 
701 			match(input,LCURLY,FOLLOW_LCURLY_in_media_rule399); 
702 			pushFollow(FOLLOW_variables_in_media_rule403);
703 			v=variables();
704 			state._fsp--;
705 
706 			match(input,RCURLY,FOLLOW_RCURLY_in_media_rule405); 
707 			}
708 
709 
710 			          if (matchingMedia(q))
711 			              vars = v;
712 			      
713 			}
714 
715 		}
716 		catch (RecognitionException re) {
717 			reportError(re);
718 			recover(input,re);
719 		}
720 		finally {
721 			// do for sure before leaving
722 		}
723 		return vars;
724 	}
725 	// $ANTLR end "media_rule"
726 
727 
728 
729 	// $ANTLR start "media"
730 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:140:1: media returns [String media] : t=~ ( S | LCURLY | SEMICOLON | COMMA | STRING | URI ) (t=~ ( LCURLY | SEMICOLON ) )* ;
731 	public final String media() throws RecognitionException {
732 		String media = null;
733 
734 
735 		Token t=null;
736 
737 
738 		    StringBuilder s = new StringBuilder();
739 
740 		try {
741 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:147:5: (t=~ ( S | LCURLY | SEMICOLON | COMMA | STRING | URI ) (t=~ ( LCURLY | SEMICOLON ) )* )
742 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:147:7: t=~ ( S | LCURLY | SEMICOLON | COMMA | STRING | URI ) (t=~ ( LCURLY | SEMICOLON ) )*
743 			{
744 			t=input.LT(1);
745 			if ( (input.LA(1) >= ANY && input.LA(1) <= COLON)||(input.LA(1) >= COMMENT && input.LA(1) <= IMPORT)||(input.LA(1) >= LINE_COMMENT && input.LA(1) <= RCURLY)||input.LA(1)==SPACE_CHAR||(input.LA(1) >= STRING_CHAR && input.LA(1) <= STRING_MACR)||(input.LA(1) >= URI_CHAR && input.LA(1) <= XML_COMMENT_OPEN) ) {
746 				input.consume();
747 				state.errorRecovery=false;
748 			}
749 			else {
750 				MismatchedSetException mse = new MismatchedSetException(null,input);
751 				throw mse;
752 			}
753 			 s.append(t.getText()); 
754 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:148:7: (t=~ ( LCURLY | SEMICOLON ) )*
755 			loop12:
756 			while (true) {
757 				int alt12=2;
758 				int LA12_0 = input.LA(1);
759 				if ( ((LA12_0 >= ANY && LA12_0 <= IMPORT)||(LA12_0 >= LINE_COMMENT && LA12_0 <= S)||(LA12_0 >= SPACE_CHAR && LA12_0 <= XML_COMMENT_OPEN)) ) {
760 					alt12=1;
761 				}
762 
763 				switch (alt12) {
764 				case 1 :
765 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:148:8: t=~ ( LCURLY | SEMICOLON )
766 					{
767 					t=input.LT(1);
768 					if ( (input.LA(1) >= ANY && input.LA(1) <= IMPORT)||(input.LA(1) >= LINE_COMMENT && input.LA(1) <= S)||(input.LA(1) >= SPACE_CHAR && input.LA(1) <= XML_COMMENT_OPEN) ) {
769 						input.consume();
770 						state.errorRecovery=false;
771 					}
772 					else {
773 						MismatchedSetException mse = new MismatchedSetException(null,input);
774 						throw mse;
775 					}
776 					 s.append(t.getText()); 
777 					}
778 					break;
779 
780 				default :
781 					break loop12;
782 				}
783 			}
784 
785 			}
786 
787 
788 			    media = s.toString().trim();
789 
790 		}
791 		catch (RecognitionException re) {
792 			reportError(re);
793 			recover(input,re);
794 		}
795 		finally {
796 			// do for sure before leaving
797 		}
798 		return media;
799 	}
800 	// $ANTLR end "media"
801 
802 
803 
804 	// $ANTLR start "import_uri"
805 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:151:1: import_uri returns [java.net.URI uri] : (s= STRING |u= URI ) ;
806 	public final java.net.URI import_uri() throws RecognitionException {
807 		java.net.URI uri = null;
808 
809 
810 		Token s=null;
811 		Token u=null;
812 
813 		try {
814 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:152:5: ( (s= STRING |u= URI ) )
815 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:152:7: (s= STRING |u= URI )
816 			{
817 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:152:7: (s= STRING |u= URI )
818 			int alt13=2;
819 			int LA13_0 = input.LA(1);
820 			if ( (LA13_0==STRING) ) {
821 				alt13=1;
822 			}
823 			else if ( (LA13_0==URI) ) {
824 				alt13=2;
825 			}
826 
827 			else {
828 				NoViableAltException nvae =
829 					new NoViableAltException("", 13, 0, input);
830 				throw nvae;
831 			}
832 
833 			switch (alt13) {
834 				case 1 :
835 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:152:9: s= STRING
836 					{
837 					s=(Token)match(input,STRING,FOLLOW_STRING_in_import_uri501); 
838 
839 					            String t = s.getText();
840 					            t = t.substring(1, t.length() - 1);
841 					            t = org.unbescape.css.CssEscape.unescapeCss(t);
842 					            uri = java.net.URI.create(t);
843 					        
844 					}
845 					break;
846 				case 2 :
847 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:158:9: u= URI
848 					{
849 					u=(Token)match(input,URI,FOLLOW_URI_in_import_uri515); 
850 
851 					            String t = u.getText();
852 					            t = t.substring(4, t.length() - 1);
853 					            t = t.trim();
854 					            if (t.length() > 0 && (t.charAt(0) == '\'' || t.charAt(0) == '"')) {
855 					                t = t.substring(1, t.length() - 1);
856 					                t = org.unbescape.css.CssEscape.unescapeCss(t);
857 					            }
858 					            uri = java.net.URI.create(t);
859 					        
860 					}
861 					break;
862 
863 			}
864 
865 			}
866 
867 		}
868 		catch (RecognitionException re) {
869 			reportError(re);
870 			recover(input,re);
871 		}
872 		finally {
873 			// do for sure before leaving
874 		}
875 		return uri;
876 	}
877 	// $ANTLR end "import_uri"
878 
879 
880 
881 	// $ANTLR start "rule_block"
882 	// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:171:1: rule_block : LCURLY ( rule_block |~ ( RCURLY | LCURLY ) )* RCURLY ;
883 	public final void rule_block() throws RecognitionException {
884 		try {
885 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:172:5: ( LCURLY ( rule_block |~ ( RCURLY | LCURLY ) )* RCURLY )
886 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:172:7: LCURLY ( rule_block |~ ( RCURLY | LCURLY ) )* RCURLY
887 			{
888 			match(input,LCURLY,FOLLOW_LCURLY_in_rule_block542); 
889 			// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:173:10: ( rule_block |~ ( RCURLY | LCURLY ) )*
890 			loop14:
891 			while (true) {
892 				int alt14=3;
893 				int LA14_0 = input.LA(1);
894 				if ( (LA14_0==LCURLY) ) {
895 					alt14=1;
896 				}
897 				else if ( ((LA14_0 >= ANY && LA14_0 <= IMPORT)||(LA14_0 >= LINE_COMMENT && LA14_0 <= QUOT)||(LA14_0 >= S && LA14_0 <= XML_COMMENT_OPEN)) ) {
898 					alt14=2;
899 				}
900 
901 				switch (alt14) {
902 				case 1 :
903 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:173:12: rule_block
904 					{
905 					pushFollow(FOLLOW_rule_block_in_rule_block555);
906 					rule_block();
907 					state._fsp--;
908 
909 					}
910 					break;
911 				case 2 :
912 					// org/daisy/pipeline/css/sass/impl/SassDocumentation.g:174:12: ~ ( RCURLY | LCURLY )
913 					{
914 					if ( (input.LA(1) >= ANY && input.LA(1) <= IMPORT)||(input.LA(1) >= LINE_COMMENT && input.LA(1) <= QUOT)||(input.LA(1) >= S && input.LA(1) <= XML_COMMENT_OPEN) ) {
915 						input.consume();
916 						state.errorRecovery=false;
917 					}
918 					else {
919 						MismatchedSetException mse = new MismatchedSetException(null,input);
920 						throw mse;
921 					}
922 					}
923 					break;
924 
925 				default :
926 					break loop14;
927 				}
928 			}
929 
930 			match(input,RCURLY,FOLLOW_RCURLY_in_rule_block593); 
931 			}
932 
933 		}
934 		catch (RecognitionException re) {
935 			reportError(re);
936 			recover(input,re);
937 		}
938 		finally {
939 			// do for sure before leaving
940 		}
941 	}
942 	// $ANTLR end "rule_block"
943 
944 	// Delegated rules
945 
946 
947 
948 	public static final BitSet FOLLOW_variables_in_start44 = new BitSet(new long[]{0x0000000000000002L});
949 	public static final BitSet FOLLOW_comment_in_variables71 = new BitSet(new long[]{0x0000007FFBFFFFF2L});
950 	public static final BitSet FOLLOW_VAR_DECL_in_variables86 = new BitSet(new long[]{0x0000007FEFFFEFF0L});
951 	public static final BitSet FOLLOW_variable_value_in_variables92 = new BitSet(new long[]{0x0000000010001000L});
952 	public static final BitSet FOLLOW_DEFAULT_in_variables95 = new BitSet(new long[]{0x0000000018000000L});
953 	public static final BitSet FOLLOW_S_in_variables99 = new BitSet(new long[]{0x0000000010000000L});
954 	public static final BitSet FOLLOW_SEMICOLON_in_variables104 = new BitSet(new long[]{0x0000007FFBFFFFF2L});
955 	public static final BitSet FOLLOW_import_rule_in_variables126 = new BitSet(new long[]{0x0000007FFBFFFFF2L});
956 	public static final BitSet FOLLOW_media_rule_in_variables140 = new BitSet(new long[]{0x0000007FFBFFFFF2L});
957 	public static final BitSet FOLLOW_rule_block_in_variables152 = new BitSet(new long[]{0x0000007FFBFFFFF2L});
958 	public static final BitSet FOLLOW_set_in_variables164 = new BitSet(new long[]{0x0000007FFBFFFFF2L});
959 	public static final BitSet FOLLOW_S_in_variables191 = new BitSet(new long[]{0x0000007FFBFFFFF2L});
960 	public static final BitSet FOLLOW_set_in_variable_value235 = new BitSet(new long[]{0x0000007FEFFFEFF2L});
961 	public static final BitSet FOLLOW_COMMENT_in_comment268 = new BitSet(new long[]{0x0000000000000002L});
962 	public static final BitSet FOLLOW_IMPORT_in_import_rule297 = new BitSet(new long[]{0x0000000248000000L});
963 	public static final BitSet FOLLOW_S_in_import_rule306 = new BitSet(new long[]{0x0000000240000000L});
964 	public static final BitSet FOLLOW_import_uri_in_import_rule311 = new BitSet(new long[]{0x0000007DBFFBFFF0L});
965 	public static final BitSet FOLLOW_S_in_import_rule323 = new BitSet(new long[]{0x0000000000000200L});
966 	public static final BitSet FOLLOW_COMMA_in_import_rule326 = new BitSet(new long[]{0x0000000248000000L});
967 	public static final BitSet FOLLOW_S_in_import_rule328 = new BitSet(new long[]{0x0000000240000000L});
968 	public static final BitSet FOLLOW_import_uri_in_import_rule333 = new BitSet(new long[]{0x0000007DBFFBFFF0L});
969 	public static final BitSet FOLLOW_S_in_import_rule346 = new BitSet(new long[]{0x0000007DB7FBFDF0L});
970 	public static final BitSet FOLLOW_media_in_import_rule352 = new BitSet(new long[]{0x0000000010000000L});
971 	public static final BitSet FOLLOW_SEMICOLON_in_import_rule365 = new BitSet(new long[]{0x0000000000000002L});
972 	public static final BitSet FOLLOW_MEDIA_in_media_rule390 = new BitSet(new long[]{0x0000007DAFFBFDF0L});
973 	public static final BitSet FOLLOW_S_in_media_rule392 = new BitSet(new long[]{0x0000007DA7FBFDF0L});
974 	public static final BitSet FOLLOW_media_in_media_rule397 = new BitSet(new long[]{0x0000000000040000L});
975 	public static final BitSet FOLLOW_LCURLY_in_media_rule399 = new BitSet(new long[]{0x0000007FFFFFFFF0L});
976 	public static final BitSet FOLLOW_variables_in_media_rule403 = new BitSet(new long[]{0x0000000004000000L});
977 	public static final BitSet FOLLOW_RCURLY_in_media_rule405 = new BitSet(new long[]{0x0000000000000002L});
978 	public static final BitSet FOLLOW_set_in_media441 = new BitSet(new long[]{0x0000007FEFFBFFF2L});
979 	public static final BitSet FOLLOW_set_in_media467 = new BitSet(new long[]{0x0000007FEFFBFFF2L});
980 	public static final BitSet FOLLOW_STRING_in_import_uri501 = new BitSet(new long[]{0x0000000000000002L});
981 	public static final BitSet FOLLOW_URI_in_import_uri515 = new BitSet(new long[]{0x0000000000000002L});
982 	public static final BitSet FOLLOW_LCURLY_in_rule_block542 = new BitSet(new long[]{0x0000007FFFFFFFF0L});
983 	public static final BitSet FOLLOW_rule_block_in_rule_block555 = new BitSet(new long[]{0x0000007FFFFFFFF0L});
984 	public static final BitSet FOLLOW_set_in_rule_block568 = new BitSet(new long[]{0x0000007FFFFFFFF0L});
985 	public static final BitSet FOLLOW_RCURLY_in_rule_block593 = new BitSet(new long[]{0x0000000000000002L});
986 }