当前位置: 首页>>代码示例>>C++>>正文


C++ peek_char函数代码示例

本文整理汇总了C++中peek_char函数的典型用法代码示例。如果您正苦于以下问题:C++ peek_char函数的具体用法?C++ peek_char怎么用?C++ peek_char使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了peek_char函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: peek_char

bool Lexer::lex_identifier(FILE * fp) {
    Token token;
    token.filename = current_filename;
	token.line_number = current_line;
	token.column_number = current_column;
    token.type = TOKEN_IDENT;
    char cur = peek_char(fp);
    char buf[256];
    int i = 0;
    while (cur && isalnum(cur)) {
        if (!(i < 256)) {
            REPORT_TOKEN_ERROR("Identifier exceeds limit of 256 characters.", token);
            return false;
        }
		next_char(fp); // eat current char

        buf[i] = cur;
        i++;
        cur = peek_char(fp);
    }

    make_token_text(&token, buf, i);
    tokens.push_back(token);
    return true;
}
开发者ID:ACEfanatic02,项目名称:CInterp,代码行数:25,代码来源:Lexer.cpp

示例2: parse_escaped_word_item

/* This function is a bit messy unfortunately since it does efficient in-place parsing of "words"
 * with escape codes. When escape codes are encountered, it collapses them to the actual character
 * value in-place in memory. The token data generated from this operation points to the word within
 * the stream data memory. */
void parse_escaped_word_item(struct tml_stream *stream, struct tml_token *token)
{
    char *word_start = &stream->data[stream->index];
    char *p = word_start;
    bool shift_necessary = false;

    /* scan the word, collapsing escape codes in-place if necessary */
    int ch = peek_char(stream);
    while (ch != ' ' && ch != '\t' && ch != -1 &&
            ch != TML_DIVIDER_CHAR && ch != TML_OPEN_CHAR && ch != TML_CLOSE_CHAR)
    {
        if (ch == TML_ESCAPE_CHAR) {
            /* substitute 2-character escape code with the character it represents */
            next_char(stream);
            ch = peek_char(stream);
            if (ch == -1) break;
            *p = translate_escape_code(ch);
            shift_necessary = true;
        }
        else if (shift_necessary) {
            /* shift character to the left collapsed position */
            *p = (ch = peek_char(stream));
        }

        /* go on to the next potential character */
        p++;
        next_char(stream);
        ch = peek_char(stream);
    }

    /* return a reference to the data slice */
    token->type = TML_TOKEN_ITEM;
    token->value = word_start;
    token->value_size = (p - word_start);
}
开发者ID:judnich,项目名称:TupleMarkup,代码行数:39,代码来源:tml_tokenizer.c

示例3: get_number

struct Token get_number(char c)
{
    struct Token token;
    BOOLEAN isReal = FALSE;
    int i = 1;


    token.tokenCode = NUMBER;
    token.literalValue.valString[0] = c;

    while(char_table[peek_char()] == DIGIT || peek_char() == '.' || peek_char() == 'e'|| peek_char() == '-') {
        c = get_char();
        token.literalValue.valString[i] = c;
        isReal = (c == '.' || c == 'e' || c == '-')? TRUE : isReal;
        i++;
    }

    for(i; i<MAX_TOKEN_STRING_LENGTH; i++) {
        token.literalValue.valString[i] = '\0';
    }

    if(isReal) {
        token.literalType = REAL_LIT;
    } else {
        token.literalType = INTEGER_LIT;
        token.literalValue.valInt = atoi(token.literalValue.valString);
    }

    return token;
}
开发者ID:rgonza26,项目名称:3rdLab,代码行数:30,代码来源:scanner.c

示例4: get_args

static bool get_args (const char **s, const char *keyw, uint32 *args, uint count)
{
  if (!count)
    return true;

  if (peek_char (s) != '(')
  {
    ScriptError("%s(%d args) expected", keyw, count);
    return false;
  }

  (*s)++;
  while (count--)
  {
    if (!get_expression (s, args, 0, count ? 0 : PAREN_EXPECT | PAREN_EAT))
    {
error:
      ScriptError("not enough arguments to function %s", keyw);
      return false;
    }

    if (!count)
      break;

    if (peek_char (s) != ',')
      goto error;

    (*s)++;
    args++;
  }

  return true;
}
开发者ID:MeiDahua,项目名称:Haret-for-HTC-Mega,代码行数:33,代码来源:script.cpp

示例5: read_character

static object read_character(FILE *in)
{
	int c = fgetc(in);

	switch (c) {
	case EOF:
		error("Unexpected EOF -- read", nil);
		break;

	case 's':
	case 'S':
		if (tolower(peek_char(in)) == 'p') {
			expect_string(in, "pace");
			peek_char_expect_delimiter(in);
			return make_character(' ');
		}
	        break;

	case 'n':
	case 'N':
		if (tolower(peek_char(in)) == 'e') {
			expect_string(in, "ewline");
			peek_char_expect_delimiter(in);
			return make_character('\n');
		}
	        break;
	}

	peek_char_expect_delimiter(in);
	return make_character(c);
}
开发者ID:cmatei,项目名称:yalfs,代码行数:31,代码来源:io.c

示例6: skip_spaces

static CMARK_INLINE bool skip_spaces(subject *subj) {
  bool skipped = false;
  while (peek_char(subj) == ' ' || peek_char(subj) == '\t') {
    advance(subj);
    skipped = true;
  }
  return skipped;
}
开发者ID:rhinoman,项目名称:go-commonmark,代码行数:8,代码来源:inlines.c

示例7: cmark_parse_reference_inline

// Parse reference.  Assumes string begins with '[' character.
// Modify refmap if a reference is encountered.
// Return 0 if no reference found, otherwise position of subject
// after reference is parsed.
int cmark_parse_reference_inline(cmark_strbuf *input, cmark_reference_map *refmap)
{
	subject subj;

	cmark_chunk lab;
	cmark_chunk url;
	cmark_chunk title;

	int matchlen = 0;
	int beforetitle;

	subject_from_buf(&subj, input, NULL);

	// parse label:
	if (!link_label(&subj, &lab))
		return 0;

	// colon:
	if (peek_char(&subj) == ':') {
		advance(&subj);
	} else {
		return 0;
	}

	// parse link url:
	spnl(&subj);
	matchlen = scan_link_url(&subj.input, subj.pos);
	if (matchlen) {
		url = cmark_chunk_dup(&subj.input, subj.pos, matchlen);
		subj.pos += matchlen;
	} else {
		return 0;
	}

	// parse optional link_title
	beforetitle = subj.pos;
	spnl(&subj);
	matchlen = scan_link_title(&subj.input, subj.pos);
	if (matchlen) {
		title = cmark_chunk_dup(&subj.input, subj.pos, matchlen);
		subj.pos += matchlen;
	} else {
		subj.pos = beforetitle;
		title = cmark_chunk_literal("");
	}
	// parse final spaces and newline:
	while (peek_char(&subj) == ' ') {
		advance(&subj);
	}
	if (peek_char(&subj) == '\n') {
		advance(&subj);
	} else if (peek_char(&subj) != 0) {
		return 0;
	}
	// insert reference into refmap
	cmark_reference_create(refmap, &lab, &url, &title);
	return subj.pos;
}
开发者ID:lowks,项目名称:cmark.ex,代码行数:62,代码来源:inlines.c

示例8: spnl

// Parse zero or more space characters, including at most one newline.
static void spnl(subject* subj)
{
	bool seen_newline = false;
	while (peek_char(subj) == ' ' ||
	       (!seen_newline &&
	        (seen_newline = peek_char(subj) == '\n'))) {
		advance(subj);
	}
}
开发者ID:lowks,项目名称:cmark.ex,代码行数:10,代码来源:inlines.c

示例9: while

void analyzer::drop_garbage()
{
    if( peek_char() == EOF )return ;
    while(true){
        char c = read_char();
        if( !isspace(c) ){
            if( c == '/' ){
                if( peek_char() == EOF ){
                    restore_char();
                    return ;
                }
                char cc = read_char();
                if( cc == '/' ){//drop until new line is found
                    while(true){
                        cc = read_char();
                        if( cc == EOF )return ;
                        if( cc == '\n' ){
                            drop_garbage();//maybe the new line has garbage
                            return ;//return from this method
                        }
                    }
                }
                else if( cc == '*' ){//drop until */ is found
                    c = read_char();
                    while( true ){
                        if( c != EOF ){
                            cc = read_char();
                            if( cc == EOF )return ;
                            if( c == '*' && cc == '/' ){
                                drop_garbage();
                                return ;
                            }
                            c = cc ;
                        }
                        else{
                            return ;
                        }
                    }
                }
                else{//we're in good case
                    restore_char(2);
                    break ;
                }
            }
            else{
                restore_char();
                break ;/* means we start at character that is not a begin of comment */
            }
        }
        else{
            drop_garbage();
            break ;
        }
    }
}
开发者ID:Moh-Nabil,项目名称:Compilers-Project,代码行数:55,代码来源:analyzer.cpp

示例10: skip_line_end

static CMARK_INLINE bool skip_line_end(subject *subj) {
  bool seen_line_end_char = false;
  if (peek_char(subj) == '\r') {
    advance(subj);
    seen_line_end_char = true;
  }
  if (peek_char(subj) == '\n') {
    advance(subj);
    seen_line_end_char = true;
  }
  return seen_line_end_char || is_eof(subj);
}
开发者ID:rhinoman,项目名称:go-commonmark,代码行数:12,代码来源:inlines.c

示例11: read_expression

static char *
read_expression (struct parsebuf *p)
{
  int start;
  int end;

  skip_whitespace (p);
  if (peek_char (p) == '"')
    {
      /* Read as a quoted string.  
         The quotation marks are not included in the expression value.  */
      /* Skip opening quotation mark.  */
      read_char (p);
      start = p->pos;
      while (has_more (p) && peek_char (p) != '"')
        read_char (p);
      end = p->pos;
      /* Skip the terminating quotation mark.  */
      read_char (p);
    }
  else if (peek_char (p) == '(')
    {
      /* Read as a parenthesized string -- for tuples/coordinates.  */
      /* The parentheses are included in the expression value.  */
      int c;

      start = p->pos;
      do
        {
          c = read_char (p);
        }
      while (c != -1 && c != ')');
      end = p->pos;
    }
  else if (has_more (p))
    {
      /* Read as a single word -- for numeric values or words without
         whitespace.  */
      start = p->pos;
      while (has_more (p) && ! is_whitespace (peek_char (p)))
        read_char (p);
      end = p->pos;
    }
  else
    {
      /* The end of the theme file has been reached.  */
      grub_error (GRUB_ERR_IO, "%s:%d:%d expression expected in theme file",
                  p->filename, p->line_num, p->col_num);
      return 0;
    }

  return grub_new_substring (p->buf, start, end);
}
开发者ID:flihp,项目名称:grub2,代码行数:53,代码来源:theme_loader.c

示例12: advance

// Assumes we have a period at the current position.
static cmark_node *handle_period(subject *subj, bool smart) {
  advance(subj);
  if (smart && peek_char(subj) == '.') {
    advance(subj);
    if (peek_char(subj) == '.') {
      advance(subj);
      return make_str(subj->mem, cmark_chunk_literal(ELLIPSES));
    } else {
      return make_str(subj->mem, cmark_chunk_literal(".."));
    }
  } else {
    return make_str(subj->mem, cmark_chunk_literal("."));
  }
}
开发者ID:rhinoman,项目名称:go-commonmark,代码行数:15,代码来源:inlines.c

示例13: handle_hyphen

// Assumes we have a hyphen at the current position.
static cmark_node* handle_hyphen(subject* subj, bool smart)
{
	advance(subj);
	if (smart && peek_char(subj) == '-') {
		advance(subj);
		if (peek_char(subj) == '-') {
			advance(subj);
			return make_str(cmark_chunk_literal(EMDASH));
		} else {
			return make_str(cmark_chunk_literal(ENDASH));
		}
	} else {
		return make_str(cmark_chunk_literal("-"));
	}
}
开发者ID:lowks,项目名称:cmark.ex,代码行数:16,代码来源:inlines.c

示例14: get_special

struct Token get_special(char c)
{
    struct Token tokenOneChar, tokenTwoChar, tokenFinal;
    TokenCode codeOneChar, codeTwoChar, codeFinal;

    tokenOneChar.literalType = STRING_LIT;
    tokenTwoChar.literalType = STRING_LIT;


    tokenOneChar.literalValue.valString[0] = c;
    tokenOneChar.literalValue.valString[1] = '\0';

    tokenTwoChar.literalValue.valString[0] = c;
    tokenTwoChar.literalValue.valString[1] = peek_char();
    tokenTwoChar.literalValue.valString[2] = '\0';

    codeOneChar = is_reserved_word(tokenOneChar.literalValue.valString);
    codeTwoChar = is_reserved_word(tokenTwoChar.literalValue.valString);

    if(codeTwoChar != NO_TOKEN) {
        get_char();
        codeFinal = codeTwoChar;
        tokenFinal = tokenTwoChar;
    } else {
        codeFinal = codeOneChar;
        tokenFinal = tokenOneChar;
    }
    tokenFinal.tokenCode = codeFinal;

    return tokenFinal;
}
开发者ID:rgonza26,项目名称:3rdLab,代码行数:31,代码来源:scanner.c

示例15: peek_char

	char lexer::next_char() {
		char c = peek_char();
		++current;
		++column;

		return c;
	}
开发者ID:storance,项目名称:dcpu16,代码行数:7,代码来源:lexer.cpp


注:本文中的peek_char函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。