UnprocessedStatement* LessParser::parseRulesetStatement (LessRuleset &ruleset) { UnprocessedStatement* statement; Selector tokens; size_t property_i; while (parseProperty(tokens) || parsePropertyVariable(tokens)) {} property_i = tokens.size(); parseWhitespace(tokens); parseSelector(tokens); tokens.trim(); if (tokens.empty()) return NULL; statement = ruleset.createUnprocessedStatement(); statement->getTokens()->swap(tokens); statement->property_i = property_i; if (tokenizer->getTokenType() == Token::BRACKET_OPEN) return statement; parseValue(*statement->getTokens()); if (tokenizer->getTokenType() == Token::DELIMITER) { tokenizer->readNextToken(); skipWhitespace(); } return statement; }
void MapCSSPaintstyle::loadPainters(const QString& filename) { QFile file(filename); if (!file.open(QIODevice::ReadOnly)) return; QByteArray css = file.readAll(); QString cssS(css); file.close(); /* Remove comments */ QRegExp cssComments("/\\*.*\\*/"); cssComments.setMinimal(true); cssS.replace(cssComments, ""); /* Styles */ QRegExp cssStyle("\\s*(.*)\\s*\\{(.*)\\}"); cssStyle.setMinimal(true); QRegExp blanks("\\s*"); QRegExp attSep("\\s*;\\s*"); QHash <QString, QStringList> styles; int pos=0; while (cssStyle.indexIn(cssS, pos) != -1) { QString selector = parseSelector(cssStyle.capturedTexts().at(1).trimmed()); QString attributes = cssStyle.capturedTexts().at(2).trimmed(); styles[selector] = attributes.split(attSep); pos += cssStyle.matchedLength(); } qDebug() << styles; }
void stylesheetParser::parse(){ if(!m_stopProcessing){ if(!m_styleSheet.isEmpty()){ if(m_styleSheet.startsWith("/*")) parseComment(); else if(m_styleSheet.startsWith("@page")) parseAtRules1(); else if(m_styleSheet.startsWith("@media")) parseAtRules1(); else if(m_styleSheet.startsWith("@import")) parseAtRules2(); else if(m_styleSheet.startsWith("@charset")) parseAtRules2(); else parseSelector(); } else return; } }
Ruleset* CssParser::parseRuleset () { Ruleset* ruleset = NULL; Declaration* declaration = NULL; Selector* selector = new Selector(); if (!parseSelector(selector)) { delete selector; selector = NULL; if (tokenizer->getTokenType() != Token::BRACKET_OPEN) { return NULL; } } else if (tokenizer->getTokenType() != Token::BRACKET_OPEN) { delete selector; throw new ParseException(tokenizer->getToken()->str, "a declaration block ('{...}')"); } tokenizer->readNextToken(); ruleset = new Ruleset(selector); skipWhitespace(); declaration = parseDeclaration(); if (declaration != NULL) ruleset->addDeclaration(declaration); while (tokenizer->getTokenType() == Token::DELIMITER) { tokenizer->readNextToken(); skipWhitespace(); declaration = parseDeclaration(); if (declaration != NULL) ruleset->addDeclaration(declaration); } if (tokenizer->getTokenType() != Token::BRACKET_CLOSED) { throw new ParseException(tokenizer->getToken()->str, "end of declaration block ('}')"); } tokenizer->readNextToken(); skipWhitespace(); return ruleset; }
bool LessParser::parseStatement(Stylesheet &stylesheet) { Selector selector; Mixin* mixin; CssComment* comment; LessStylesheet* ls = (LessStylesheet*)&stylesheet; if (tokenizer->getTokenType() == Token::COMMENT) { comment = ls->createComment(); comment->setComment(tokenizer->getToken()); tokenizer->readNextToken(); skipWhitespace(); return true; } else if (parseSelector(selector) && !selector.empty()) { #ifdef WITH_LIBGLOG VLOG(2) << "Parse: Selector: " << selector.toString(); #endif if (parseRuleset(*ls, selector)) return true; // Parameter mixin in the root. Inserts nested rules but no // declarations. mixin = ls->createMixin(); mixin->setReference(reference); if (mixin->parse(selector)) { if (tokenizer->getTokenType() == Token::DELIMITER) { tokenizer->readNextToken(); skipWhitespace(); } return true; } else { ls->deleteMixin(*mixin); throw new ParseException(tokenizer->getToken(), "a declaration block ('{...}') following selector"); } } else { return parseAtRuleOrVariable(*ls); } }
void CreateView::execute() { if ( d->name.isEmpty() ) { parseOptions(); Utf8Codec c; d->name = c.toUnicode( next() ); d->source = c.toUnicode( next() ); UString owner( c.toUnicode( next() ) ); d->selector = parseSelector( args() ); if ( !c.valid() ) error( "Argument encoding: " + c.error() ); if ( d->name.isEmpty() ) error( "No name supplied for the view." ); if ( d->source.isEmpty() ) error( "No source mailbox name supplied." ); if ( !d->selector ) error( "Invalid search expression supplied." ); database( true ); Mailbox::setup( this ); if ( !owner.isEmpty() ) { d->user = new User; d->user->setLogin( owner ); d->user->refresh( this ); } } if ( !choresDone() ) return; if ( !d->t ) { if ( d->user ) { if ( d->user->state() == User::Unverified ) return; if ( d->user->state() == User::Nonexistent ) error( "No user named " + d->user->login().utf8() ); if ( !d->name.startsWith( "/" ) ) d->name = d->user->home()->name() + "/" + d->name; if ( !d->source.startsWith( "/" ) ) d->source = d->user->home()->name() + "/" + d->source; } d->ms = Mailbox::obtain( d->source ); if ( !d->ms || d->ms->deleted() ) error( "Can't create view on " + d->source.utf8() ); d->t = new Transaction( this ); d->mv = Mailbox::obtain( d->name ); Query * q = d->mv->create( d->t, d->user ); if ( !q ) error( "Couldn't create view named " + d->name.utf8() ); q = new Query( "insert into views " "(view, selector, source, nextmodseq) values " "((select id from mailboxes where name=$1)," "$2, " "((select id from mailboxes where name=$3), " "1::bigint)", this ); q->bind( 1, d->name ); q->bind( 2, d->selector->string() ); q->bind( 3, d->ms->name() ); d->t->enqueue( q ); d->t->commit(); } if ( !d->t->done() ) return; if ( d->t->failed() ) error( "Couldn't create view" ); finish(); }
int main( int ac, char ** av ) { Scope global; bool bad = false; if ( ac < 1 ) bad = true; Configuration::setup( "archiveopteryx.conf" ); EventLoop::setup(); Log * l = new Log; Allocator::addEternal( l, "aoxexport log" ); global.setLog( l ); LogClient::setup( "aoxexport" ); Configuration::report(); int i = 1; while( i < ac && *av[i] == '-' ) { uint j = 1; while ( av[i][j] ) { switch( av[i][j] ) { case 'v': verbosity++; break; case 'q': if ( verbosity ) verbosity--; break; default: bad = true; break; } j++; } i++; } Utf8Codec c; UString source; if ( i >= ac ) bad = true; else if ( av[i][0] == '/' ) source = c.toUnicode( av[i++] ); Selector * which; if ( i < ac ) { EStringList args; while ( i < ac ) args.append( new EString( av[i++] ) ); which = parseSelector( &args ); } else { which = new Selector( Selector::NoField, Selector::All, 0 ); } if ( bad ) { fprintf( stderr, "Usage: %s [-vq] [mailbox] [search]" "See aoxexport(8) or " "http://aox.org/aoxexport/ for details.\n", av[0] ); exit( -1 ); } if ( !c.valid() ) { fprintf( stderr, "%s: Mailbox name could not be converted from UTF-8: %s\n", av[0], c.error().cstr() ); exit( -1 ); } Entropy::setup(); Database::setup(); Exporter * e = new Exporter( source, which ); Mailbox::setup( e ); EventLoop::global()->start(); return 0; }
static void readToken (tokenInfo *const token) { int c; vStringClear (token->string); getNextChar: c = getcFromInputFile (); while (isspace (c)) c = getcFromInputFile (); token->type = c; switch (c) { case EOF: token->type = TOKEN_EOF; break; case '\'': case '"': { const int delimiter = c; do { vStringPut (token->string, c); c = getcFromInputFile (); if (c == '\\') c = getcFromInputFile (); } while (c != EOF && c != delimiter); if (c != EOF) vStringPut (token->string, c); token->type = TOKEN_STRING; break; } case '/': /* maybe comment start */ { int d = getcFromInputFile (); if (d != '*') { ungetcToInputFile (d); vStringPut (token->string, c); token->type = c; } else { d = getcFromInputFile (); do { c = d; d = getcFromInputFile (); } while (d != EOF && ! (c == '*' && d == '/')); goto getNextChar; } break; } default: if (! isSelectorChar (c)) { vStringPut (token->string, c); token->type = c; } else { parseSelector (token->string, c); token->type = TOKEN_SELECTOR; } break; } }