/** * Implements {@link ExtendedParser#parseStyleDeclaration(String)}. */ public void parseStyleDeclaration(String source) throws CSSException, IOException { scanner = new Scanner(source); parseStyleDeclarationInternal(); }
/** * Advances to the next token, ignoring comments. */ protected int next() { try { for (;;) { scanner.clearBuffer(); current = scanner.next(); if (current == LexicalUnits.COMMENT) { documentHandler.comment(scanner.getStringValue()); } else { break; } } return current; } catch (ParseException e) { reportError(e.getMessage()); return current; } }
/** * Parses selectors using the current scanner. */ protected SelectorList parseSelectorsInternal() throws CSSException, IOException { nextIgnoreSpaces(); SelectorList ret = parseSelectorList(); scanner.close(); scanner = null; return ret; }
/** * Parses an unknown rule. */ protected void parseAtRule() { scanner.scanAtRule(); documentHandler.ignorableAtRule(scanner.getStringValue()); nextIgnoreSpaces(); }
return; case '{': nextChar(); type = LexicalUnits.LEFT_CURLY_BRACE; return; case '}': nextChar(); type = LexicalUnits.RIGHT_CURLY_BRACE; return; case '=': nextChar(); type = LexicalUnits.EQUAL; return; case '+': nextChar(); type = LexicalUnits.PLUS; return; case ',': nextChar(); type = LexicalUnits.COMMA; return; case ';': nextChar(); type = LexicalUnits.SEMI_COLON; return; case '>': nextChar(); type = LexicalUnits.PRECEDE; return;
/** * Scans a number. */ protected int number() throws IOException { loop: for (;;) { switch (nextChar()) { case '.': switch (nextChar()) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return dotNumber(); } throw new ParseException("character", reader.getLine(), reader.getColumn()); default: break loop; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': } } return numberUnit(true); }
/** * Converts the current lexical unit to a float. */ protected float number(boolean positive) { try { float sgn = (positive) ? 1 : -1; String val = scanner.getStringValue(); nextIgnoreSpaces(); return sgn * Float.parseFloat(val); } catch (NumberFormatException e) { throw createCSSParseException("number.format"); } }
documentHandler.startDocument(source); current = scanner.next(); switch (current) { case LexicalUnits.CHARSET_SYMBOL: documentHandler.comment(scanner.getStringValue()); scanner.close(); scanner = null;
/** * Skips the white spaces. */ protected int skipSpaces() { int lex = scanner.getType(); while (lex == LexicalUnits.SPACE) { lex = next(); } return lex; }
/** * Skips the white spaces and CDO/CDC units. */ protected int skipSpacesAndCDOCDC() { loop: for (;;) { switch (current) { default: break loop; case LexicalUnits.COMMENT: case LexicalUnits.SPACE: case LexicalUnits.CDO: case LexicalUnits.CDC: } scanner.clearBuffer(); next(); } return current; }
return; case '{': nextChar(); type = LexicalUnits.LEFT_CURLY_BRACE; return; case '}': nextChar(); type = LexicalUnits.RIGHT_CURLY_BRACE; return; case '=': nextChar(); type = LexicalUnits.EQUAL; return; case '+': nextChar(); type = LexicalUnits.PLUS; return; case ',': nextChar(); type = LexicalUnits.COMMA; return; case ';': nextChar(); type = LexicalUnits.SEMI_COLON; return; case '>': nextChar(); type = LexicalUnits.PRECEDE; return;
/** * Scans a number. */ protected int number() throws IOException { loop: for (;;) { switch (nextChar()) { case '.': switch (nextChar()) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return dotNumber(); } throw new ParseException("character", reader.getLine(), reader.getColumn()); default: break loop; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': } } return numberUnit(true); }
/** * Converts the current lexical unit to a float. */ protected float number(boolean positive) { try { float sgn = (positive) ? 1 : -1; String val = scanner.getStringValue(); nextIgnoreSpaces(); return sgn * Float.parseFloat(val); } catch (NumberFormatException e) { throw createCSSParseException("number.format"); } }
documentHandler.startDocument(source); current = scanner.next(); switch (current) { case LexicalUnits.CHARSET_SYMBOL: documentHandler.comment(scanner.getStringValue()); scanner.close(); scanner = null;
/** * Parses an unknown rule. */ protected void parseAtRule() { scanner.scanAtRule(); documentHandler.ignorableAtRule(scanner.getStringValue()); nextIgnoreSpaces(); }