X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Flex.c;h=89c3c407b28c578181f07c4e460c684ea8fe591d;hb=bcb320b537b6f7e5e3724e8a30d309322171eb43;hp=958e0fb4e9ec254022a57a52853f88987e377ebc;hpb=b05e32fa8c11e6d66bb70850751e170dc472a1a3;p=simgear.git diff --git a/simgear/nasal/lex.c b/simgear/nasal/lex.c index 958e0fb4..89c3c407 100644 --- a/simgear/nasal/lex.c +++ b/simgear/nasal/lex.c @@ -1,7 +1,7 @@ #include "parse.h" // Static table of recognized lexemes in the language -struct Lexeme { +static const struct Lexeme { char* str; int tok; } LEXEMES[] = { @@ -130,7 +130,6 @@ static void newToken(struct Parser* p, int pos, int type, tok->str = str; tok->strlen = slen; tok->num = num; - tok->parent = &p->tree; tok->next = 0; tok->prev = last; tok->children = 0; @@ -182,6 +181,7 @@ static void sqEscape(char* buf, int len, int index, struct Parser* p, } // Ditto, but more complicated for double quotes. +/* FIXME: need to handle \b (8), \f (12), and \uXXXX for JSON compliance */ static void dqEscape(char* buf, int len, int index, struct Parser* p, char* cOut, int* eatenOut) { @@ -256,25 +256,27 @@ static int lexHexLiteral(struct Parser* p, int index) return i; } +#define ISNUM(c) ((c) >= '0' && (c) <= '9') +#define ISHEX(c) (ISNUM(c) || ((c)>='a' && (c)<='f') || ((c)>='A' && (c)<='F')) +#define NUMSTART(c) (ISNUM(c) || (c) == '+' || (c) == '-') static int lexNumLiteral(struct Parser* p, int index) { int len = p->len, i = index; unsigned char* buf = (unsigned char*)p->buf; double d; - if(i+1= '0' && buf[i] <= '9') i++; + while(i= '0' && buf[i] <= '9') i++; + while(i= '0' && buf[i+1] <= '9')) i++; - while(i= '0' && buf[i] <= '9') i++; + if(buf[i] == '-' || buf[i] == '+') i++; + while(ibuf + index, i - index, &d); newToken(p, index, TOK_LITERAL, 0, 0, d); @@ -333,7 +335,6 @@ static int tryLexemes(struct Parser* p, int index, int* lexemeOut) return best; } -#define ISNUM(c) ((c) >= '0' && (c) <= '9') void naLex(struct Parser* p) { int i = 0;