📄 lex.c
字号:
} *cp2++ = 0; if (chgmode == '-') { skipspc(cp); if (cp != closing) return 0; strlist_remove((Strlist **)rctable[i].ptr, namebuf); } else { if (!isspace(*cp) && *cp != '=') return 0; skipspc(cp); if (*cp == '=') { cp++; skipspc(cp); } if (chgmode == '=' || isspace(chgmode)) strlist_remove((Strlist **)rctable[i].ptr, namebuf); sp = strlist_append((Strlist **)rctable[i].ptr, namebuf); if (tempopt) strlist_insert(&tempoptionlist, namebuf)->value = i; cp2 = namebuf; if (*cp == '"' && rctable[i].def == 4) { cp++; while (*cp != '"') { if (cp == closing) return 0; if (*cp == 92 && cp+1 < closing) cp++; *cp2++ = *cp++; } cp++; skipspc(cp); } else { while (*cp && cp != closing && !isspace(*cp)) *cp2++ = *cp++; } *cp2++ = 0; skipspc(cp); if (cp != closing) return 0; sp->value = (long)stralloc(namebuf); } inbufptr = after; if (lex_initialized) handle_nameof(); /* as good a place to do this as any! */ return 1; case 3: /* Synonym parameter */ if (isspace(*cp) || *cp == '=' || *cp == '+' || *cp == '-') { chgmode = *cp++; skipspc(cp); cp2 = namebuf; while (isalnum(*cp) || *cp == '_' || *cp == '$' || *cp == '%') *cp2++ = *cp++; *cp2++ = 0; if (!*namebuf) return 0; skipspc(cp); if (!pascalcasesens) upc(namebuf); sym = findsymbol(namebuf); if (chgmode == '-') { if (cp != closing) return 0; sym->flags &= ~SSYNONYM; inbufptr = after; return 1; } if (*cp == '=') { cp++; skipspc(cp); } cp2 = namebuf; while (isalnum(*cp) || *cp == '_' || *cp == '$' || *cp == '%') *cp2++ = *cp++; *cp2++ = 0; skipspc(cp); if (cp != closing) return 0; sym->flags |= SSYNONYM; if (!pascalcasesens) upc(namebuf); if (*namebuf) strlist_append(&sym->symbolnames, "===")->value = (long)findsymbol(namebuf); else strlist_append(&sym->symbolnames, "===")->value=0; inbufptr = after; return 1; } return 0; } return 0; } return 0;}Static void comment(starparen)int starparen; /* 0={ }, 1=(* *), 2=C comments, 3=" " */{ register char ch; int nestcount = 1, startlnum = inf_lnum, wasrel = 0, trailing; int i, cmtindent, cmtindent2, saveeat = eatcomments; char *cp; if (!strncmp(inbufptr, embedcomment, strlen(embedcomment)) && *embedcomment) eatcomments = 0; cp = inbuf; while (isspace(*cp)) cp++; trailing = (*cp != '{' && ((*cp != '(' && *cp != '/') || cp[1] != '*') && (*cp != '"' || starparen != 3)); cmtindent = inbufindent; cmtindent2 = cmtindent + 1 + (starparen != 0); cp = inbufptr; while (isspace(*cp)) cmtindent2++, cp++; cp = curtokbuf; for (;;) { ch = *inbufptr++; switch (ch) { case '}': if ((!starparen || nestedcomments == 0) && starparen < 2 && --nestcount <= 0) { *cp = 0; if (wasrel && !strcmp(curtokbuf, "\003")) *curtokbuf = '\002'; if (!commenting_flag) commentline(trailing ? CMT_TRAIL : CMT_POST); eatcomments = saveeat; return; } break; case '"': if (starparen == 3) { *cp = 0; if (wasrel && !strcmp(curtokbuf, "\003")) *curtokbuf = '\002'; if (!commenting_flag) commentline(trailing ? CMT_TRAIL : CMT_POST); eatcomments = saveeat; return; } break; case '{': if (nestedcomments == 1 && starparen < 2) nestcount++; break; case '*': if (*inbufptr == ((starparen == 2) ? '/' : ')') && starparen < 3 && (starparen || nestedcomments == 0) && --nestcount <= 0) { inbufptr++; *cp = 0; if (wasrel && !strcmp(curtokbuf, "\003")) *curtokbuf = '\002'; if (!commenting_flag) commentline(trailing ? CMT_TRAIL : CMT_POST); eatcomments = saveeat; return; } break; case '(': if (*inbufptr == '*' && nestedcomments == 1 && starparen < 2) { *cp++ = ch; ch = *inbufptr++; nestcount++; } break; case 0: *cp = 0; if (commenting_flag) saveinputcomment(inbufptr-1); else commentline(CMT_POST); trailing = 0; getline(); i = 0; for (;;) { if (*inbufptr == ' ') { inbufptr++; i++; } else if (*inbufptr == '\t') { inbufptr++; i++; if (intabsize) i = (i / intabsize + 1) * intabsize; } else break; } cp = curtokbuf; if (*inbufptr) { if (i == cmtindent2 && !starparen) cmtindent--; cmtindent2 = -1; if (i >= cmtindent && i > 0) { *cp++ = '\002'; i -= cmtindent; wasrel = 1; } else { *cp++ = '\003'; } while (--i >= 0) *cp++ = ' '; } else *cp++ = (slashslash) ? '\002' : '\003'; continue; case EOFMARK: error(format_d("Runaway comment from line %d", startlnum)); eatcomments = saveeat; return; /* unnecessary */ } *cp++ = ch; }}char *getinlinepart(){ char *cp, *buf; for (;;) { if (isspace(*inbufptr)) { inbufptr++; } else if (!*inbufptr) { getline(); } else if (*inbufptr == '{') { inbufptr++; comment(0); } else if (*inbufptr == '(' && inbufptr[1] == '*') { inbufptr += 2; comment(1); } else break; } cp = inbufptr; while (isspace(*cp) || isalnum(*cp) || *cp == '_' || *cp == '$' || *cp == '+' || *cp == '-' || *cp == '<' || *cp == '>') cp++; if (cp == inbufptr) return ""; while (isspace(cp[-1])) cp--; buf = format_s("%s", inbufptr); buf[cp-inbufptr] = 0; /* truncate the string */ inbufptr = cp; return buf;}Static int getflag(){ int res = 1; gettok(); if (curtok == TOK_IDENT) { res = (strcmp(curtokbuf, "OFF") != 0); gettok(); } return res;}char getchartok(){ if (!*inbufptr) { warning("Unexpected end of line [236]"); return ' '; } if (isspace(*inbufptr)) { warning("Whitespace not allowed here [237]"); return ' '; } return *inbufptr++;}char *getparenstr(buf)char *buf;{ int count = 0; char *cp; if (inbufptr < buf) /* this will get most bad cases */ error("Can't handle a line break here"); while (isspace(*buf)) buf++; cp = buf; for (;;) { if (!*cp) error("Can't handle a line break here"); if (*cp == '(') count++; if (*cp == ')') if (--count < 0) break; cp++; } inbufptr = cp + 1; while (cp > buf && isspace(cp[-1])) cp--; return format_ds("%.*s", (int)(cp - buf), buf);}void leadingcomments(){ for (;;) { switch (*inbufptr++) { case 0: getline(); break; case ' ': case '\t': case 26: /* ignore whitespace */ break; case '{': if (!parsecomment(1, 0)) { inbufptr--; return; } break; case '(': if (*inbufptr == '*') { inbufptr++; if (!parsecomment(1, 1)) { inbufptr -= 2; return; } break; } /* fall through */ default: inbufptr--; return; } }}void get_C_string(term)int term;{ char *cp = curtokbuf; char ch; int i; while ((ch = *inbufptr++)) { if (ch == term) { *cp = 0; curtokint = cp - curtokbuf; return; } else if (ch == '\\') { if (isdigit(*inbufptr)) { i = (*inbufptr++) - '0'; if (isdigit(*inbufptr)) i = i*8 + (*inbufptr++) - '0'; if (isdigit(*inbufptr)) i = i*8 + (*inbufptr++) - '0'; *cp++ = i; } else { ch = *inbufptr++; switch (tolower(ch)) { case 'n': *cp++ = '\n'; break; case 't': *cp++ = '\t'; break; case 'v': *cp++ = '\v'; break; case 'b': *cp++ = '\b'; break; case 'r': *cp++ = '\r'; break; case 'f': *cp++ = '\f'; break; case '\\': *cp++ = '\\'; break; case '\'': *cp++ = '\''; break; case '"': *cp++ = '"'; break; case 'x': if (isxdigit(*inbufptr)) { if (isdigit(*inbufptr)) i = (*inbufptr++) - '0'; else i = (toupper(*inbufptr++)) - 'A' + 10; if (isdigit(*inbufptr)) i = i*16 + (*inbufptr++) - '0'; else if (isxdigit(*inbufptr)) i = i*16 + (toupper(*inbufptr++)) - 'A' + 10; *cp++ = i; break; } /* fall through */ default: warning("Strange character in C string [238]"); } } } else *cp++ = ch; } *cp = 0; curtokint = cp - curtokbuf; warning("Unterminated C string [239]");}void begincommenting(cp)char *cp;{ if (!commenting_flag) { commenting_ptr = cp; } commenting_flag++;}void saveinputcomment(cp)char *cp;{ if (commenting_ptr) sprintf(curtokbuf, "%.*s", (int)(cp - commenting_ptr), commenting_ptr); else sprintf(curtokbuf, "\003%.*s", (int)(cp - inbuf), inbuf); commentline(CMT_POST); commenting_ptr = NULL;}void endcommenting(cp)char *cp;{ commenting_flag--; if (!commenting_flag) { saveinputcomment(cp); }}char *peeknextptr(){ char *cp; cp = inbufptr; for (;;) { if (isspace(*cp)) { cp++; } else if (*cp == '{') { while (*cp && *cp != '}') cp++; if (*cp) cp++; } else if (*cp == '(' && cp[1] == '*') { cp += 2; while (*cp && (*cp != '*' || cp[1] != ')')) cp++; if (*cp) cp += 2; } else { return cp; } }}int peeknextchar(){ char *cp; cp = peeknextptr(); if (*cp == ':') if (cp[1] == '=') return 1; else if (cp[1] == ':') return 2; return *cp;}int peeknextword(word)char *word;{ char *cp; int len; cp = peeknextptr(); len = strlen(word); if (strcincmp(cp, word, len)) return 0; if (isalnum(cp[len]) || cp[len] ==
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -