mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
23ffa73f4c
commit
eb1806deaa
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "pocketpy/common/str.h"
|
#include "pocketpy/common/str.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -11,19 +11,21 @@ typedef uint8_t TokenIndex;
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
constexpr const char* kTokens[] = {
|
constexpr const char* kTokens[] = {
|
||||||
"is not", "not in", "yield from",
|
|
||||||
"@eof", "@eol", "@sof",
|
"@eof", "@eol", "@sof",
|
||||||
"@id", "@num", "@str", "@fstr", "@long", "@bytes", "@imag",
|
"@id", "@num", "@str", "@fstr", "@long", "@bytes", "@imag",
|
||||||
"@indent", "@dedent",
|
"@indent", "@dedent",
|
||||||
|
// These 3 are compound keywords which are generated on the fly
|
||||||
|
"is not", "not in", "yield from",
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
"+", "+=", "-", "-=", // (INPLACE_OP - 1) can get '=' removed
|
"+", "+=", "-", "-=", // (INPLACE_OP - 1) can get '=' removed
|
||||||
"*", "*=", "/", "/=", "//", "//=", "%", "%=",
|
"*", "*=", "/", "/=", "//", "//=", "%", "%=",
|
||||||
"&", "&=", "|", "|=", "^", "^=",
|
"&", "&=", "|", "|=", "^", "^=",
|
||||||
"<<", "<<=", ">>", ">>=",
|
"<<", "<<=", ">>", ">>=",
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
".", ",", ":", ";", "#", "(", ")", "[", "]", "{", "}",
|
"(", ")", "[", "]", "{", "}",
|
||||||
"**", "=", ">", "<", "..", "...", "->", "@", "==", "!=", ">=", "<=",
|
".", "..", "...", ",", ":", ";",
|
||||||
"++", "--", "~",
|
"**", "->", "#", "@",
|
||||||
|
">", "<", "=", "==", "!=", ">=", "<=", "~",
|
||||||
/** KW_BEGIN **/
|
/** KW_BEGIN **/
|
||||||
// NOTE: These keywords should be sorted in ascending order!!
|
// NOTE: These keywords should be sorted in ascending order!!
|
||||||
"False", "None", "True", "and", "as", "assert", "break", "class", "continue",
|
"False", "None", "True", "and", "as", "assert", "break", "class", "continue",
|
||||||
|
@ -34,6 +34,15 @@ void pkpy_Exception__dtor(pkpy_Exception* self);
|
|||||||
void pkpy_Exception__stpush(pkpy_Exception* self, pkpy_SourceData_ src, int lineno, const char* cursor, const char* name);
|
void pkpy_Exception__stpush(pkpy_Exception* self, pkpy_SourceData_ src, int lineno, const char* cursor, const char* name);
|
||||||
pkpy_Str pkpy_Exception__summary(pkpy_Exception* self);
|
pkpy_Str pkpy_Exception__summary(pkpy_Exception* self);
|
||||||
|
|
||||||
|
struct Error{
|
||||||
|
const char* type;
|
||||||
|
pkpy_SourceData_ src;
|
||||||
|
int lineno;
|
||||||
|
const char* cursor;
|
||||||
|
char msg[100];
|
||||||
|
int64_t userdata;
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@ -59,13 +59,6 @@ struct TopLevelException : std::exception {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Error{
|
|
||||||
const char* type;
|
|
||||||
pkpy_SourceData_ src;
|
|
||||||
int lineno;
|
|
||||||
const char* cursor;
|
|
||||||
char msg[100];
|
|
||||||
i64 userdata;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace pkpy
|
} // namespace pkpy
|
||||||
|
@ -20,7 +20,7 @@ c11_string pkpy_TokenDeserializer__read_string(pkpy_TokenDeserializer* self, cha
|
|||||||
const char* start = self->curr;
|
const char* start = self->curr;
|
||||||
while(*self->curr != c)
|
while(*self->curr != c)
|
||||||
self->curr++;
|
self->curr++;
|
||||||
c11_string retval = {start, self->curr - start};
|
c11_string retval = {start, (int)(self->curr-start)};
|
||||||
self->curr++; // skip the delimiter
|
self->curr++; // skip the delimiter
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -390,13 +390,7 @@ Error* Lexer::lex_one_token(bool* eof) noexcept{
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
case '=': add_token_2('=', TK("="), TK("==")); return NULL;
|
case '=': add_token_2('=', TK("="), TK("==")); return NULL;
|
||||||
case '+':
|
case '+': add_token_2('=', TK("+"), TK("+=")); return NULL;
|
||||||
if(matchchar('+')) {
|
|
||||||
add_token(TK("++"));
|
|
||||||
} else {
|
|
||||||
add_token_2('=', TK("+"), TK("+="));
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
case '>': {
|
case '>': {
|
||||||
if(matchchar('='))
|
if(matchchar('='))
|
||||||
add_token(TK(">="));
|
add_token(TK(">="));
|
||||||
@ -416,16 +410,12 @@ Error* Lexer::lex_one_token(bool* eof) noexcept{
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
case '-': {
|
case '-': {
|
||||||
if(matchchar('-')) {
|
if(matchchar('='))
|
||||||
add_token(TK("--"));
|
add_token(TK("-="));
|
||||||
} else {
|
else if(matchchar('>'))
|
||||||
if(matchchar('='))
|
add_token(TK("->"));
|
||||||
add_token(TK("-="));
|
else
|
||||||
else if(matchchar('>'))
|
add_token(TK("-"));
|
||||||
add_token(TK("->"));
|
|
||||||
else
|
|
||||||
add_token(TK("-"));
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
case '!':
|
case '!':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user