Skip to content
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

66 comma and spaces #71

Merged
merged 4 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
format
formatString: aString class: aClass noPattern: aBoolean notifying: anObject with: aPPFormatterConfig

| formatter methodNode |
self example: 'string test' receiver: [PPFormatter] args: [{'self halt; yourself'. UndefinedObject. true. nil}].

methodNode := PPParser new
encoderClass: PPFormatEncoder;
parse: (aString string codeWithEmptyLineMarkersNoPattern: aBoolean)
class: aClass
noPattern: aBoolean
notifying: anObject
ifFail: nil.

formatter := self new initForNode: methodNode; config: aPPFormatterConfig.
methodNode accept: formatter.
^ aBoolean ifTrue: [self stripMethodPattern: formatter contents] ifFalse: [formatter contents]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
format
formatString: aString class: aClass noPattern: aBoolean with: aPPFormatterConfig

^ self formatString: aString class: aClass noPattern: aBoolean notifying: nil with: aPPFormatterConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
comments: anObject

comments := anObject.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
comments

^ comments
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
config: aPPFormatterConfig

config := aPPFormatterConfig.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
config

^ config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
indent

^ indent
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
initialize-release
initialize

super initialize.
stream := '' writeStream.
indent := 0.
preFormatCache := Dictionary new.
comments := OrderedCollection new
comments := OrderedCollection new.
config := PPFormatterConfig default.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
parents

^ parents
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
preFormatCache

^ preFormatCache
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
printing
printBinaryMessage: aNode multiLine: multiLine

aNode originalSelector ~= #, ifTrue: [stream space].
stream
(aNode originalSelector ~= #, or: [config spaceBeforeCommaInArray]) ifTrue: [stream space].
stream
nextPutAll: aNode originalSelector;
space.
self indent: (multiLine ifTrue: [1] ifFalse: [0]) around: [self visitNode: aNode originalArguments first].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
stream: anObject

stream := anObject.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ visitBraceNode: aNode
self indent: (multiLine ifTrue: [1] ifFalse: [0]) around: [
multiLine ifTrue: [self newLine].

aNode elements do: [:element | | isLast |
isLast := element = aNode elements last.

aNode elements do: [:element | | isLast |
isLast := element = aNode elements last.
(self isEmptyLineMarker: element) ifFalse: [
self visitNode: element.
isLast ifFalse: [stream nextPut: $.]].

self visitNode: element.
isLast ifFalse: [config spaceBeforePointInArray ifTrue: [stream space]. stream nextPut: $.]].


isLast ifFalse: [multiLine ifTrue: [self newLine] ifFalse: [stream space]]]].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ visitMessageNode: aNode
| multiLine isInCascade |
isInCascade := ((self parentFor: aNode) isKindOf: CascadeNode) and: [(self parentFor: aNode) originalReceiver ~= aNode].
isInCascade ifFalse: [self visitNode: aNode originalReceiver].

aNode originalSelector isUnary ifTrue: [
isInCascade ifFalse: [stream space].
aNode originalSelector isUnary ifTrue: [
isInCascade ifFalse: [stream space].
^ stream nextPutAll: aNode originalSelector].

multiLine := self isMultiLineMessage: aNode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ visiting
visitReturnNode: aNode

stream nextPutAll: '^ '.
self visitNode: aNode expr
self visitNode: aNode expr.

Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,39 @@
"formatMethod:" : "tobe 3/10/2021 13:32",
"formatPackage:" : "tobe 3/10/2021 14:59",
"formatString:class:noPattern:" : "tobe 3/10/2021 15:47",
"formatString:class:noPattern:notifying:" : "tobe 3/20/2021 10:44",
"formatString:class:noPattern:notifying:" : "Alexander Ungefug 6/1/2022 15:37",
"formatString:class:noPattern:notifying:with:" : "Alexander Ungefug 6/1/2022 16:05",
"formatString:class:noPattern:with:" : "Alexander Ungefug 6/1/2022 16:06",
"stripMethodPattern:" : "tobe 3/19/2021 18:51" },
"instance" : {
"comments" : "Alexander Ungefug 5/30/2022 19:04",
"comments:" : "Alexander Ungefug 5/30/2022 19:04",
"config" : "Alexander Ungefug 6/1/2022 16:02",
"config:" : "Alexander Ungefug 6/1/2022 16:02",
"contents" : "tobe 3/10/2021 14:58",
"example:receiver:args:" : "tobe 3/10/2021 14:58",
"formatTemporariesOf:isMethod:" : "tobe 3/10/2021 14:58",
"indent" : "Alexander Ungefug 5/30/2022 19:04",
"indent:" : "tobe 3/10/2021 14:58",
"indent:around:" : "tobe 3/10/2021 14:58",
"initForNode:" : "tobe 3/10/2021 14:58",
"initialize" : "tobe 3/10/2021 14:58",
"initialize" : "Alexander Ungefug 5/30/2022 19:06",
"isCaseOf:" : "tobe 3/11/2021 10:40",
"isEmptyLineMarker:" : "tobe 3/11/2021 10:46",
"isMultiLineMessage:" : "tobe 3/11/2021 10:38",
"maxLineLength" : "tobe 3/10/2021 15:10",
"needsParenthesisFor:" : "tobe 3/11/2021 13:43",
"newLine" : "tobe 3/10/2021 14:58",
"parentFor:" : "tobe 3/10/2021 14:58",
"parents" : "Alexander Ungefug 5/30/2022 19:04",
"parents:" : "tobe 3/10/2021 14:58",
"preFormat:" : "tobe 3/11/2021 09:55",
"preFormatCache" : "Alexander Ungefug 5/30/2022 19:04",
"preFormatCache:" : "tobe 3/10/2021 14:58",
"precedenceOf:" : "tobe 3/10/2021 14:58",
"prepareMultilineLiteral:" : "tobe 3/11/2021 09:09",
"printAllCommentsOf:lastStatement:" : "tobe 3/11/2021 10:08",
"printBinaryMessage:multiLine:" : "tobe 3/10/2021 17:16",
"printBinaryMessage:multiLine:" : "Alexander Ungefug 5/30/2022 19:12",
"printBlockComment:" : "tobe 3/11/2021 09:53",
"printBlockStart:startWithNewLine:" : "tobe 3/10/2021 14:58",
"printKeywordMessage:inCascade:multiLine:" : "tobe 3/10/2021 15:51",
Expand All @@ -41,18 +50,19 @@
"reindent:" : "tobe 3/10/2021 15:51",
"remainingLineLength" : "tobe 3/10/2021 15:27",
"stream" : "tobe 3/10/2021 14:58",
"stream:" : "Alexander Ungefug 5/30/2022 19:04",
"visitAssignmentNode:" : "tobe 3/10/2021 14:58",
"visitBlockNode:" : "tobe 3/11/2021 10:46",
"visitBraceNode:" : "tobe 3/11/2021 10:49",
"visitBraceNode:" : "Alexander Ungefug 5/30/2022 19:08",
"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:" : "tobe 3/10/2021 14:58",
"visitMessageNode:" : "Alexander Ungefug 5/30/2022 19:13",
"visitMethodNode:" : "tobe 3/11/2021 11:38",
"visitNode:" : "tobe 3/11/2021 10:00",
"visitReturnNode:" : "tobe 3/10/2021 14:58",
"visitReturnNode:" : "Alexander Ungefug 6/1/2022 15:33",
"visitTempVariableNode:" : "tobe 3/10/2021 14:58",
"visitTrackedAssignmentNode:" : "tobe 3/10/2021 14:58",
"visitVariableNode:" : "tobe 3/10/2021 14:58",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"indent",
"parents",
"preFormatCache",
"comments" ],
"comments",
"config" ],
"name" : "PPFormatter",
"pools" : [
],
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
default
"Default is lazy initialized"
^ self new.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
spaceBeforeCommaInArray: anObject

spaceBeforeCommaInArray := anObject.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
spaceBeforeCommaInArray

^ spaceBeforeCommaInArray ifNil: [spaceBeforeCommaInArray := false].

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
spaceBeforePointInArray: anObject

spaceBeforePointInArray := anObject.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
spaceBeforePointInArray

^ spaceBeforePointInArray ifNil: [spaceBeforePointInArray := false]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"class" : {
"default" : "Alexander Ungefug 5/30/2022 19:03" },
"instance" : {
"spaceBeforeCommaInArray" : "Alexander Ungefug 5/31/2022 11:00",
"spaceBeforeCommaInArray:" : "Alexander Ungefug 5/30/2022 18:59",
"spaceBeforePointInArray" : "Alexander Ungefug 6/1/2022 15:59",
"spaceBeforePointInArray:" : "Alexander Ungefug 5/30/2022 18:59" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"category" : "PoppyPrint-Core",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"spaceBeforeCommaInArray",
"spaceBeforePointInArray" ],
"name" : "PPFormatterConfig",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
canFormat: aString as: anotherString with: aPPFormatterConfig

self assert: anotherString equals: (PPFormatter formatString: aString class: UndefinedObject noPattern: false with: aPPFormatterConfig)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
canFormat: aString with: aPPFormatterConfig

^ self canFormat: aString as: aString with: aPPFormatterConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
getConfigSpacesinArray

^ PPFormatterConfig default spaceBeforePointInArray: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests - spaces in Array
testSpaceBeforeCommaInArray

self canFormat:
'test

{0. 0. 0. 0. 0. 1}'
as:
'test

{0 . 0 . 0 . 0 . 0 . 1}'
with: self getConfigSpacesinArray
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
"instance" : {
"canFormat:" : "ct 4/7/2021 11:59",
"canFormat:as:" : "tobe 3/11/2021 12:24",
"canFormat:as:with:" : "Alexander Ungefug 6/1/2022 16:06",
"canFormat:with:" : "Alexander Ungefug 6/1/2022 16:11",
"canFormatMethod:" : "ct 4/7/2021 15:51",
"exampleExplorerContents" : "tobe 3/11/2021 10:20",
"exampleMorphDoLayoutIn" : "tobe 3/11/2021 09:00",
"getConfigSpacesinArray" : "Alexander Ungefug 6/1/2022 16:09",
"testAllMethods" : "KD 5/11/2022 18:29",
"testBinaryMessageChain" : "tobe 3/11/2021 10:58",
"testBinaryMessageChainWithParenthesis" : "tobe 3/11/2021 13:33",
Expand Down Expand Up @@ -39,6 +42,7 @@
"testReindentMultilineComment" : "tobe 3/11/2021 10:08",
"testShortArray" : "tobe 3/11/2021 10:41",
"testShortCaseOf" : "tobe 3/11/2021 10:40",
"testSpaceBeforeCommaInArray" : "Alexander Ungefug 6/1/2022 16:13",
"testSubexpressionComment" : "tobe 3/11/2021 10:08",
"testTemporaries" : "tobe 3/11/2021 11:39",
"testTooLongLine" : "tobe 3/11/2021 09:21",
Expand Down