예제 #1
0
void DocumentBuilder::consumeMisc(Node *root){
  consumeSpaces();
  bool hasTokens = true;
  while(hasTokens){
    if(isComment()){
      consumeComment(root);
      consumeSpaces();
    }else if(isPI()){
      consumePI(root);
      consumeSpaces();
    }else{
      hasTokens = false;
    }
  }
}
예제 #2
0
파일: lexer.cpp 프로젝트: mvila/liu
 Token *Lexer::nextToken() {
     while(true) {
         switch(_currentChar.toAscii()) {
         case '\'': return scanCharacter();
         case '"': return scanText();
         case '(': return scan(Token::LeftParenthesis);
         case ')': return scan(Token::RightParenthesis);
         case '[': return scan(Token::LeftBracket);
         case ']': return scanRightBracket();
         case '{': return scan(Token::LeftBrace);
         case '}': return scan(Token::RightBrace);
         case ';': return scan(Token::Semicolon);
         default:
             if(isEof()) return scan(Token::Eof);
             else if(isLineComment()) consumeLineComment();
             else if(isBlockComment()) consumeBlockComment();
             else if(isNewline()) return scanNewline();
             else if(isSpace()) consumeSpaces();
             else if(isName()) return scanName();
             else if(isBackquotedName()) return scanBackquotedName();
             else if(isNumber()) return scanNumber();
             else if(isOperator()) return scanOperator();
             else throw lexerException(QString("invalid character: '%1'").arg(_currentChar));
         }
     }
 }
예제 #3
0
파일: consume.c 프로젝트: openSUSE/fillup
/*--------------- consumeCommentLines --------------*\
|  This function returns the number of read 
|  characters that are part of comment lines,
|  additionaly a prefix of white spaces.
|  The characters are read from a stream/buffer and
|  the stream is length restricted.
\*--------------- consumeCommentLines --------------*/
long
consumeCommentLines
(
    char           * buffer,                  /* in */
    long             length                   /* in */
)
{
    long             commentMarkerStringLength;
    long             consumedLength;
    long             sumOfConsumedLength;
    char           * markerString;

    queryStringParameter( CommentMarker, &markerString );
    commentMarkerStringLength = stringLength( markerString );
    sumOfConsumedLength = 0;

    while( length > 0 )
    {
        consumedLength = consumeSpaces( buffer, length );
        sumOfConsumedLength += consumedLength;
        length -= consumedLength;
        buffer += consumedLength;

        if( length > commentMarkerStringLength )
        {
            if( Equal ==
                compareStringsExactly( markerString, buffer ) )
            {
                /* this is a comment line           */

                consumedLength = consumeUptoBreak( buffer, length );
                sumOfConsumedLength += consumedLength;
                length -= consumedLength;
                buffer += consumedLength;
            }
            else
            {
                break;

                /* this is a line that does not        */
                /* start with a comment marker string. */
            }
        }
        else
        {
            break;
            /* content of buffer is to short to     */
            /* hold the comment marker string.      */
        }
    }

    return( sumOfConsumedLength );
}
예제 #4
0
void DocumentBuilder::consumeXmlDecl(){
  wchar c1 = peek(0);
  wchar c2 = peek(1);
  if (c1 != '<' || c2 != '?') return;

  consume("<?xml", 5);
  consumeSpaces(1);

  consume("version", 7);
  consumeSpaces();
  consume("=", 1);
  consumeSpaces();
  delete consumeQoutedValue();

  consumeSpaces();

  if (peek() == 'e'){
    consume("encoding", 8);
    consumeSpaces();
    consume("=", 1);
    consumeSpaces();
    delete consumeQoutedValue();
  }

  consumeSpaces();

  if (peek() == 's'){
    consume("standalone", 10);
    consumeSpaces();
    consume("=", 1);
    consumeSpaces();
    delete consumeQoutedValue();
  }

  consumeSpaces();
  consume("?>", 2);
}
예제 #5
0
void DocumentBuilder::consumePI(Node *root){
  StringBuffer *sb = sb = new StringBuffer(40);
  consume("<?", 2);
  String * target = consumeNCName();
  consumeSpaces(1);
  while(peek(0) != '?' || peek(1) != '>'){
    if (peek(0) == -1){
      delete sb;
      get();
    }
    sb->append(get());
  }
  consume("?>", 2);
  root->appendChild(doc->createProcessingInstruction(target, sb));
}
예제 #6
0
void DocumentBuilder::consumeElement(Node *root){

  consume("<", 1);
  String *name = consumeName();
  Element *el = doc->createElement(name);
  root->appendChild(el);

  if (peek(0) == '/' && peek(1) == '>' || peek(0) == '>'){
    // no attributes
  }else{
    consumeSpaces(1);
    while(!(peek(0) == '/' && peek(1) == '>' || peek(0) == '>')){
      consumeSpaces();
      String *aname = consumeName();
      consumeSpaces();
      consume("=", 1);
      consumeSpaces();
      String *aval = consumeAttributeValue();
      consumeSpaces();
      el->setAttribute(aname, aval);
    }
  }

  if (peek(0) == '/' && peek(1) == '>'){
    consume("/>", 1);
  }else{
    consume(">", 1);

    consumeContent(el);

    consume("</", 2);
    consume(*name);
    consumeSpaces();
    consume(">", 1);
  }
}
예제 #7
0
void DocumentBuilder::consumeDTD(){
  wchar c1 = peek(0);
  wchar c2 = peek(1);
  if (c1 != '<' || c2 != '!') return;

  consume("<!DOCTYPE", 9);
  consumeSpaces(1);
  delete consumeNCName();

  consumeSpaces();
  if (peek() == 'S'){
    consume("SYSTEM", 6);
    consumeSpaces(1);
    delete consumeQoutedValue();
  }else if (peek() == 'P'){
    consume("PUBLIC", 6);
    consumeSpaces(1);
    delete consumeQoutedValue();
    consumeSpaces(1);
    delete consumeQoutedValue();
  }
  consumeSpaces();

  //markup decl
  if (peek() == '['){
    consume("[", 1);

    while(peek() != ']'){
      if (peek(0) == '<' && peek(1) == '!' && peek(2) == 'E'){
        consume("<!ENTITY", 8);
        consumeSpaces(1);
        String *entityName = consumeNCName();
        consumeSpaces(1);
        String *entityValue = null;
        String *extEntityValue = null;
        if (peek() == 'S'){
          consume("SYSTEM", 6);
          consumeSpaces(1);
          extEntityValue = consumeQoutedValue();
        }else if (peek() == 'P'){
          consume("PUBLIC", 6);
          consumeSpaces(1);
          delete consumeQoutedValue();
          consumeSpaces(1);
          extEntityValue = consumeQoutedValue();
        }else{
          entityValue = consumeQoutedValue();
        }
        if (entityValue != null){
          entitiesHash.put(entityName, entityValue);
        }
        if (extEntityValue != null){
          extEntitiesHash.put(entityName, extEntityValue);
        }
        delete entityName;

      }else if (isComment()){
        consumeComment(null);
      }
      get();
    }

    consume("]", 1);
    consumeSpaces();
  }


  consume(">", 1);

}