Warning, /kdevelop/kdev-css/parser/css.g is written in an unsupported language. File is not indexed.
0001 -- This file is part of KDevelop
0002 --
0003 -- Copyright 2009 Niko Sams <niko.sams@gmail.com>
0004 --
0005 -- This file is based on WebCore/css/CSSGrammar.y
0006 -- Copyright (C) 2002-2003 Lars Knoll (knoll@kde.org)
0007 -- Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
0008 -- Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
0009 -- Copyright (C) 2008 Eric Seidel <eric@webkit.org>
0010 --
0011 -- This library is free software; you can redistribute it and/or
0012 -- modify it under the terms of the GNU Lesser General Public
0013 -- License as published by the Free Software Foundation; either
0014 -- version 2 of the License, or (at your option) any later version.
0015 --
0016 -- This library is distributed in the hope that it will be useful,
0017 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
0018 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019 -- Lesser General Public License for more details.
0020 --
0021 -- You should have received a copy of the GNU Lesser General Public
0022 -- License along with this library; if not, write to the Free Software
0023 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0024 --
0025
0026 [:
0027 namespace Css
0028 {
0029 class ParseSession;
0030 }
0031 :]
0032
0033 %parser_declaration_header "QString"
0034 %parser_declaration_header "debug.h"
0035 %parser_declaration_header "language/duchain/problem.h"
0036 %parser_declaration_header "language/editor/documentrange.h"
0037
0038
0039
0040 ------------------------------------------------------------
0041 -- Export macro to use the parser in a shared lib
0042 ------------------------------------------------------------
0043 %export_macro "KDEVCSSPARSER_EXPORT"
0044 %export_macro_header "parserexport.h"
0045
0046
0047 ------------------------------------------------------------
0048 -- Enumeration types for additional AST members,
0049 -- in the global "Css" namespace
0050 ------------------------------------------------------------
0051 %namespace
0052 [:
0053 class Tokenizer;
0054 :]
0055
0056 ------------------------------------------------------------
0057 -- Parser class members
0058 ------------------------------------------------------------
0059
0060 %parserclass (public declaration)
0061 [:
0062 /**
0063 * Transform the raw input into tokens.
0064 * When this method returns, the parser's token stream has been filled
0065 * and any parse*() method can be called.
0066 */
0067 void tokenize(const QString& contents);
0068
0069 enum ProblemType {
0070 Error,
0071 Warning,
0072 Info
0073 };
0074 void reportProblem( Parser::ProblemType type, const QString& message );
0075 QList<KDevelop::ProblemPointer> problems() {
0076 return m_problems;
0077 }
0078 QString tokenText(qint64 begin, qint64 end);
0079 void setDebug(bool debug);
0080 void setCurrentDocument(const KDevelop::IndexedString& url);
0081
0082 :]
0083
0084 %parserclass (private declaration)
0085 [:
0086 QString m_contents;
0087 bool m_debug;
0088 KDevelop::IndexedString m_currentDocument;
0089 QList<KDevelop::ProblemPointer> m_problems;
0090 :]
0091
0092
0093
0094 -----------------------------------------------------------
0095 -- List of defined tokens
0096 -----------------------------------------------------------
0097
0098 -- keywords:<
0099 %token IMPORT_SYM ("@import"), PAGE_SYM ("@page"), MEDIA_SYM ("@media"),
0100 FONT_FACE_SYM ("@font-face"), CHARSET_SYM ("@charset"), NAMESPACE_SYM ("@namespace"),
0101 IMPORTANT_SYM ("!important") ;;
0102
0103 %token WHITESPACE ("whitespace"), IDENT ("identifier"), STRING ("string"), SGML_CD ("<!--/-->"),
0104 NOTFUNCTION ("not function"), URI ("uri"), FUNCTION ("function"), UNICODERANGE ("unicoderange"),
0105 HEXCOLOR ("hex color"), NTH ("nth"), IDSEL ("id selector"),
0106 MEDIA_NOT ("media not"), MEDIA_ONLY ("media only"), MEDIA_AND ("media and") ;;
0107
0108 -- seperators:
0109 %token COMMA (","), LPAREN ("("), RPAREN (")"), LBRACE ("{"), RBRACE ("}"),
0110 LBRACKET ("["), RBRACKET ("]"),
0111 COLON (":"), STAR("*"), SEMICOLON (";"), DOT ("."), EQUALS("="),
0112 INCLUDES ("~="), DASHMATCH ("|="), BEGINSWITH ("^="), ENDSWITH ("$="),
0113 CONTAINS ("*="), MINUS ("-"), PLUS ("+"), DIVIDE ("/") ;;
0114
0115 %token EMS ("em"), QEMS ("__qem"), EXS ("ex"), PXS ("ps"), CMS ("cm"), MMS ("mm"),
0116 INS ("in"), PTS ("pt"), PCS ("pc"), DEGS ("deg"), RADS ("rad"), GRADS ("grad"),
0117 MSECS ("ms"), SECS ("s"), HERZ ("Hz"), DPI ("dpi"), DPCM ("dpcm"), KHERZ ("kHz"),
0118 DIMEN ("dimen"), PERCENTAGE ("%"), INTEGER ("integer"), FLOAT ("float") ;;
0119
0120 -- token that makes the parser fail in any case:
0121 %token INVALID ("invalid token") ;;
0122
0123
0124
0125 -- The actual grammar starts here.
0126
0127 -- these rule isn't used by the parser, it's as ast node
0128 -- to support multiple style elements in one html file
0129 0
0130 -> html [
0131 member variable elements: QList<AstNode*>;
0132 ];;
0133
0134 start=start
0135 -> styleElement [
0136 member variable session: ParseSession*;
0137 ];;
0138
0139 declarationList=declarationList
0140 -> inlineStyle [
0141 member variable session: ParseSession*;
0142 ];;
0143 -- end custom rules
0144
0145
0146 (charset=charset | 0)
0147 maybeSgml
0148 imports=importList
0149 --variablesList
0150 --namespaceList
0151 rules=ruleList
0152 -> start ;;
0153
0154 WHITESPACE+ | 0
0155 -> maybeSpace ;;
0156
0157 maybeSpace (SGML_CD @ maybeSpace | 0)
0158 -> maybeSgml ;;
0159
0160
0161 -- closing_brace:
0162 -- '}'
0163 -- | %prec LOWEST_PREC TOKEN_EOF
0164 -- ;
0165
0166 CHARSET_SYM maybeSpace STRING maybeSpace SEMICOLON maybeSpace
0167 -> charset ;;
0168
0169 (#imports=import maybeSgml)*
0170 -> importList ;;
0171
0172 -- 0
0173 -- | variablesList variablesRule maybeSgml
0174 -- -> variablesList ;;
0175
0176 -- 0
0177 -- | namespaceList namespace maybeSgml
0178 ---> namespaceList ;;
0179
0180 (#rules=rule maybeSgml)*
0181 -> ruleList ;;
0182
0183 ruleset=ruleset
0184 -- | media
0185 -- | page
0186 -- | font_face
0187 -- | keyframes
0188 -> rule ;;
0189 --
0190 -- block_ruleList:
0191 -- /* empty */ { $$ = 0; }
0192 -- | block_ruleList block_rule maybeSgml
0193 -- ;
0194 --
0195 -- block_valid_rule:
0196 -- ruleset
0197 -- | page
0198 -- | font_face
0199 -- | keyframes
0200 -- ;
0201 --
0202 -- block_rule:
0203 -- block_valid_rule
0204 -- | invalid_rule
0205 -- | invalid_at
0206 -- | invalid_import
0207 -- | invalid_media
0208 -- ;
0209
0210 --IMPORT_SYM maybeSpace stringOrUri maybeSpace maybeMediaList SEMICOLON
0211 IMPORT_SYM maybeSpace stringOrUri maybeSpace SEMICOLON maybeSpace
0212 -> import ;;
0213
0214 -- variablesRule:
0215 -- WEBKIT_VARIABLES_SYM maybeSpace maybeMediaList '{' maybeSpace variables_declaration_list '}'
0216 -- |
0217 -- WEBKIT_DEFINE_SYM maybeSpace variables_mediaList '{' maybeSpace variables_declaration_list '}'
0218 -- ;
0219 --
0220 -- variables_mediaList:
0221 -- /* empty */
0222 -- |
0223 -- VARIABLES_FOR WHITESPACE mediaList
0224 -- ;
0225 --
0226 -- variables_declaration_list:
0227 -- variables_declaration
0228 -- | variables_decl_list variables_declaration
0229 -- | variables_decl_list
0230 -- | error invalid_block_list error
0231 -- | error
0232 -- | variables_decl_list error
0233 -- ;
0234 --
0235 -- variables_decl_list:
0236 -- variables_declaration ';' maybeSpace
0237 -- | variables_declaration invalid_block_list ';' maybeSpace
0238 -- | error ';' maybeSpace
0239 -- | error invalid_block_list error ';' maybeSpace
0240 -- | variables_decl_list variables_declaration ';' maybeSpace
0241 -- | variables_decl_list error ';' maybeSpace
0242 -- | variables_decl_list error invalid_block_list error ';' maybeSpace
0243 -- ;
0244 --
0245 -- variables_declaration:
0246 -- variable_name ':' maybeSpace expr
0247 -- |
0248 -- variable_name maybeSpace '{' maybeSpace declaration_list '}' maybeSpace
0249 -- |
0250 -- variable_name error
0251 -- |
0252 -- variable_name ':' maybeSpace error expr
0253 -- |
0254 -- variable_name ':' maybeSpace /* @variables { varname: } Just reduce away this variable with no value. */
0255 -- |
0256 -- variable_name ':' maybeSpace error /* if we come across rules with invalid values like this case: @variables { varname: *; }, just discard the property/value pair */
0257 -- ;
0258 --
0259 -- variable_name:
0260 -- IDENT maybeSpace
0261 -- ;
0262 --
0263 -- namespace:
0264 -- NAMESPACE_SYM maybeSpace maybe_ns_prefix stringOrUri maybeSpace ';'
0265 -- | NAMESPACE_SYM error invalid_block
0266 -- | NAMESPACE_SYM error ';'
0267 -- ;
0268 --
0269 -- maybe_ns_prefix:
0270 -- /* empty */
0271 -- | IDENT WHITESPACE
0272 -- ;
0273
0274 string=STRING
0275 | uri=URI
0276 -> stringOrUri ;;
0277
0278 -- media_feature:
0279 -- IDENT maybeSpace
0280 -- ;
0281 --
0282 -- maybe_media_value:
0283 -- /*empty*/
0284 -- | ':' maybeSpace expr maybeSpace
0285 -- ;
0286 --
0287 -- mediaQuery_exp:
0288 -- '(' maybeSpace media_feature maybeSpace maybe_media_value ')' maybeSpace
0289 -- ;
0290 --
0291 -- mediaQueryExpList:
0292 -- mediaQuery_exp
0293 -- | mediaQueryExpList maybeSpace MEDIA_AND maybeSpace mediaQuery_exp
0294 -- ;
0295 --
0296 -- maybe_and_mediaQueryExpList:
0297 -- /*empty*/
0298 -- | MEDIA_AND maybeSpace mediaQueryExpList
0299 -- ;
0300 --
0301 -- maybe_media_restrictor:
0302 -- /*empty*/
0303 -- | MEDIA_ONLY
0304 -- | MEDIA_NOT
0305 -- ;
0306 --
0307 -- mediaQuery:
0308 -- mediaQueryExpList
0309 -- |
0310 -- maybe_media_restrictor maybeSpace medium maybe_and_mediaQueryExpList
0311 -- ;
0312
0313 -- 0
0314 -- | mediaList
0315 ---> maybeMediaList ;;
0316
0317 -- mediaQuery
0318 -- | mediaList COMMA maybeSpace mediaQuery
0319 -- | mediaList error
0320 ---> mediaList ;;
0321
0322 -- media:
0323 -- MEDIA_SYM maybeSpace mediaList '{' maybeSpace block_ruleList save_block
0324 -- | MEDIA_SYM maybeSpace '{' maybeSpace block_ruleList save_block
0325 -- ;
0326 --
0327 -- medium:
0328 -- IDENT maybeSpace
0329 -- ;
0330 --
0331 -- keyframes:
0332 -- WEBKIT_KEYFRAMES_SYM maybeSpace keyframe_name maybeSpace '{' maybeSpace keyframes_rule '}'
0333 -- ;
0334 --
0335 -- keyframe_name:
0336 -- IDENT
0337 -- | STRING
0338 -- ;
0339 --
0340 -- keyframes_rule:
0341 -- /* empty */
0342 -- | keyframes_rule keyframe_rule maybeSpace
0343 -- ;
0344 --
0345 -- keyframe_rule:
0346 -- key_list maybeSpace '{' maybeSpace declaration_list '}'
0347 -- ;
0348 --
0349 -- key_list:
0350 -- key
0351 -- | key_list maybeSpace ',' maybeSpace key
0352 -- ;
0353 --
0354 -- key:
0355 -- PERCENTAGE
0356 -- | IDENT
0357 -- ;
0358 --
0359 -- /*
0360 -- page:
0361 -- PAGE_SYM maybeSpace IDENT? pseudo_page? maybeSpace
0362 -- '{' maybeSpace declaration [ ';' maybeSpace declaration ]* '}' maybeSpace
0363 -- ;
0364 --
0365 -- pseudo_page
0366 -- : ':' IDENT
0367 -- ;
0368 -- */
0369 --
0370 -- page:
0371 -- PAGE_SYM error invalid_block
0372 -- | PAGE_SYM error ';'
0373 -- ;
0374 --
0375 -- font_face:
0376 -- FONT_FACE_SYM maybeSpace
0377 -- '{' maybeSpace declaration_list '}' maybeSpace
0378 -- | FONT_FACE_SYM error invalid_block
0379 -- | FONT_FACE_SYM error ';'
0380 -- ;
0381 --
0382 -- combinator:
0383 -- '+' maybeSpace
0384 -- | '~' maybeSpace
0385 -- | '>' maybeSpace
0386 -- ;
0387
0388 MINUS
0389 | PLUS
0390 -> unaryOperator ;;
0391
0392 selectors=selectorList (lbrace=LBRACE | 0 [: reportProblem( Error, "Expected '{'" ); :]) maybeSpace declarations=declarationList
0393 ( rbrace=RBRACE
0394 | 0 [: reportProblem( Error, "Expected '}'" ); :])
0395 -> ruleset ;;
0396
0397 --selector %prec UNIMPORTANT_TOK
0398 -- | selectorList ',' maybeSpace selector %prec UNIMPORTANT_TOK
0399 -- | selectorList error
0400 #selectors=selector
0401 @ (COMMA maybeSpace
0402 [: if(LA(1).kind == Token_LBRACE || LA(1).kind == Token_EOF) {
0403 reportProblem( Error, "Expected Selector" );
0404 break;}
0405 :])
0406 -> selectorList ;;
0407
0408 -- | selector combinator simpleSelector
0409 -- | selector error
0410 simpleSelector=simpleSelectorWithWhitespace+
0411 -> selector ;;
0412
0413 simpleSelector=simpleSelector maybeSpace
0414 -> simpleSelectorWithWhitespace ;;
0415
0416 -- /* empty */ '|'
0417 -- | STAR '|'
0418 -- | IDENT '|'
0419 -- -> namespaceSelector ;;
0420
0421 element=elementName (specifier=specifierList | 0)
0422 | specifier=specifierList
0423 -- | namespace_selector elementName
0424 -- | namespace_selector elementName specifierList
0425 -- | namespace_selector specifierList
0426 -> simpleSelector ;;
0427
0428 ident=IDENT | star=STAR
0429 -> elementName ;;
0430
0431 (#specifiers=specifier)+
0432 -> specifierList ;;
0433
0434 DOT ( className=IDENT | INVALID [: reportProblem( Error, "Invalid Token" ); :] )
0435 | attrib=attrib
0436 | pseudo=pseudo
0437 | idSel=IDSEL
0438 -- | HEX
0439 -> specifier ;;
0440
0441 -- | LBRACKET maybeSpace namespace_selector IDENT maybeSpace RBRACKET
0442 -- | LBRACKET maybeSpace namespace_selector IDENT maybeSpace match maybeSpace identOrString maybeSpace RBRACKET
0443 LBRACKET
0444 maybeSpace attrName=IDENT maybeSpace
0445 (match=match maybeSpace ident=identOrString maybeSpace | 0)
0446 RBRACKET
0447 -> attrib ;;
0448
0449 EQUALS
0450 | INCLUDES
0451 | DASHMATCH
0452 | BEGINSWITH
0453 | ENDSWITH
0454 | CONTAINS
0455 -> match ;;
0456
0457 ident=IDENT
0458 | string=STRING
0459 -> identOrString ;;
0460
0461 COLON (
0462 ident=IDENT
0463 | FUNCTION (
0464 NTH --used by :nth-*(ax+b)
0465 | INTEGER --used by :nth-*
0466 | IDENT --used by :nth-*(odd/even) and :lang
0467 ) RPAREN
0468 | NOTFUNCTION maybeSpace simpleSelector maybeSpace RPAREN --used by :not
0469 | COLON ident=IDENT --used by ::selection (I guess)
0470 )
0471 -> pseudo ;;
0472
0473 (#declarations=declaration)+ | 0
0474 -> declarationList ;;
0475
0476 -- variable_reference maybeSpace
0477 -- |
0478 -- property error
0479 -- |
0480 -- property ':' maybeSpace error expr prio {
0481 -- /* The default movable type template has letter-spacing: .none; Handle this by looking for
0482 -- error tokens at the start of an expr, recover the expr and then treat as an error, cleaning
0483 -- up and deleting the shifted expr. */
0484 -- $$ = false;
0485 -- }
0486 -- |
0487 -- property ':' maybeSpace expr prio error {
0488 -- /* When we encounter something like p {color: red !important fail;} we should drop the declaration */
0489 -- $$ = false;
0490 -- }
0491 -- |
0492 -- IMPORTANT_SYM maybeSpace {
0493 -- /* Handle this case: div { text-align: center; !important } Just reduce away the stray !important. */
0494 -- $$ = false;
0495 -- }
0496 -- |
0497 -- property ':' maybeSpace {
0498 -- /* div { font-family: } Just reduce away this property with no value. */
0499 -- $$ = false;
0500 -- }
0501 -- |
0502 -- property ':' maybeSpace error {
0503 -- /* if we come across rules with invalid values like this case: p { weight: *; }, just discard the rule */
0504 -- $$ = false;
0505 -- }
0506 -- |
0507 -- property invalid_block {
0508 -- /* if we come across: div { color{;color:maroon} }, ignore everything within curly brackets */
0509 -- $$ = false;
0510 -- }
0511 property=property
0512 (colon=COLON | 0 [: reportProblem( Error, "Expected Colon" ); :])
0513 maybeSpace
0514 --don't parse next property as expr (happens if there is no expr and semicolon)
0515 [: if (LA(2).kind != Token_COLON && !(LA(2).kind == Token_WHITESPACE && LA(3).kind == Token_COLON)) { :]
0516 expr=expr prio
0517 (semicolon=SEMICOLON | 0 )
0518 maybeSpace
0519 [: } :]
0520 -> declaration ;;
0521
0522
0523 maybeSpace ident=IDENT maybeSpace
0524 -> property ;;
0525
0526 IMPORTANT_SYM maybeSpace | 0
0527 -> prio ;;
0528
0529
0530 -- term+ as adding |0 to operator gives a conflict
0531 #terms=term+ @ operator
0532 | 0 [: reportProblem( Error, "Expected exprssion" ); :]
0533 -> expr ;;
0534
0535 DIVIDE maybeSpace
0536 | COMMA maybeSpace
0537 | EQUALS maybeSpace --non standard, for eg. filter: alpha(opacity=0);
0538 -> operator ;;
0539
0540 -- | '#' maybeSpace /* Handle error case: "color: #;" */
0541 -- | variable_reference maybeSpace
0542 -- | '%' maybeSpace /* Handle width: %; */
0543 string=STRING maybeSpace
0544 | ident=IDENT maybeSpace
0545 | (op=unaryOperator | 0) (term=unaryTerm | DIMEN)
0546 | uri=URI maybeSpace
0547 | unicoderange=UNICODERANGE maybeSpace
0548 | hexcolor=hexcolor
0549 | function=function -- /* FIXME: according to the specs a function can have a unaryOperator in front. I know no case where this makes sense */
0550 -> term ;;
0551
0552
0553 value=INTEGER maybeSpace
0554 | value=FLOAT maybeSpace
0555 | value=PERCENTAGE maybeSpace
0556 | value=PXS maybeSpace
0557 | value=CMS maybeSpace
0558 | value=MMS maybeSpace
0559 | value=INS maybeSpace
0560 | value=PTS maybeSpace
0561 | value=PCS maybeSpace
0562 | value=DEGS maybeSpace
0563 | value=RADS maybeSpace
0564 | value=GRADS maybeSpace
0565 | value=MSECS maybeSpace
0566 | value=SECS maybeSpace
0567 | value=HERZ maybeSpace
0568 | value=KHERZ maybeSpace
0569 | value=EMS maybeSpace
0570 | value=QEMS maybeSpace
0571 | value=EXS maybeSpace
0572 -- | TURNS maybeSpace
0573 -- | REMS maybeSpace
0574 -> unaryTerm ;;
0575
0576
0577 -- variable_reference:
0578 -- VARCALL
0579 -- ;
0580
0581 FUNCTION maybeSpace expr RPAREN maybeSpace
0582 --|
0583 --FUNCTION maybeSpace error
0584 -> function ;;
0585
0586
0587 -- /*
0588 -- * There is a constraint on the color that it must
0589 -- * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
0590 -- * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
0591 -- */
0592 HEXCOLOR maybeSpace
0593 -- | IDSEL maybeSpace
0594 -> hexcolor ;;
0595
0596
0597
0598 -----------------------------------------------------------------
0599 -- Code segments copied to the implementation (.cpp) file.
0600 -- If existent, kdevelop-pg's current syntax requires this block
0601 -- to occur at the end of the file.
0602 -----------------------------------------------------------------
0603
0604 [:
0605
0606 #include <KTextEditor/Range>
0607 #include <debug.h>
0608 #include "tokenizer.h"
0609
0610 namespace Css
0611 {
0612
0613 void Parser::tokenize(const QString& contents)
0614 {
0615 m_contents = contents;
0616
0617 Tokenizer tokenizer(tokenStream, contents.toLatin1().data());
0618
0619 int kind = Parser::Token_EOF;
0620 do
0621 {
0622 kind = tokenizer.yylex();
0623
0624 if ( !kind ) // when the lexer returns 0, the end of file is reached
0625 {
0626 kind = Parser::Token_EOF;
0627 }
0628 Parser::Token &t = tokenStream->push();
0629 t.begin = tokenizer.tokenBegin();
0630 t.end = tokenizer.tokenEnd();
0631 t.kind = kind;
0632 //if ( m_debug ) qCDebug(KDEV_CSS) << kind << tokenText(t.begin,t.end) << t.begin << t.end;
0633 }
0634 while ( kind != Parser::Token_EOF );
0635
0636 yylex(); // produce the look ahead token
0637 }
0638
0639
0640 QString Parser::tokenText(qint64 begin, qint64 end)
0641 {
0642 return m_contents.mid(begin,end-begin+1);
0643 }
0644
0645
0646 void Parser::reportProblem( Parser::ProblemType type, const QString& message )
0647 {
0648 if (type == Error)
0649 qCDebug(KDEV_CSS) << "** ERROR:" << message;
0650 else if (type == Warning)
0651 qCWarning(KDEV_CSS) << "** WARNING:" << message;
0652 else if (type == Info)
0653 #if QT_VERSION >= 0x050500
0654 qCInfo(KDEV_CSS) << "** Info:" << message;
0655 #else
0656 qCDebug(KDEV_CSS) << "** Info:" << message;
0657 #endif
0658
0659 qint64 sLine;
0660 qint64 sCol;
0661 qint64 index = tokenStream->index()-1;
0662 tokenStream->startPosition(index, &sLine, &sCol);
0663 qint64 eLine;
0664 qint64 eCol;
0665 tokenStream->endPosition(index, &eLine, &eCol);
0666 KDevelop::Problem *p = new KDevelop::Problem();
0667 p->setSource(KDevelop::IProblem::Parser);
0668 switch ( type ) {
0669 case Error:
0670 p->setSeverity(KDevelop::IProblem::Error);
0671 break;
0672 case Warning:
0673 p->setSeverity(KDevelop::IProblem::Warning);
0674 break;
0675 case Info:
0676 p->setSeverity(KDevelop::IProblem::Hint);
0677 break;
0678 }
0679 p->setDescription(message);
0680 p->setFinalLocation({m_currentDocument, KTextEditor::Range(sLine, sCol, eLine, eCol+1)});
0681 m_problems << KDevelop::ProblemPointer(p);
0682 }
0683
0684
0685 // custom error recovery
0686 void Parser::expectedToken(int /*expected*/, qint64 /*where*/, const QString& name)
0687 {
0688 reportProblem( Parser::Error, QString("Expected token \"%1\"").arg(name));
0689 }
0690
0691 void Parser::expectedSymbol(int /*expectedSymbol*/, const QString& name)
0692 {
0693 qint64 line;
0694 qint64 col;
0695 qint64 index = tokenStream->index()-1;
0696 Token &token = tokenStream->at(index);
0697 qCDebug(KDEV_CSS) << "token starts at:" << token.begin;
0698 qCDebug(KDEV_CSS) << "index is:" << index;
0699 tokenStream->startPosition(index, &line, &col);
0700 QString tokenValue = tokenText(token.begin, token.end);
0701 qint64 eLine;
0702 qint64 eCol;
0703 tokenStream->endPosition(index, &eLine, &eCol);
0704 reportProblem( Parser::Error,
0705 QString("Expected symbol \"%1\" (current token: \"%2\" [%3] at %4:%5 - %6:%7)")
0706 .arg(name)
0707 .arg(token.kind != 0 ? tokenValue : "EOF")
0708 .arg(token.kind)
0709 .arg(line)
0710 .arg(col)
0711 .arg(eLine)
0712 .arg(eCol));
0713 }
0714
0715 void Parser::setDebug( bool debug )
0716 {
0717 m_debug = debug;
0718 }
0719
0720 void Parser::setCurrentDocument(const KDevelop::IndexedString& url)
0721 {
0722 m_currentDocument = url;
0723 }
0724
0725 } // end of namespace Css
0726
0727 :]
0728
0729 -- kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on