-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -377,7 +377,7 @@ def t_CPPCOMMENT(t): | |
|
|
||
|
|
||
| def t_error(t): | ||
| console.Out.Verbose("Illegal character '%s'" % t.value[0], t.lexer.lineno) | ||
| console.Out.Verbose(f"Illegal character '{t.value[0]}'", t.lexer.lineno) | ||
| t.lexer.skip(1) | ||
|
|
||
|
|
||
|
|
@@ -403,9 +403,9 @@ def __init__(self, filename, data=None): | |
| try: | ||
| self.data = f.read() | ||
| except UnicodeDecodeError as ex: | ||
| console.Out.Ci("[ERROR] UnicodeDecodeError in CppLexerNavigator: " + str(ex)) | ||
| console.Out.Ci(f"[ERROR] UnicodeDecodeError in CppLexerNavigator: {str(ex)}") | ||
| console.Out.Ci( | ||
| "[ERROR] Exception occurred reading file '%s', convert from UTF16LE to UTF8" % (filename), | ||
| f"[ERROR] Exception occurred reading file '{filename}', convert from UTF16LE to UTF8" | ||
|
Comment on lines
-406
to
+408
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| ) | ||
| raise | ||
| self.lines = self.data.splitlines() | ||
|
|
@@ -445,7 +445,7 @@ def ProcessIfdef(self, token): | |
| self.ifdefstack.append(True) | ||
| elif Match(r"^#\s*endif$", token.value) and len(self.ifdefstack) != 0: | ||
| self.ifdefstack.pop() | ||
| return any(not ifdef for ifdef in self.ifdefstack) | ||
| return not all(self.ifdefstack) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def Backup(self): | ||
| """ | ||
|
|
@@ -473,9 +473,7 @@ def GetCurTokenLine(self): | |
| Get Current Token, if No current token, return None | ||
| """ | ||
| curToken = self.GetCurToken() | ||
| if curToken is not None: | ||
| return self.lines[curToken.lineno - 1] | ||
| return None | ||
| return self.lines[curToken.lineno - 1] if curToken is not None else None | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def _MoveToToken(self, token): | ||
| self.tokenindex = token.index | ||
|
|
@@ -488,9 +486,7 @@ def _GetColumn(self, token): | |
| if last_cr < 0: | ||
| last_cr = -1 | ||
| column = token.lexpos - last_cr | ||
| if column == 0: | ||
| return 1 | ||
| return column | ||
| return 1 if column == 0 else column | ||
|
Comment on lines
-491
to
+489
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def GetCurToken(self): | ||
| """ | ||
|
|
@@ -630,11 +626,10 @@ def GetNextToken(self, skipWhiteSpace=False, skipComment=False, skipDirective=Fa | |
| def GetNextMatchingGT(self, keepCur=False): | ||
| if keepCur: | ||
| self.PushTokenIndex() | ||
| gtStack = [] | ||
| if self.GetCurToken().type != "LT": | ||
| msg = "Matching next GT token should be examined when cur token is <" | ||
| raise RuntimeError(msg) | ||
| gtStack.append(self.GetCurToken()) | ||
| gtStack = [self.GetCurToken()] | ||
|
Comment on lines
-633
to
+632
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| t = self._GetNextMatchingGTToken(gtStack) | ||
| if keepCur: | ||
| self.PopTokenIndex() | ||
|
|
@@ -666,11 +661,10 @@ def GetNextMatchingToken(self, keepCur=False): | |
| """ | ||
| if keepCur: | ||
| self.PushTokenIndex() | ||
| tokenStack = [] | ||
| if self.GetCurToken().type not in ["LPAREN", "LBRACE", "LBRACKET"]: | ||
| msg = "Matching token should be examined when cur token is { [ (" | ||
| raise RuntimeError(msg) | ||
| tokenStack.append(self.GetCurToken()) | ||
| tokenStack = [self.GetCurToken()] | ||
|
Comment on lines
-669
to
+667
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| t = self._GetNextMatchingToken(tokenStack) | ||
| if keepCur: | ||
| self.PopTokenIndex() | ||
|
|
@@ -771,12 +765,10 @@ def _GetPrevMatchingLTToken(self, tokenStack): | |
| def GetPrevMatchingToken(self, keepCur=False): | ||
| if keepCur: | ||
| self.PushTokenIndex() | ||
| tokenStack = [] | ||
| if self.GetCurToken().type not in ["RPAREN", "RBRACE", "RBRACKET"]: | ||
| msg = "Matching token should be examined when cur token is } ) ]" | ||
| raise RuntimeError(msg) | ||
| tokenStack.append(self.GetCurToken()) | ||
|
|
||
| tokenStack = [self.GetCurToken()] | ||
|
Comment on lines
-774
to
+771
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| t = self._GetPrevMatchingToken(tokenStack) | ||
| if keepCur: | ||
| self.PopTokenIndex() | ||
|
|
@@ -815,40 +807,35 @@ def _GetPrevMatchingToken(self, tokenStack): | |
| def _SkipContext(self, skipWhiteSpace=False, skipComment=False): | ||
| context = [] | ||
| if skipWhiteSpace: | ||
| context.append("SPACE") | ||
| context.append("LINEFEED") | ||
| context.extend(("SPACE", "LINEFEED")) | ||
| if skipComment: | ||
| context.append("COMMENT") | ||
| context.append("CPPCOMMENT") | ||
| context.extend(("COMMENT", "CPPCOMMENT")) | ||
|
Comment on lines
-818
to
+812
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return context | ||
|
|
||
| def _GetNextToken(self): | ||
| if self.tokenindex < self.tokenlistsize - 1: | ||
| self.tokenindex = self.tokenindex + 1 | ||
| return self.tokenlist[self.tokenindex] | ||
| else: | ||
| if self.tokenindex >= self.tokenlistsize - 1: | ||
| return None | ||
| self.tokenindex = self.tokenindex + 1 | ||
| return self.tokenlist[self.tokenindex] | ||
|
Comment on lines
-826
to
+819
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def _GetPrevToken(self): | ||
| if self.tokenindex >= 0: | ||
| self.tokenindex = self.tokenindex - 1 | ||
| if self.tokenindex == -1: | ||
| return None | ||
| return self.tokenlist[self.tokenindex] | ||
| else: | ||
| if self.tokenindex < 0: | ||
| return None | ||
| self.tokenindex = self.tokenindex - 1 | ||
| return None if self.tokenindex == -1 else self.tokenlist[self.tokenindex] | ||
|
Comment on lines
-833
to
+825
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def GetPrevTokenInType(self, type, keepCur=True, skipPreprocess=True): | ||
| if keepCur: | ||
| self.PushTokenIndex() | ||
| token = None | ||
| while True: | ||
| token = self.GetPrevToken() | ||
| if token is None: | ||
| break | ||
| elif token.type == type: | ||
| if skipPreprocess and token.pp: | ||
| continue | ||
| if ( | ||
| token is not None | ||
| and token.type == type | ||
| and (not skipPreprocess or not token.pp) | ||
| or token is None | ||
| ): | ||
|
Comment on lines
-847
to
+838
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| break | ||
| if keepCur: | ||
| self.PopTokenIndex() | ||
|
|
@@ -860,11 +847,12 @@ def GetPrevTokenInTypeList(self, typelist, keepCur=True, skipPreprocess=True): | |
| token = None | ||
| while True: | ||
| token = self.GetPrevToken(False, False, skipPreprocess, False) | ||
| if token is None: | ||
| break | ||
| elif token.type in typelist: | ||
| if skipPreprocess and token.pp: | ||
| continue | ||
| if ( | ||
| token is not None | ||
| and token.type in typelist | ||
| and (not skipPreprocess or not token.pp) | ||
| or token is None | ||
| ): | ||
|
Comment on lines
-863
to
+855
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| break | ||
| if keepCur: | ||
| self.PopTokenIndex() | ||
|
|
@@ -884,11 +872,12 @@ def GetNextTokenInType(self, type, keepCur=False, skipPreprocess=True): | |
| token = None | ||
| while True: | ||
| token = self.GetNextToken() | ||
| if token is None: | ||
| break | ||
| elif token.type == type: | ||
| if skipPreprocess and token.pp: | ||
| continue | ||
| if ( | ||
| token is not None | ||
| and token.type == type | ||
| and (not skipPreprocess or not token.pp) | ||
| or token is None | ||
| ): | ||
|
Comment on lines
-887
to
+880
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| break | ||
| if keepCur: | ||
| self.PopTokenIndex() | ||
|
|
@@ -900,11 +889,12 @@ def GetNextTokenInTypeList(self, typelist, keepCur=False, skipPreprocess=True): | |
| token = None | ||
| while True: | ||
| token = self.GetNextToken() | ||
| if token is None: | ||
| break | ||
| elif token.type in typelist: | ||
| if skipPreprocess and token.pp: | ||
| continue | ||
| if ( | ||
| token is not None | ||
| and token.type in typelist | ||
| and (not skipPreprocess or not token.pp) | ||
| or token is None | ||
| ): | ||
|
Comment on lines
-903
to
+897
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| break | ||
| if keepCur: | ||
| self.PopTokenIndex() | ||
|
|
@@ -918,9 +908,7 @@ def HasBody(self): | |
|
|
||
| if token_id3 is None and token_id2 is not None: | ||
| return True | ||
| if token_id2 is not None and token_id2.lexpos < token_id3.lexpos: | ||
| return True | ||
| return False | ||
| return token_id2 is not None and token_id2.lexpos < token_id3.lexpos | ||
|
Comment on lines
-921
to
+911
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class Context: | ||
|
|
@@ -933,7 +921,9 @@ def __init__(self, type, name, sig=False, starttoken=None, endtoken=None): | |
| self.additional = "" | ||
|
|
||
| def __str__(self): | ||
| return ", ".join([self.type, "'" + self.name + "'", str(self.startToken), str(self.endToken)]) | ||
| return ", ".join( | ||
| [self.type, f"'{self.name}'", str(self.startToken), str(self.endToken)] | ||
| ) | ||
|
Comment on lines
-936
to
+926
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def IsContextStart(self, token): | ||
| return token == self.startToken | ||
|
|
@@ -942,9 +932,10 @@ def IsContextEnd(self, token): | |
| return token == self.endToken | ||
|
|
||
| def InScope(self, token): | ||
| if token.lexpos >= self.startToken.lexpos and token.lexpos <= self.endToken.lexpos: | ||
| return True | ||
| return False | ||
| return ( | ||
| token.lexpos >= self.startToken.lexpos | ||
| and token.lexpos <= self.endToken.lexpos | ||
| ) | ||
|
Comment on lines
-945
to
+938
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class ContextStack: | ||
|
|
@@ -955,14 +946,10 @@ def Push(self, context): | |
| self.contextstack.append(context) | ||
|
|
||
| def Pop(self): | ||
| if self.Size() == 0: | ||
| return None | ||
| return self.contextstack.pop() | ||
| return None if self.Size() == 0 else self.contextstack.pop() | ||
|
Comment on lines
-958
to
+949
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def Peek(self): | ||
| if self.Size() == 0: | ||
| return None | ||
| return self.contextstack[-1] | ||
| return None if self.Size() == 0 else self.contextstack[-1] | ||
|
Comment on lines
-963
to
+952
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def SigPeek(self): | ||
| i = len(self.contextstack) | ||
|
|
@@ -991,10 +978,9 @@ def ContainsIn(self, type): | |
| return False | ||
|
|
||
| def __str__(self): | ||
| a = "" | ||
| for eachContext in self.contextstack: | ||
| a += eachContext.__str__() + " >> " | ||
| return a | ||
| return "".join( | ||
| f"{eachContext.__str__()} >> " for eachContext in self.contextstack | ||
| ) | ||
|
Comment on lines
-994
to
+983
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def Copy(self): | ||
| contextStack = ContextStack() | ||
|
|
@@ -1015,9 +1001,7 @@ def Pop(self): | |
| return self.contextstackstack.pop() | ||
|
|
||
| def Peek(self): | ||
| if len(self.contextstackstack) == 0: | ||
| return None | ||
| return self.contextstackstack[-1] | ||
| return None if len(self.contextstackstack) == 0 else self.contextstackstack[-1] | ||
|
Comment on lines
-1018
to
+1004
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| ############################################################################ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
t_errorrefactored with the following changes:replace-interpolation-with-fstring)