-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathformattingrule.py
37 lines (36 loc) · 1.92 KB
/
formattingrule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from sourcecodepart import *
import word
class FormattingRule:
###
### formats to this format: ["string", "string2", "string3"]
###
@classmethod
def formatStringInList(cls,sourceCodePart):
if sourceCodePart.characterAtIndex2 != " ":
if sourceCodePart.characterAtIndex2 == ",":
return SourceCodePart(sourceCodePart.characterAtIndex0,",","",2)
else:
return SourceCodePart(sourceCodePart.characterAtIndex0,","," ",1)
return SourceCodePart(sourceCodePart.characterAtIndex0,",",sourceCodePart.characterAtIndex2,2)
@classmethod
def formatMethodArgument(cls,sourceCodePart):
if sourceCodePart.characterAtIndex1 == " ":
return SourceCodePart(sourceCodePart.characterAtIndex0,sourceCodePart.characterAtIndex1,sourceCodePart.characterAtIndex2,2)
else:
return SourceCodePart(sourceCodePart.characterAtIndex0," ",sourceCodePart.characterAtIndex1,1)
@classmethod
def formatMethod(cls,sourceCodePart):
if sourceCodePart.characterAtIndex1 == " ":
if word.KeyWord.isKeyWordSeparator(sourceCodePart.characterAtIndex2):
return SourceCodePart(sourceCodePart.characterAtIndex0,"",sourceCodePart.characterAtIndex2,2)
else:
return SourceCodePart(sourceCodePart.characterAtIndex0," ",sourceCodePart.characterAtIndex2,2)
else:
return SourceCodePart(sourceCodePart.characterAtIndex0,"",sourceCodePart.characterAtIndex1,1)
#generic case for setting spaces
@classmethod
def formatGeneric(cls,sourceCodePart):
if sourceCodePart.characterAtIndex1 == ")":
if sourceCodePart.lastReadKeyWord:
return SourceCodePart("",sourceCodePart.characterAtIndex1,sourceCodePart.characterAtIndex2,2)
return SourceCodePart(sourceCodePart.characterAtIndex0,sourceCodePart.characterAtIndex1,sourceCodePart.characterAtIndex2,2)