Skip to content

Commit

Permalink
Updated linter
Browse files Browse the repository at this point in the history
- Implemented Find and RFind functions for arrays in the linter.
- Implemented documentation strings for functions and events with the
Native keyword.
  • Loading branch information
Kapiainen committed Mar 4, 2016
1 parent 1750fd5 commit 30afc9a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ Single file build system and a batch build variant.
- SKSE mod event names

## **Changelog**
Version 1.0.1 - 2016/03/05:
- Implemented support in the linter for Find and RFind functions for arrays.
- Implemented support in the linter for documentation strings for functions and events with the Native keyword.

Version 1.0.0 - 2016/03/04:
- Major rewrite
- Introduction of version numbers
Expand Down
48 changes: 36 additions & 12 deletions Source/Modules/Skyrim/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,11 @@ def Process(self, statements, paths, cancel = None): # Return True if successful
else:
self.Abort("Unterminated function definition.", func[0].line)
return False
else:
docString = None
if len(statements) > 0:
if statements[0].type == self.STAT_DOCUMENTATION:
docString = statements.pop(0)
elif stat.type == self.STAT_EVENTDEF:
if not self.AddFunction(stat):
return False
Expand All @@ -1577,6 +1582,11 @@ def Process(self, statements, paths, cancel = None): # Return True if successful
else:
self.Abort("Unterminated event definition.", event[0].line)
return False
else:
docString = None
if len(statements) > 0:
if statements[0].type == self.STAT_DOCUMENTATION:
docString = statements.pop(0)
elif stat.type == self.STAT_IMPORT:
if not stat.data.name in self.imports:
self.imports.append(stat.data.name)
Expand Down Expand Up @@ -2016,21 +2026,35 @@ def NodeVisitor(self, node, expected = None):
else:
self.Abort("This script does not have a function/event called %s." % node.data.name.value)
elif expected:
script = self.GetCachedScript(expected)
if script:
func = script.functions.get(node.data.name.value.upper(), None)
if func:
if func.data.type:
if func.data.array:
result = "%s[]" % func.data.type
if "[]" in expected:
typ = expected[:-2]
script = self.GetCachedScript(typ)
if script:
funcName = node.data.name.value.upper()
if funcName == "FIND":
func = Statement(self.STAT_FUNCTIONDEF, 0, FunctionDef("INT", "Int", False, "FIND", "Find", [ParameterDef(typ, typ.capitalize(), False, "AKELEMENT", "akElement", None), ParameterDef("INT", "Int", False, "AISTARTINDEX", "aiStartIndex", Node(self.NODE_EXPRESSION, ExpressionNode(Node(self.NODE_CONSTANT, ConstantNode(Token(self.INT, "0", 0, 0))))))], [self.KW_NATIVE]))
result = self.KW_INT
elif funcName == "RFIND":
func = Statement(self.STAT_FUNCTIONDEF, 0, FunctionDef("INT", "Int", False, "RFIND", "RFind", [ParameterDef(typ, typ.capitalize(), False, "AKELEMENT", "akElement", None), ParameterDef("INT", "Int", False, "AISTARTINDEX", "aiStartIndex", Node(self.NODE_EXPRESSION, ExpressionNode(Node(self.NODE_UNARYOPERATOR, UnaryOperatorNode(self.OP_SUBTRACTION, Node(self.NODE_CONSTANT, ConstantNode(Token(self.INT, "1", 0, 0))))))))], [self.KW_NATIVE]))
result = self.KW_INT
else:
self.Abort("Arrays objects only have FIND and RFIND functions.")
else:
script = self.GetCachedScript(expected)
if script:
func = script.functions.get(node.data.name.value.upper(), None)
if func:
if func.data.type:
if func.data.array:
result = "%s[]" % func.data.type
else:
result = func.data.type
else:
result = func.data.type
result = self.KW_NONE
else:
result = self.KW_NONE
self.Abort("%s does not have a function/event called %s." % (expected, node.data.name.value))
else:
self.Abort("%s does not have a function/event called %s." % (expected, node.data.name.value))
else:
pass
pass
else:
func = self.GetFunction(node.data.name.value)
if func:
Expand Down

0 comments on commit 30afc9a

Please sign in to comment.