Chris Muller uploaded a new version of Compiler to project The Inbox:
http://source.squeak.org/inbox/Compiler-cmm.329.mcz ==================== Summary ==================== Name: Compiler-cmm.329 Author: cmm Time: 16 August 2016, 2:44:49.238535 pm UUID: 27532efe-b045-474b-a197-43c6cea193ae Ancestors: Compiler-tfel.327 Kent Beckian purposefully plenk'd pretty printing. =============== Diff against Compiler-tfel.327 =============== Item was added: + ----- Method: AssignmentNode>>isComplex (in category 'testing') ----- + isComplex + ^ value isComplex! Item was changed: ----- Method: AssignmentNode>>printOn:indent: (in category 'printing') ----- printOn: aStream indent: level variable printOn: aStream indent: level. aStream nextPutAll: ' := '. + value printOn: aStream indent: level! - value printOn: aStream indent: level + 2! Item was changed: ----- Method: BlockNode>>isComplex (in category 'testing') ----- isComplex + ^ statements size > 1 or: + [ (statements size = 1 and: [ statements first isComplex ]) or: + [ arguments size > 0 or: [ temporaries size > 0 ] ] ]! - - ^statements size > 1 or: [statements size = 1 and: [statements first isComplex]]! Item was changed: ----- Method: BlockNode>>printArgumentsOn:indent: (in category 'printing') ----- + printArgumentsOn: aStream indent: level - printArgumentsOn: aStream indent: level arguments size = 0 ifTrue: [^ self]. + arguments do: + [ : arg | + aStream nextPut: $: ; + space; + nextPutAll: arg key; + space ]. + aStream + nextPut: $|; + space! - arguments do: - [:arg | aStream nextPut: $:; nextPutAll: arg key; space]. - aStream nextPut: $|; space. - "If >0 args and >1 statement, put all statements on separate lines" - statements size > 1 ifTrue: - [aStream crtab: level]! Item was changed: ----- Method: BlockNode>>printOn:indent: (in category 'printing') ----- + printOn: aStream indent: level + aStream + nextPut: $[ ; + space. + self + printArgumentsOn: aStream + indent: level. + (self + printTemporaries: temporaries + on: aStream + doPrior: [ ] ) ifTrue: + [ "If >0 temps and >1 statement, put all statements on separate lines" + statements size > 1 + ifTrue: [ aStream crtab: level ] + ifFalse: [ aStream space] ] . + self + printStatementsOn: aStream + indent: level. + aStream + space ; + nextPut: $]! - printOn: aStream indent: level - - "statements size <= 1 ifFalse: [aStream crtab: level]." - aStream nextPut: $[. - self printArgumentsOn: aStream indent: level. - (self printTemporaries: temporaries on: aStream doPrior: []) ifTrue: - ["If >0 temps and >1 statement, put all statements on separate lines" - statements size > 1 - ifTrue: [aStream crtab: level] - ifFalse: [aStream space]]. - self printStatementsOn: aStream indent: level. - aStream nextPut: $]! Item was changed: ----- Method: BlockNode>>printWithClosureAnalysisOn:indent: (in category 'printing') ----- printWithClosureAnalysisOn: aStream indent: level + aStream nextPut: $[; space. - aStream nextPut: $[. blockExtent ifNotNil: [aStream print: blockExtent]. self printWithClosureAnalysisArgumentsOn: aStream indent: level. self printWithClosureAnalysisTemporariesOn: aStream indent: level. self printWithClosureAnalysisStatementsOn: aStream indent: level. + aStream space; nextPut: $]! - aStream nextPut: $]! Item was changed: ----- Method: BraceNode>>printOn:indent: (in category 'printing') ----- + printOn: aStream indent: level - printOn: aStream indent: level - aStream nextPut: ${. + 1 + to: elements size + do: + [ : i | + (elements at: i) + printOn: aStream + indent: level. + i < elements size ifTrue: + [ aStream + nextPutAll: '. ' ; + crtab: level ] ]. - 1 to: elements size do: - [:i | (elements at: i) printOn: aStream indent: level. - i < elements size ifTrue: [aStream nextPutAll: '. ']]. aStream nextPut: $}! Item was added: + ----- Method: CascadeNode>>isComplex (in category 'testing') ----- + isComplex + ^ true! Item was changed: ----- Method: CascadeNode>>printOn:indent:precedence: (in category 'printing') ----- printOn: aStream indent: level precedence: p + p > 0 ifTrue: [ aStream nextPut: $( ]. + messages first + printReceiver: receiver + on: aStream + indent: level. + 1 + to: messages size + do: + [ : i | + aStream crtab: level + 1. + (messages at: i) + printOn: aStream + indent: level. + i < messages size ifTrue: [ aStream nextPutAll: ' ;' ] ]. + p > 0 ifTrue: [ aStream nextPut: $) ]! - - p > 0 ifTrue: [aStream nextPut: $(]. - messages first printReceiver: receiver on: aStream indent: level. - 1 to: messages size do: - [:i | (messages at: i) printOn: aStream indent: level. - i < messages size ifTrue: - [aStream nextPut: $;. - messages first precedence >= 2 ifTrue: [aStream crtab: level + 1]]]. - p > 0 ifTrue: [aStream nextPut: $)]! Item was changed: ----- Method: MessageNode>>isComplex (in category 'testing') ----- isComplex + ^ (special + between: 1 + and: 10) + or: + [ arguments size > 1 + or: + [ receiver isComplex or: [ arguments anySatisfy: [ : each | each isComplex ] ] ] ]! - - ^(special between: 1 and: 10) or: [arguments size > 2 or: [receiver isComplex]]! Item was changed: ----- Method: MessageNode>>printIfOn:indent: (in category 'printing') ----- + printIfOn: aStream indent: level + receiver ifNotNil: + [ receiver + printOn: aStream + indent: level + precedence: precedence ]. + (arguments last isJust: NodeNil) ifTrue: [ ^ self + printKeywords: #ifTrue: + arguments: (Array with: arguments first) + on: aStream + indent: level ]. + (arguments last isJust: NodeFalse) ifTrue: [ ^ self + printKeywords: #and: + arguments: (Array with: arguments first) + on: aStream + indent: level ]. + (arguments first isJust: NodeNil) ifTrue: [ ^ self + printKeywords: #ifFalse: + arguments: (Array with: arguments last) + on: aStream + indent: level ]. + (arguments first isJust: NodeTrue) ifTrue: [ ^ self + printKeywords: #or: + arguments: (Array with: arguments last) + on: aStream + indent: level ]. + self + printKeywords: #ifTrue:ifFalse: + arguments: arguments + on: aStream + indent: level! - printIfOn: aStream indent: level - - receiver ifNotNil: - [receiver printOn: aStream indent: level + 1 precedence: precedence]. - (arguments last isJust: NodeNil) ifTrue: - [^self printKeywords: #ifTrue: arguments: (Array with: arguments first) - on: aStream indent: level]. - (arguments last isJust: NodeFalse) ifTrue: - [^self printKeywords: #and: arguments: (Array with: arguments first) - on: aStream indent: level]. - (arguments first isJust: NodeNil) ifTrue: - [^self printKeywords: #ifFalse: arguments: (Array with: arguments last) - on: aStream indent: level]. - (arguments first isJust: NodeTrue) ifTrue: - [^self printKeywords: #or: arguments: (Array with: arguments last) - on: aStream indent: level]. - self printKeywords: #ifTrue:ifFalse: arguments: arguments - on: aStream indent: level! Item was changed: ----- Method: MessageNode>>printKeywords:arguments:on:indent: (in category 'printing') ----- + printKeywords: key arguments: args on: aStream indent: level - printKeywords: key arguments: args on: aStream indent: level | keywords indent arg kwd doCrTab | args size = 0 ifTrue: + [ aStream + space ; + nextPutAll: key. + ^ self ]. + keywords := key keywords. + doCrTab := args size > 1. + 1 + to: (args size min: keywords size) + do: + [ : i | arg := args at: i. + kwd := keywords at: i. + doCrTab + ifTrue: + [ aStream crtab: level + 1. + indent := 1 + "newline after big args" ] + ifFalse: + [ aStream space. + indent := 0 ]. + aStream nextPutAll: kwd. + arg isComplex + ifTrue: [ aStream crtab: level + indent + 1 ] + ifFalse: [ aStream space ]. + arg + printOn: aStream + indent: level + 1 + indent + precedence: + (precedence = 2 + ifTrue: [ 1 ] + ifFalse: [ precedence ]) ]! - [aStream space; nextPutAll: key. - ^self]. - keywords := key asString keywords. - doCrTab := args size > 2 - or: [{receiver} , args anySatisfy: - [:thisArg | - thisArg notNil - and: [thisArg isBlockNode - or: [thisArg isMessageNode and: [thisArg precedence >= 3]]]]]. - 1 to: (args size min: keywords size) do: - [:i | - arg := args at: i. - kwd := keywords at: i. - doCrTab - ifTrue: [aStream crtab: level+1. indent := 1] "newline after big args" - ifFalse: [aStream space. indent := 0]. - aStream nextPutAll: kwd; space. - arg printOn: aStream - indent: level + 1 + indent - precedence: (precedence = 2 ifTrue: [1] ifFalse: [precedence])]! Item was changed: ----- Method: ParseNode>>printSingleComment:on:indent: (in category 'private') ----- printSingleComment: aString on: aStream indent: indent + "Print the comment string, assuming it has been indented indent tabs. Break the string at word breaks, given the widths in the default font, at 450 points." + aStream nextPutAll: aString! - "Print the comment string, assuming it has been indented indent tabs. - Break the string at word breaks, given the widths in the default - font, at 450 points." - - | readStream word position lineBreak font wordWidth tabWidth spaceWidth lastChar | - readStream := ReadStream on: aString. - font := TextStyle default defaultFont. - tabWidth := TextConstants at: #DefaultTab. - spaceWidth := font widthOf: Character space. - position := indent * tabWidth. - lineBreak := 450. - [readStream atEnd] - whileFalse: - [word := self nextWordFrom: readStream setCharacter: [:lc | lastChar := lc]. - wordWidth := word inject: 0 into: [:width :char | width + (font widthOf: char)]. - position := position + wordWidth. - position > lineBreak - ifTrue: - [aStream skip: -1; crtab: indent. - position := indent * tabWidth + wordWidth + spaceWidth. - lastChar = Character cr - ifTrue: [[readStream peekFor: Character tab] whileTrue]. - word isEmpty ifFalse: [aStream nextPutAll: word; space]] - ifFalse: - [aStream nextPutAll: word. - readStream atEnd - ifFalse: - [position := position + spaceWidth. - aStream space]. - lastChar = Character cr - ifTrue: - [aStream skip: -1; crtab: indent. - position := indent * tabWidth. - [readStream peekFor: Character tab] whileTrue]]]! |
Hi Chris, we could benefit from references such as the book and page number for these kind of changes. Maybe in the comments of the particular method? Such references can then support discussions and decision making for future modifications in the realm of the pretty printer. (Note that I personally do not like the rectangular block style because it hurts *my* eyes. ;-) Maybe I am thinking about and looking at blocks differently. Don't know. A pluggable/configurable pretty printer would be nice. We once had a student's project about this. That project used another parser though...) Best, Marcel
|
Hi Marcel,
Good idea. This diff actually looks shorter than I thought, so probably not a lot of work.
That would be a great project. I remember an add-on for VisualAge that did that. Its configuration dialog had a the settings in the top half, and a valid code sample in the bottom half which revealed all of syntactical possibilities, so you could see the effects as your configuration options as they were changed... it was pretty cool. Best, Chris
|
Free forum by Nabble | Edit this page |