support complex import

This commit is contained in:
BLUELOVETH 2023-08-28 12:43:43 +08:00
parent 5888151182
commit 8b47a2001f
11 changed files with 32 additions and 7 deletions

View File

@ -20,7 +20,7 @@ constexpr const char* kTokens[] = {
"<<", "<<=", ">>", ">>=", "<<", "<<=", ">>", ">>=",
/*****************************************/ /*****************************************/
".", ",", ":", ";", "#", "(", ")", "[", "]", "{", "}", ".", ",", ":", ";", "#", "(", ")", "[", "]", "{", "}",
"**", "=", ">", "<", "...", "->", "?", "@", "==", "!=", ">=", "<=", "**", "=", ">", "<", "..", "...", "->", "?", "@", "==", "!=", ">=", "<=",
"++", "--", "~", "++", "--", "~",
/** SPEC_BEGIN **/ /** SPEC_BEGIN **/
"$goto", "$label", "$goto", "$label",

View File

@ -502,7 +502,8 @@ __SUBSCR_END:
while(true){ while(true){
switch(curr().type){ switch(curr().type){
case TK("."): dots++; break; case TK("."): dots+=1; break;
case TK(".."): dots+=2; break;
case TK("..."): dots+=3; break; case TK("..."): dots+=3; break;
default: goto __EAT_DOTS_END; default: goto __EAT_DOTS_END;
} }

View File

@ -345,7 +345,7 @@ static bool is_unicode_Lo_char(uint32_t c) {
if(matchchar('.')) { if(matchchar('.')) {
add_token(TK("...")); add_token(TK("..."));
} else { } else {
SyntaxError("invalid token '..'"); add_token(TK(".."));
} }
} else { } else {
add_token(TK(".")); add_token(TK("."));

View File

@ -6,3 +6,12 @@ except ImportError:
import test1 import test1
assert test1.add(1, 2) == 13 assert test1.add(1, 2) == 13
from test2.a.g import get_value
assert get_value() == '123'
import test2
assert test2.a.g.get_value() == '123'
from test2.utils import get_value_2
assert get_value_2() == '123'

View File

@ -1 +1 @@
from ._a import D from .a import D

View File

@ -1 +0,0 @@
from ._b import D

View File

@ -0,0 +1 @@
from ..b import D

View File

@ -0,0 +1,4 @@
from ...utils import r
def get_value():
return r.value

View File

@ -1,7 +1,7 @@
D = 10 D = 10
try: try:
import test import abc # does not exist
exit(1) exit(1)
except ImportError: except ImportError:
pass pass

View File

@ -0,0 +1,4 @@
from .r import value
def get_value_2():
return value

7
tests/test2/utils/r.py Normal file
View File

@ -0,0 +1,7 @@
value = '123'
try:
from test2.a import g
except ImportError:
# circular import
pass