diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/class/formatString.class.noPattern.notifying.with..st b/packages/PoppyPrint-Core.package/PPFormatter.class/class/formatString.class.noPattern.notifying.with..st index 509781c..cc53416 100644 --- a/packages/PoppyPrint-Core.package/PPFormatter.class/class/formatString.class.noPattern.notifying.with..st +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/class/formatString.class.noPattern.notifying.with..st @@ -1,7 +1,7 @@ format formatString: aString class: aClass noPattern: aBoolean notifying: anObject with: aPPFormatterConfig - | formatter methodNode | + | formatter methodNode result | self example: 'string test' receiver: [PPFormatter] @@ -19,4 +19,10 @@ formatString: aString class: aClass noPattern: aBoolean notifying: anObject with initForNode: methodNode; config: aPPFormatterConfig. methodNode accept: formatter. - ^ aBoolean ifTrue: [self stripMethodPattern: formatter contents] ifFalse: [formatter contents] \ No newline at end of file + + result := aBoolean + ifTrue: [self stripMethodPattern: formatter contents] + ifFalse: [formatter contents]. + aPPFormatterConfig formatToMaxLineWidth ifTrue: [result := PPWindowFormatter new format: result withWindowWidth: aPPFormatterConfig maxLineWidth]. + + ^ result \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/braceNodeHasMultiLineParts..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/braceNodeHasMultiLineParts..st new file mode 100644 index 0000000..e2cdf8d --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/braceNodeHasMultiLineParts..st @@ -0,0 +1,5 @@ +helper +braceNodeHasMultiLineParts: aNode + + ^ (aNode elements anySatisfy: [:node | + (self willBeMultiLine: node) or: [self isTypeOfNewLineMarker: node]]) or: [self isCaseOf: (self parentFor: aNode)] diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/getBraceNodeLength..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/getBraceNodeLength..st new file mode 100644 index 0000000..2b574d7 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/getBraceNodeLength..st @@ -0,0 +1,6 @@ +helper +getBraceNodeLength: aNode + + ^ aNode elements + inject: 0 + into: [:sum :node | sum + (self preFormat: node) size] diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isOptionalEmptyLineMarker..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isOptionalEmptyLineMarker..st new file mode 100644 index 0000000..4c94762 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isOptionalEmptyLineMarker..st @@ -0,0 +1,4 @@ +helper +isOptionalEmptyLineMarker: aNode + + ^ aNode isLiteralNode and: [aNode key = #ppOptionalEmptyLine] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isOptionalNewLineMarker..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isOptionalNewLineMarker..st new file mode 100644 index 0000000..2eff67a --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isOptionalNewLineMarker..st @@ -0,0 +1,4 @@ +helper +isOptionalNewLineMarker: aNode + + ^ aNode isLiteralNode and: [aNode key = #ppOptionalNewLine] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isTypeOfNewLineMarker..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isTypeOfNewLineMarker..st new file mode 100644 index 0000000..dacb326 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/isTypeOfNewLineMarker..st @@ -0,0 +1,4 @@ +helper +isTypeOfNewLineMarker: aNode + + ^ ((self isOptionalEmptyLineMarker: aNode) or: [self isOptionalNewLineMarker: aNode] or: (self isEmptyLineMarker: aNode)) \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/printBraceStatements.multiLine..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/printBraceStatements.multiLine..st new file mode 100644 index 0000000..2285c25 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/printBraceStatements.multiLine..st @@ -0,0 +1,16 @@ +helper +printBraceStatements: aNode multiLine: multiLine + + aNode elements do: [:element | | isLast | + isLast := element = aNode elements last. + ((self isOptionalNewLineMarker: element) and: [multiLine]) ifFalse: [ + ((self isEmptyLineMarker: element) or: [self isOptionalEmptyLineMarker: element]) + ifTrue: [self newLine] + ifFalse: [ + (self isOptionalNewLineMarker: element) ifFalse: [ + self visitNode: element. + isLast ifFalse: [ + config spaceBeforePointInArray ifTrue: [stream space]. + self stream nextPut: $.]]. + + isLast ifFalse: [multiLine ifTrue: [self newLine] ifFalse: [self stream space]]]]] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/shouldSkipStatement..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/shouldSkipStatement..st new file mode 100644 index 0000000..3dae687 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/shouldSkipStatement..st @@ -0,0 +1,8 @@ +accessing +shouldSkipStatement: aBoolean + + | element | + ^ self isEmptyLineMarker: element + ifTrue: [self newLine] + ifFalse: [ + (self isOptionalEmptyLineMarker: element) or: [self isOptionalNewLineMarker: element]]. \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBlockNode..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBlockNode..st index 68e8ced..c7abe3b 100644 --- a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBlockNode..st +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBlockNode..st @@ -14,11 +14,15 @@ visitBlockNode: aNode self printBlockComment: aNode. aNode statements do: [:statement | - (self isEmptyLineMarker: statement) ifTrue: [self newLine] ifFalse: [ - self visitNode: statement. - statement ~= aNode statements last ifTrue: [ - stream nextPut: $.. - self newLine]]. + (self isEmptyLineMarker: statement) + ifTrue: [self newLine] + ifFalse: [ + ((self isOptionalEmptyLineMarker: statement) or: [self isOptionalNewLineMarker: statement]) + ifFalse: [ + self visitNode: statement. + statement ~= aNode statements last ifTrue: [ + stream nextPut: $.. + self newLine]]]. self printAllCommentsOf: statement lastStatement: statement = aNode statements last]]. isMethodBlock ifFalse: [stream nextPut: $]] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBraceNode..st b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBraceNode..st index 0d9fbdf..7545141 100644 --- a/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBraceNode..st +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/instance/visitBraceNode..st @@ -2,22 +2,12 @@ visiting visitBraceNode: aNode | length multiLine | - length := aNode elements inject: 0 into: [:sum :node | sum + (self preFormat: node) size]. - multiLine := length > self maxLineLength or: [(aNode elements anySatisfy: [:node | (self willBeMultiLine: node) or: [self isEmptyLineMarker: node]]) or: [self isCaseOf: (self parentFor: aNode)]]. - - stream nextPut: ${. + length := self getBraceNodeLength: aNode. + multiLine := length > self maxLineLength or: [self braceNodeHasMultiLineParts: aNode]. + self stream nextPut: ${. self indent: (multiLine ifTrue: [1] ifFalse: [0]) around: [ multiLine ifTrue: [self newLine]. - - aNode elements do: [:element | | isLast | - isLast := element = aNode elements last. - (self isEmptyLineMarker: element) ifFalse: [ - self visitNode: element. - isLast ifFalse: [ - config spaceBeforePointInArray ifTrue: [stream space]. - stream nextPut: $.]]. - - isLast ifFalse: [multiLine ifTrue: [self newLine] ifFalse: [stream space]]]]. + self printBraceStatements: aNode multiLine: multiLine]. - stream nextPut: $} \ No newline at end of file + self stream nextPut: $} \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatter.class/methodProperties.json b/packages/PoppyPrint-Core.package/PPFormatter.class/methodProperties.json index 2c71224..28d825f 100644 --- a/packages/PoppyPrint-Core.package/PPFormatter.class/methodProperties.json +++ b/packages/PoppyPrint-Core.package/PPFormatter.class/methodProperties.json @@ -5,7 +5,7 @@ "format:in:notifying:decorated:" : "tobe 3/10/2021 15:45", "formatCategory:" : "tobe 3/10/2021 14:59", "formatClass:" : "tobe 3/10/2021 14:59", - "formatMethod:" : "tobe 3/10/2021 13:32", + "formatMethod:" : "JW 6/1/2022 19:34", "formatPackage:" : "tobe 3/10/2021 14:59", "formatString:class:noPattern:" : "tobe 3/10/2021 15:47", "formatString:class:noPattern:notifying:" : "KD 6/15/2022 16:11", @@ -13,6 +13,7 @@ "formatString:class:noPattern:with:" : "Alexander Ungefug 6/1/2022 16:06", "stripMethodPattern:" : "tobe 3/19/2021 18:51" }, "instance" : { + "braceNodeHasMultiLineParts:" : "KD 7/18/2022 09:58", "comments" : "Alexander Ungefug 5/30/2022 19:04", "comments:" : "KD 6/15/2022 16:11", "config" : "Alexander Ungefug 6/1/2022 16:02", @@ -20,6 +21,7 @@ "contents" : "tobe 3/10/2021 14:58", "example:receiver:args:" : "tobe 3/10/2021 14:58", "formatTemporariesOf:isMethod:" : "KD 6/15/2022 16:11", + "getBraceNodeLength:" : "YH 6/8/2022 17:55", "indent" : "Alexander Ungefug 5/30/2022 19:04", "indent:" : "tobe 3/10/2021 14:58", "indent:around:" : "tobe 3/10/2021 14:58", @@ -27,7 +29,10 @@ "initialize" : "KD 6/15/2022 16:11", "isCaseOf:" : "KD 6/15/2022 16:11", "isEmptyLineMarker:" : "tobe 3/11/2021 10:46", - "isMultiLineMessage:" : "KD 6/15/2022 16:11", + "isMultiLineMessage:" : "tobe 3/11/2021 10:38", + "isOptionalEmptyLineMarker:" : "YH 6/8/2022 17:52", + "isOptionalNewLineMarker:" : "YH 6/9/2022 18:07", + "isTypeOfNewLineMarker:" : "KD 7/19/2022 09:18", "maxLineLength" : "tobe 3/10/2021 15:10", "needsParenthesisFor:" : "KD 6/15/2022 16:11", "newLine" : "tobe 3/10/2021 14:58", @@ -43,26 +48,28 @@ "printBinaryMessage:multiLine:" : "KD 6/15/2022 16:11", "printBlockComment:" : "tobe 3/11/2021 09:53", "printBlockStart:startWithNewLine:" : "tobe 3/10/2021 14:58", + "printBraceStatements:multiLine:" : "KD 7/19/2022 09:19", "printKeywordMessage:inCascade:multiLine:" : "tobe 3/10/2021 15:51", "printMethodComment:" : "tobe 3/11/2021 09:10", "printPragmas:" : "tobe 3/10/2021 14:58", "rawContents" : "tobe 3/10/2021 14:58", "reindent:" : "tobe 3/10/2021 15:51", "remainingLineLength" : "tobe 3/10/2021 15:27", + "shouldSkipStatement:" : "KD 7/21/2022 09:48", "stream" : "tobe 3/10/2021 14:58", "stream:" : "KD 6/15/2022 16:00", "visitAssignmentNode:" : "tobe 3/10/2021 14:58", - "visitBlockNode:" : "KD 6/15/2022 16:11", - "visitBraceNode:" : "KD 6/15/2022 16:05", + "visitBlockNode:" : "YH 6/28/2022 11:06", + "visitBraceNode:" : "KD 7/19/2022 09:20", "visitCascadeNode:" : "tobe 3/10/2021 17:17", "visitFutureNode:" : "tobe 3/10/2021 14:58", "visitInstanceVariableNode:" : "tobe 3/10/2021 14:58", "visitLiteralNode:" : "tobe 3/11/2021 09:09", "visitLiteralVariableNode:" : "tobe 3/10/2021 14:58", - "visitMessageNode:" : "KD 6/15/2022 16:11", - "visitMethodNode:" : "tobe 3/11/2021 11:38", + "visitMessageNode:" : "YH 6/19/2022 23:43", + "visitMethodNode:" : "JW 6/1/2022 20:51", "visitNode:" : "tobe 3/11/2021 10:00", - "visitReturnNode:" : "KD 6/15/2022 16:05", + "visitReturnNode:" : "YH 6/20/2022 14:41", "visitTempVariableNode:" : "tobe 3/10/2021 14:58", "visitTrackedAssignmentNode:" : "tobe 3/10/2021 14:58", "visitVariableNode:" : "tobe 3/10/2021 14:58", diff --git a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/formatToMaxLineWidth..st b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/formatToMaxLineWidth..st new file mode 100644 index 0000000..20168f8 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/formatToMaxLineWidth..st @@ -0,0 +1,4 @@ +accessing +formatToMaxLineWidth: aBoolean + + formatToMaxLineWidth := aBoolean \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/formatToMaxLineWidth.st b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/formatToMaxLineWidth.st new file mode 100644 index 0000000..f2112a4 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/formatToMaxLineWidth.st @@ -0,0 +1,4 @@ +accessing +formatToMaxLineWidth + + ^ formatToMaxLineWidth ifNil: [formatToMaxLineWidth := false] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/maxLineWidth..st b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/maxLineWidth..st new file mode 100644 index 0000000..85d5293 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/maxLineWidth..st @@ -0,0 +1,4 @@ +accessing +maxLineWidth: anInteger + + maxLineWidth := anInteger \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/maxLineWidth.st b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/maxLineWidth.st new file mode 100644 index 0000000..cc9fbe0 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/instance/maxLineWidth.st @@ -0,0 +1,4 @@ +accessing +maxLineWidth + + ^ maxLineWidth ifNil: [maxLineWidth := 83] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/methodProperties.json b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/methodProperties.json index d1250b6..de126e4 100644 --- a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/methodProperties.json +++ b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/methodProperties.json @@ -2,6 +2,10 @@ "class" : { "default" : "KD 6/15/2022 16:11" }, "instance" : { + "formatToMaxLineWidth" : "JW 6/1/2022 20:57", + "formatToMaxLineWidth:" : "JW 6/23/2022 10:53", + "maxLineWidth" : "JW 6/1/2022 19:28", + "maxLineWidth:" : "JW 6/23/2022 10:52", "spaceBeforeComma" : "KD 6/15/2022 16:07", "spaceBeforeComma:" : "YH 6/2/2022 14:16", "spaceBeforePointInArray" : "Alexander Ungefug 6/1/2022 15:59", diff --git a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/properties.json b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/properties.json index 8d7bee4..8eb3d50 100644 --- a/packages/PoppyPrint-Core.package/PPFormatterConfig.class/properties.json +++ b/packages/PoppyPrint-Core.package/PPFormatterConfig.class/properties.json @@ -7,7 +7,9 @@ "commentStamp" : "", "instvars" : [ "spaceBeforeComma", - "spaceBeforePointInArray" ], + "spaceBeforePointInArray", + "formatToMaxLineWidth", + "maxLineWidth" ], "name" : "PPFormatterConfig", "pools" : [ ], diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/README.md b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/README.md new file mode 100644 index 0000000..e69de29 diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/charAt..st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/charAt..st new file mode 100644 index 0000000..a883dde --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/charAt..st @@ -0,0 +1,4 @@ +accessing +charAt: aNumber + + ^ string at: aNumber \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/charAtIndex.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/charAtIndex.st new file mode 100644 index 0000000..b7fe0ab --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/charAtIndex.st @@ -0,0 +1,4 @@ +accessing +charAtIndex + + ^ self charAt: index \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/countTabs.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/countTabs.st new file mode 100644 index 0000000..a2606ee --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/countTabs.st @@ -0,0 +1,10 @@ +helper +countTabs + + | i | + i := index + 1. + tabCount := 0. + + [i <= string size and: [(self charAt: i) = Character tab]] whileTrue: [ + tabCount := tabCount + 1. + i := i + 1] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/format.withWindowWidth..st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/format.withWindowWidth..st new file mode 100644 index 0000000..a5ff6ec --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/format.withWindowWidth..st @@ -0,0 +1,19 @@ +formatting +format: aString withWindowWidth: aNumber + + aString isEmpty ifTrue: [^ aString]. + + string := aString. + maxWidth := aNumber. + self reset. + + [index <= string size] whileTrue: [ | seperator | + seperator := self charAtIndex. + self getNextWord. + + seperator = Character cr ifTrue: [self putNewlineAndCountTabs] ifFalse: [ + wordWidth + lineWidth + 1 > maxWidth + ifTrue: [self putIndentedNewlineAndWord] + ifFalse: [self putSeperatorAndWord]]]. + + ^ resultStream contents \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/getNextWord.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/getNextWord.st new file mode 100644 index 0000000..1080c18 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/getNextWord.st @@ -0,0 +1,13 @@ +helper +getNextWord + + | i | + i := index + 1. + wordWidth := 0. + wordStream reset. + + [i <= string size and: [inString or: [(seperators occurrencesOf: (self charAt: i)) = 0]]] whileTrue: [ + wordStream nextPut: (self charAt: i). + (self charAt: i) = $' ifTrue: [inString := inString not]. + wordWidth := wordWidth + 1. + i := i + 1] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putIndentedNewlineAndWord.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putIndentedNewlineAndWord.st new file mode 100644 index 0000000..2439b06 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putIndentedNewlineAndWord.st @@ -0,0 +1,8 @@ +put +putIndentedNewlineAndWord + + resultStream nextPut: Character cr; + next: tabCount + 1 put: Character tab; + nextPutAll: wordStream contents. + lineWidth := tabCount + 1 + wordWidth. + index := index + wordWidth + 1 \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putNewlineAndCountTabs.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putNewlineAndCountTabs.st new file mode 100644 index 0000000..dcb4dd8 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putNewlineAndCountTabs.st @@ -0,0 +1,17 @@ +put +putNewlineAndCountTabs + + self countTabs. + + resultStream nextPut: Character cr; + next: tabCount put: Character tab. + tabCount = 0 + ifTrue: [ + resultStream nextPutAll: wordStream contents. + index := index + wordWidth + 1] + ifFalse: [ + index := index + tabCount. + self getNextWord. + resultStream nextPutAll: wordStream contents. + index := index + wordWidth + 1]. + lineWidth := tabCount + wordWidth \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putSeperatorAndWord.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putSeperatorAndWord.st new file mode 100644 index 0000000..a5e3d18 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/putSeperatorAndWord.st @@ -0,0 +1,7 @@ +put +putSeperatorAndWord + + resultStream nextPut: self charAtIndex; + nextPutAll: wordStream contents. + lineWidth := lineWidth + wordWidth + 1. + index := index + wordWidth + 1 \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/reset.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/reset.st new file mode 100644 index 0000000..2c8be06 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/reset.st @@ -0,0 +1,13 @@ +initialize +reset + + seperators := { Character cr. Character tab. Character space}. + resultStream := '' writeStream. + wordStream := '' writeStream. + lineWidth := 0. + wordWidth := 0. + tabCount := 0. + index := 1. + inString := false. + + self skipToEndOfFirstWord \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/skipToEndOfFirstWord.st b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/skipToEndOfFirstWord.st new file mode 100644 index 0000000..4841d12 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/instance/skipToEndOfFirstWord.st @@ -0,0 +1,8 @@ +initialize +skipToEndOfFirstWord + + [index <= string size and: [inString or: [(seperators occurrencesOf: self charAtIndex) = 0]]] whileTrue: [ + resultStream nextPut: self charAtIndex. + self charAtIndex = $' ifTrue: [inString := inString not]. + lineWidth := lineWidth + 1. + index := index + 1] \ No newline at end of file diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/methodProperties.json b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/methodProperties.json new file mode 100644 index 0000000..0083347 --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/methodProperties.json @@ -0,0 +1,14 @@ +{ + "class" : { + }, + "instance" : { + "charAt:" : "JW 5/31/2022 11:05", + "charAtIndex" : "JW 5/31/2022 11:05", + "countTabs" : "JW 5/31/2022 11:12", + "format:withWindowWidth:" : "JW 6/1/2022 20:52", + "getNextWord" : "JW 6/1/2022 20:09", + "putIndentedNewlineAndWord" : "JW 6/23/2022 11:45", + "putNewlineAndCountTabs" : "JW 6/23/2022 11:46", + "putSeperatorAndWord" : "JW 6/23/2022 11:47", + "reset" : "JW 6/1/2022 20:05", + "skipToEndOfFirstWord" : "JW 6/1/2022 20:10" } } diff --git a/packages/PoppyPrint-Core.package/PPWindowFormatter.class/properties.json b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/properties.json new file mode 100644 index 0000000..bb65cdf --- /dev/null +++ b/packages/PoppyPrint-Core.package/PPWindowFormatter.class/properties.json @@ -0,0 +1,23 @@ +{ + "category" : "PoppyPrint-Core", + "classinstvars" : [ + ], + "classvars" : [ + ], + "commentStamp" : "", + "instvars" : [ + "string", + "resultStream", + "wordStream", + "seperators", + "lineWidth", + "wordWidth", + "tabCount", + "index", + "maxWidth", + "inString" ], + "name" : "PPWindowFormatter", + "pools" : [ + ], + "super" : "Object", + "type" : "normal" } diff --git a/packages/PoppyPrint-Core.package/String.extension/instance/codeWithEmptyLineMarkersStartingAt..st b/packages/PoppyPrint-Core.package/String.extension/instance/codeWithEmptyLineMarkersStartingAt..st index 8e5c945..7b0ab76 100644 --- a/packages/PoppyPrint-Core.package/String.extension/instance/codeWithEmptyLineMarkersStartingAt..st +++ b/packages/PoppyPrint-Core.package/String.extension/instance/codeWithEmptyLineMarkersStartingAt..st @@ -1,25 +1,41 @@ *PoppyPrint-Core codeWithEmptyLineMarkersStartingAt: aNumber - " insert #ppEmptyLine symbols where double newlines are found, for later use by e.g. a formatter. Insert no markers earlier than aNumber " + " insert #ppOptionalEmptyLine and #ppEmptyLine symbols where double or more newlines are found, #optionalNewlines where single cr's are found, for later use by e.g. a formatter. Insert no markers earlier than aNumber " | ranges crPositions write lastWasStatement | - ranges := (Array streamContents: [:stream | - Scanner new scanTokenPositionsIn: self into: [:start :end | start <= end ifTrue: [stream nextPut: (start to: end)]]]). + ranges := Array streamContents: [:stream | + Scanner new + scanTokenPositionsIn: self + into: [:start :end | start <= end ifTrue: [stream nextPut: (start to: end)]]]. ranges := self mergeConsecutiveComments: ranges. - lastWasStatement := false. - crPositions := Array streamContents: [:stream | - stream nextPut: 1. + crPositions := Array streamContents: [:stream | | numberOfNewLines | + numberOfNewLines := 0. + stream nextPut: {1. numberOfNewLines}. ranges overlappingPairsDo: [:first :second | - (((first size = 1 and: [(self at: first start) = $.]) or: [lastWasStatement and: [(self at: first stop) = $"]]) - and: [((self copyFrom: first stop + 1 to: second start) occurrencesOf: Character cr) > 1]) ifTrue: [ - lastWasStatement := (self at: first start) = $.. - stream nextPut: ((self copyFrom: first stop + 1 to: second start) lastIndexOf: Character cr) + first stop]]]. - + numberOfNewLines := (self copyFrom: first stop + 1 to: second start) occurrencesOf: Character cr. + ( + ( + (first size = 1 and: [(self at: first start) = $.]) + or: + [lastWasStatement and: [(self at: first stop) = $"]] + ) and: + [numberOfNewLines > 0] + ) ifTrue: [ + stream nextPut: { + ((self copyFrom: first stop + 1 to: second start) lastIndexOf: Character cr) + first stop. + numberOfNewLines}]. + lastWasStatement := (self at: first start) = $..]]. write := '' writeStream. - crPositions overlappingPairsDo: [:start :end | + crPositions overlappingPairsDo: [:startPair :endPair | | start end | + start := startPair first. + end := endPair first. write nextPutAll: (self copyFrom: start to: end - 1). - end > aNumber ifTrue: [write nextPutAll: '#ppEmptyLine.']]. - write nextPutAll: (self copyFrom: crPositions last to: self size). - - ^ write contents \ No newline at end of file + end > aNumber ifTrue: [ + (endPair second = 1) + ifTrue: [write nextPutAll: '#ppOptionalNewLine.'.] + ifFalse: [ + write nextPutAll: '#ppEmptyLine.'. + endPair second - 2 timesRepeat: [write nextPutAll: '#ppOptionalEmptyLine.']]]]. + write nextPutAll: (self copyFrom: crPositions last first to: self size). + ^ write contents diff --git a/packages/PoppyPrint-Core.package/String.extension/methodProperties.json b/packages/PoppyPrint-Core.package/String.extension/methodProperties.json index f85b78b..32ac4a2 100644 --- a/packages/PoppyPrint-Core.package/String.extension/methodProperties.json +++ b/packages/PoppyPrint-Core.package/String.extension/methodProperties.json @@ -4,6 +4,6 @@ "instance" : { "codeWithEmptyLineMarkers" : "tobe 3/11/2021 11:43", "codeWithEmptyLineMarkersNoPattern:" : "tobe 3/11/2021 11:48", - "codeWithEmptyLineMarkersStartingAt:" : "tobe 3/11/2021 13:14", + "codeWithEmptyLineMarkersStartingAt:" : "YH 6/16/2022 19:19", "mergeConsecutiveComments:" : "tobe 3/11/2021 12:42", "methodWithEmptyLineMarkers" : "tobe 3/20/2021 10:41" } } diff --git a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/getConfigWindowWidth..st b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/getConfigWindowWidth..st new file mode 100644 index 0000000..d6aa221 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/getConfigWindowWidth..st @@ -0,0 +1,4 @@ +helper +getConfigWindowWidth: aNumber + + ^ PPFormatterConfig default formatToMaxLineWidth: true; maxLineWidth: aNumber. \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testArrayInBrace.st b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testArrayInBrace.st new file mode 100644 index 0000000..331f7e4 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testArrayInBrace.st @@ -0,0 +1,10 @@ +tests - keepNewLines +testArrayInBrace + + self canFormat: 'braceTest + + { + 0. + #(0 0 0). + 0. + 0}' \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testEmptyLinesInBrace.st b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testEmptyLinesInBrace.st new file mode 100644 index 0000000..6b73d02 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testEmptyLinesInBrace.st @@ -0,0 +1,11 @@ +tests - keepNewLines +testEmptyLinesInBrace + + self canFormat: 'braceTest + + { + 0. + 0. + + 0. + 0}' \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth1.st b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth1.st new file mode 100644 index 0000000..3311453 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth1.st @@ -0,0 +1,13 @@ +tests - WindowWidth +testSmallWindowWidth1 + + self canFormat: +'test + + aaa aa aa aaa' + as: +'test + + aaa aa aa + aaa' + with: (self getConfigWindowWidth: 10) \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth2.st b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth2.st new file mode 100644 index 0000000..e2d26fc --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth2.st @@ -0,0 +1,13 @@ +tests - WindowWidth +testSmallWindowWidth2 + + self canFormat: +'test + + aaa aa aaa aaa' + as: +'test + + aaa aa + aaa aaa' + with: (self getConfigWindowWidth: 10) \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth3.st b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth3.st new file mode 100644 index 0000000..acdfbcc --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/instance/testSmallWindowWidth3.st @@ -0,0 +1,12 @@ +tests - WindowWidth +testSmallWindowWidth3 + + self canFormat: +'test + + ''aaa aa aaa aaa''' + as: +'test + + ''aaa aa aaa aaa''' + with: (self getConfigWindowWidth: 10) \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/methodProperties.json b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/methodProperties.json index 07e86b5..d9ec56c 100644 --- a/packages/PoppyPrint-Tests.package/PPFormatterTest.class/methodProperties.json +++ b/packages/PoppyPrint-Tests.package/PPFormatterTest.class/methodProperties.json @@ -12,7 +12,9 @@ "exampleMorphDoLayoutIn" : "tobe 3/11/2021 09:00", "getConfigSpacesBeforeComma" : "YH 6/2/2022 10:20", "getConfigSpacesBeforePointInArray" : "KD 6/15/2022 15:56", - "testAllMethods" : "KD 6/15/2022 16:11", + "getConfigWindowWidth:" : "JW 6/15/2022 15:47", + "testAllMethods" : "YH 6/20/2022 14:48", + "testArrayInBrace" : "YH 6/9/2022 19:04", "testBinaryMessageChain" : "tobe 3/11/2021 10:58", "testBinaryMessageChainWithParenthesis" : "tobe 3/11/2021 13:33", "testCommentAtStartOfBlock" : "tobe 3/11/2021 10:08", @@ -22,6 +24,7 @@ "testEmptyLineInArray" : "tobe 3/11/2021 10:45", "testEmptyLineInCaseOf" : "tobe 3/11/2021 10:54", "testEmptyLinesBetweenComments" : "tobe 3/11/2021 11:35", + "testEmptyLinesInBrace" : "YH 6/9/2022 11:37", "testEmptyMethod" : "tobe 3/10/2021 14:58", "testGithubIssue7" : "tobe 3/11/2021 11:15", "testInlineCommentWithNewline" : "KD 6/15/2022 16:11", @@ -43,6 +46,9 @@ "testReindentMultilineComment" : "tobe 3/11/2021 10:08", "testShortArray" : "tobe 3/11/2021 10:41", "testShortCaseOf" : "tobe 3/11/2021 10:40", + "testSmallWindowWidth1" : "JW 6/23/2022 10:56", + "testSmallWindowWidth2" : "JW 6/23/2022 10:56", + "testSmallWindowWidth3" : "JW 6/23/2022 10:57", "testSpaceBeforeComma" : "YH 6/2/2022 10:46", "testSpaceBeforePointInArray" : "KD 6/15/2022 15:57", "testSubexpressionComment" : "tobe 3/11/2021 10:08", diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/README.md b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/README.md new file mode 100644 index 0000000..e69de29 diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/canFormat.toDefaultWindowWidth..st b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/canFormat.toDefaultWindowWidth..st new file mode 100644 index 0000000..37c01f0 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/canFormat.toDefaultWindowWidth..st @@ -0,0 +1,4 @@ +helper +canFormat: aString toDefaultWindowWidth: anotherString + + self assert: anotherString equals: (PPWindowFormatter new format: aString withWindowWidth: 83) \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/canFormat.toZeroWindowWidth..st b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/canFormat.toZeroWindowWidth..st new file mode 100644 index 0000000..eb36607 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/canFormat.toZeroWindowWidth..st @@ -0,0 +1,4 @@ +helper +canFormat: aString toZeroWindowWidth: anotherString + + self assert: anotherString equals: (PPWindowFormatter new format: aString withWindowWidth: 0) \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth1.st b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth1.st new file mode 100644 index 0000000..4520a7b --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth1.st @@ -0,0 +1,13 @@ +tests +testFormattingToDefaultWindowWidth1 + + self canFormat: + 'test + ertad aweasd wed + asdasd + asdasd asdasd asd asd as dd' + toDefaultWindowWidth: + 'test + ertad aweasd wed + asdasd + asdasd asdasd asd asd as dd' \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth2.st b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth2.st new file mode 100644 index 0000000..45c91bb --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth2.st @@ -0,0 +1,9 @@ +tests +testFormattingToDefaultWindowWidth2 + + self canFormat: + 'test + abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc' + toDefaultWindowWidth: + 'test + abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc' \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth3.st b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth3.st new file mode 100644 index 0000000..dd59109 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToDefaultWindowWidth3.st @@ -0,0 +1,10 @@ +tests +testFormattingToDefaultWindowWidth3 + + self canFormat: + 'test + abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc' + toDefaultWindowWidth: + 'test + abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc + abc' \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToZeroWidth1.st b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToZeroWidth1.st new file mode 100644 index 0000000..18bdd72 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/instance/testFormattingToZeroWidth1.st @@ -0,0 +1,20 @@ +tests +testFormattingToZeroWidth1 + + self canFormat: + 'test + ertad aweasd wed + asdasd + asdasd asdasd asd asd as dd' + toZeroWindowWidth: + 'test + ertad + aweasd + wed + asdasd + asdasd + asdasd + asd + asd + as + dd' \ No newline at end of file diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/methodProperties.json b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/methodProperties.json new file mode 100644 index 0000000..75bf6b6 --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/methodProperties.json @@ -0,0 +1,10 @@ +{ + "class" : { + }, + "instance" : { + "canFormat:toDefaultWindowWidth:" : "JW 6/23/2022 11:49", + "canFormat:toZeroWindowWidth:" : "JW 6/23/2022 11:49", + "testFormattingToDefaultWindowWidth1" : "JW 6/23/2022 11:49", + "testFormattingToDefaultWindowWidth2" : "JW 6/23/2022 11:49", + "testFormattingToDefaultWindowWidth3" : "JW 6/23/2022 11:49", + "testFormattingToZeroWidth1" : "JW 6/23/2022 11:50" } } diff --git a/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/properties.json b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/properties.json new file mode 100644 index 0000000..42b32bf --- /dev/null +++ b/packages/PoppyPrint-Tests.package/PPWindowFormatterTest.class/properties.json @@ -0,0 +1,14 @@ +{ + "category" : "PoppyPrint-Tests", + "classinstvars" : [ + ], + "classvars" : [ + ], + "commentStamp" : "", + "instvars" : [ + ], + "name" : "PPWindowFormatterTest", + "pools" : [ + ], + "super" : "TestCase", + "type" : "normal" }