eric6/Utilities/ModuleParser.py

branch
maintenance
changeset 8142
43248bafe9b2
parent 8043
0acf98cd089a
parent 8131
f2129bb79269
child 8273
698ae46f40a4
--- a/eric6/Utilities/ModuleParser.py	Mon Feb 01 10:38:43 2021 +0100
+++ b/eric6/Utilities/ModuleParser.py	Tue Mar 02 17:12:08 2021 +0100
@@ -37,6 +37,7 @@
     "Python": PY_SOURCE,
     "Python3": PY_SOURCE,
     "MicroPython": PY_SOURCE,
+    "Cython": PY_SOURCE,
     "Ruby": RB_SOURCE,
 }
 
@@ -134,7 +135,7 @@
         )?
         ^
         (?P<MethodIndent> [ \t]* )
-        (?: async [ \t]+ )? def [ \t]+
+        (?: async [ \t]+ )? (?: cdef | cpdef | def) [ \t]+
         (?P<MethodName> \w+ )
         (?: [ \t]* \[ (?: plain | html ) \] )?
         [ \t]* \(
@@ -147,6 +148,7 @@
 |   (?P<Class>
         ^
         (?P<ClassIndent> [ \t]* )
+        (?: cdef [ \t]+ )?
         class [ \t]+
         (?P<ClassName> \w+ )
         [ \t]*
@@ -175,7 +177,7 @@
     )
 
 |   (?P<Import>
-        ^ [ \t]* (?: import | from [ \t]+ \. [ \t]+ import ) [ \t]+
+        ^ [ \t]* (?: c? import | from [ \t]+ \. [ \t]+ c? import ) [ \t]+
         (?P<ImportList> (?: [^#;\\\n]* (?: \\\n )* )* )
     )
 
@@ -188,7 +190,7 @@
             )*
         )
         [ \t]+
-        import [ \t]+
+        c? import [ \t]+
         (?P<ImportFromList>
             (?: \( \s* .*? \s* \) )
             |
@@ -737,6 +739,27 @@
                                         n = m.name
                             names.append(n)
                     inherit = names
+                # modify indentation level for conditional defines
+                if conditionalsstack:
+                    if thisindent > conditionalsstack[-1]:
+                        if not deltaindentcalculated:
+                            deltastack.append(
+                                thisindent - conditionalsstack[-1]
+                            )
+                            deltaindent = reduce(
+                                lambda x, y: x + y, deltastack
+                            )
+                            deltaindentcalculated = True
+                        thisindent -= deltaindent
+                    else:
+                        while (
+                            conditionalsstack and
+                            conditionalsstack[-1] >= thisindent
+                        ):
+                            del conditionalsstack[-1]
+                            if deltastack:
+                                del deltastack[-1]
+                        deltaindentcalculated = False
                 # remember this class
                 cur_class = Class(self.name, class_name, inherit,
                                   self.file, lineno)

eric ide

mercurial