예제 #1
0
void Scanner::readQuotedString( YYSTYPE & lval )
//----------------------------------------------
{
    const int   MaxBufLen = 512;
    char        buffer[ MaxBufLen ];
    int         bufPos;         // position in buffer
    char *      dupStr;

    get();  // move past "

    for( bufPos = 0; bufPos < MaxBufLen; bufPos += 1 ) {
        if( isQuote() || isEOF() ) break;
        buffer[ bufPos ] = (char) _current;
        get();
    }

    if( isQuote() ) {
        get();  // eat the quote
    }

    assert( bufPos < MaxBufLen );

    buffer[ bufPos ] = '\0';

    dupStr = new char[ strlen( buffer ) + 1 ];
    strcpy( dupStr, buffer );

    lval =  (YYSTYPE) _strings->size();
    _strings->push_back( dupStr );
}
예제 #2
0
QString BraceMatcher::insertMatchingBrace(const QTextCursor &cursor,
                                          const QString &text,
                                          const QChar la,
                                          int *skippedChars) const
{
    if (text.length() != 1)
        return QString();

    if (!shouldInsertMatchingText(cursor))
        return QString();

    const QChar ch = text.at(0);
    if (isQuote(ch)) {
        if (la != ch)
            return QString(ch);
        ++*skippedChars;
        return QString();
    }

    if (isOpeningBrace(ch))
        return QString(m_braceChars[ch]);

    if (isDelimiter(ch) || isClosingBrace(ch)) {
        if (la == ch)
            ++*skippedChars;
    }

    return QString();
}
예제 #3
0
bool BraceMatcher::shouldInsertMatchingText(const QChar lookAhead) const
{
    return lookAhead.isSpace()
        || isQuote(lookAhead)
        || isDelimiter(lookAhead)
        || isClosingBrace(lookAhead);
}
예제 #4
0
/**
 * Lex the string into tokens, each of which has a given offset into the string.
 * Lexing is done by the following algorithm:
 *  (1) If the current character is a space, and if it is then check the next:
 *  	(a) If it is another space, then the token is a tab.
 *	(b) If it is some other character, the token is a space.
 *  (2) If the current character is a character (either upper or lower case), or a digit,
 *	 then continue until the first non-matching character and that is an ident.
 *  (3) If the current character is a #, then ignore everything until the end of the line.
 *  (4) If the current character is a newline, then the token is a newline.
 *  (5) If the current character is a colon, then the token is just a colon.
 *  (6) If the current character is a quote, then read until the endquote and
 *	 declare the string as the contents of the string.
 */
Token* lex(char* input, int len) {
    Token* first = newToken(0, 0, 0);
    Token* last = first;
    int index = 0;
    while (index < len-1) {
        //printf("*");
        int start = index;
        char cur = input[index];
        if (isSpace(cur)) {
            if (isSpace(input[index+1])) {
                index++;
                addNewToken(last, TAB, start, index);
            } else {
                addNewToken(last, SPACE, index, index);
            }
            index++;
        } else if (isTab(cur)) {
            index++;
            addNewToken(last, TAB, start, index);
        } else if (isChar(cur)) {
            while (isChar(input[++index]));
            addNewToken(last, IDENT, start, index);
        } else if (isComment(cur)) {
            while (!isNewLine(input[++index]));
        } else if (isNewLine(cur)) {
            index++;
            addNewToken(last, NEWLINE, index, index);
        } else if (isColon(cur)) {
            index++;
            addNewToken(last, COLON, index, index);
        } else if (isQuote(cur)) {
            while (!isQuote(input[++index]));
            addNewToken(last, STRING, start+1, index);
            index++; /* Pass by the end quote. */
        }
        if (last->next != NULL)
            last = last->next;
    }
    addNewToken(last, NEWLINE, index, index);

    return first->next;
}
예제 #5
0
inline bool ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseStringTo(
    JsonVariant *destination) {
  bool hasQuotes = isQuote(_reader.current());
  const char *value = parseString();
  if (value == NULL) return false;
  if (hasQuotes) {
    *destination = value;
  } else {
    *destination = RawJson(value);
  }
  return true;
}
예제 #6
0
파일: clojure.c 프로젝트: lizh06/ctags
static void functionName (vString * const name, const char *dbp)
{
	const char *p;

	if (*dbp == '\'')
		dbp++;
	else if (*dbp == '(' && isQuote (dbp))
	{
		dbp += 7;
		while (isspace (*dbp))
			dbp++;
	}

	for (p = dbp; *p != '\0' && *p != '(' && !isspace ((int) *p) && *p != ')';
		p++)
		vStringPut (name, *p);
}
예제 #7
0
inline const char *
ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseString() {
  typename TypeTraits::RemoveReference<TWriter>::type::String str =
      _writer.startString();

  skipSpacesAndComments(_reader);
  char c = _reader.current();

  if (isQuote(c)) {  // quotes
    _reader.move();
    char stopChar = c;
    for (;;) {
      c = _reader.current();
      if (c == '\0') break;
      _reader.move();

      if (c == stopChar) break;

      if (c == '\\') {
        // replace char
        c = Encoding::unescapeChar(_reader.current());
        if (c == '\0') break;
        _reader.move();
      }

      str.append(c);
    }
  } else {  // no quotes
    for (;;) {
      if (!isLetterOrNumber(c)) break;
      _reader.move();
      str.append(c);
      c = _reader.current();
    }
  }

  return str.c_str();
}
예제 #8
0
Lexeme Lexal::getNext()
{
    skipSpaces();
    if (reader.isEof())
        return Lexeme(Lexeme::Eof, L"", line, pos);

    int startLine = line;
    int startPos = pos;

    wchar_t ch = reader.getNextChar();
    pos++;

    if (isIdentStart(ch))
        return readIdent(startLine, startPos, ch);
    else if (isDigit(ch))
        return readNumber(startLine, startPos, ch);
    else if (isQuote(ch))
        return readString(startLine, startPos, ch);
    else if (isSymbol(ch))
        return Lexeme(Lexeme::Symbol, toString(ch), startLine, startPos);
    
    throw Exception(L"Invalid character at "+ posToStr(startLine, startPos));
}
예제 #9
0
short Scanner::getToken( YYSTYPE & lval )
//---------------------------------------
// get the next token from the input stream.
// at each call, the next character should be
// in _current.
{
    const int   MaxBufLen = 512;
    char        buffer[ MaxBufLen ];
    int         bufPos;                 // position in buffer
    char        special;

    gobble();

    if( isEOF() ) {
        return 0;
    }

    if( isSpecial() ) {
        special = (char) _current;
        get();                      // set up for next call
        return special;   // <-------- early return
    }

    if( isQuote() ) {
        readQuotedString( lval );
        return T_String;   // <-------- early return
    }

    if( _current == '0' ) {
        get();
        if( toupper( _current ) == 'X' ) {
            readHex( lval );
        } else {
            if( isDigit() ) {
                readDecimal( lval );
            } else {
                lval = 0;
            }
        }
        return T_Number;   // <-------- early return
    }

    if( isDigit() ) {
        readDecimal( lval );
        return T_Number;   // <-------- early return
    }

    for( bufPos = 0; bufPos < MaxBufLen; bufPos += 1 ) {
        buffer[ bufPos ] = (char) _current;

        get();
        if( isEOF() || isSpace() || isSpecial() ) break;
    }

    bufPos += 1;

    assert( bufPos < MaxBufLen );

    buffer[ bufPos ] = '\0';

    return tokenValue( buffer, lval );
}
예제 #10
0
/*!
 * Returns true if given character was added as one of character types.
 */
bool BraceMatcher::isKnownChar(const QChar c) const
{
    return isQuote(c) || isDelimiter(c) || isOpeningBrace(c) || isClosingBrace(c);
}
예제 #11
0
파일: lexan.c 프로젝트: 36Chambers/xinu-arm
/**
 * Ad hoc lexical analyzer to divide command line into tokens
 * @param *line   pointer to line to parse
 * @param linelen length of line to parse
 * @param *tokbuf buffer for tokens 
 * @param *tok[]  array of pointers into token buffer
 * @return number of tokens created
 */
short lexan(char *line, ushort linelen, char *tokbuf, char *tok[])
{
    char quote;                 /* character for quoted string  */
    ushort ntok = 0;            /* number of tokens parsed      */
    ushort i = 0;               /* temp variable                */

    while ((i < linelen) && (ntok < SHELL_MAXTOK))
    {
        /* Skip whitespace in line of input */
        while (isWhitespace(line[i]) && (i < linelen))
        {
            i++;
        }

        /* Stop parsing at end of line */
        if (isEndOfLine(line[i]) || (i >= linelen))
        {
            return ntok;
        }

        /* Set token to point to value in token buffer */
        tok[ntok] = tokbuf;

        /* Handle quoted string */
        if (isQuote(line[i]))
        {
            quote = *tokbuf++ = line[i++];

            while ((quote != line[i])
                   && (!isEndOfLine(line[i])) && (i < linelen))
            {
                *tokbuf++ = line[i++];
            }

            if (quote == line[i])
            {
                *tokbuf++ = line[i++];
            }
            else
            {
                return SYSERR;
            }
        }
        else
        {
            *tokbuf++ = line[i++];

            /* Handle standard alphanumeric token */
            if (!isOtherSpecial(line[i - 1]))
            {
                while ((!isEndOfLine(line[i])) && (!isQuote(line[i]))
                       && (!isOtherSpecial(line[i]))
                       && (!isWhitespace(line[i])) && (i < linelen))
                {
                    *tokbuf++ = line[i++];
                }

                if (i >= linelen)
                    return SYSERR;
            }
        }

        /* Finish current token */
        *tokbuf++ = '\0';
        ntok++;
    }

    return ntok;
}
예제 #12
0
파일: isalpha.cpp 프로젝트: coolda/plmcore
bool isAlNumQuote(char c ) {
	return isAlpha(c) || isNum(c) || isQuote(c);
}