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

Abgabe 2020 #156

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
666a55d
Split class methods in new class
felixauringer Aug 5, 2020
fd6179d
Replace remaining occurences of OPPrinter
felixauringer Aug 5, 2020
a814344
Extract handling of indentation in own class
felixauringer Aug 5, 2020
4002b73
Extract handling of comments in own class
felixauringer Aug 5, 2020
a3cbad5
Rename 'showingOmegaPrint' to 'isShowingOmegaPrint'
felixauringer Aug 5, 2020
161e864
Add terminalExpression
T4rikA Aug 5, 2020
6ddef88
Revert "Extract handling of indentation in own class"
felixauringer Aug 5, 2020
a045a64
Clean up revert commit and rename OPEvaluator to OPPrinter
felixauringer Aug 5, 2020
621171d
Remove mysterious inheritance of OPUserInterface
felixauringer Aug 5, 2020
6ecdacf
Rename and Recategorize methods in OPCommentExtractor
felixauringer Aug 5, 2020
ae032e9
Fix small linting issues
T4rikA Aug 6, 2020
c0af976
Implement KeywordMessage and add tests
felixauringer Aug 6, 2020
77dae47
Format method declaration properly and add more tests with comments f…
felixauringer Aug 6, 2020
af825e3
Remove magic number in separatorAfterHeaderWith:and:
felixauringer Aug 6, 2020
07f4b33
Use whitespace strings consistently
felixauringer Aug 6, 2020
2ed3481
Fix newline method
felixauringer Aug 6, 2020
8ca15d0
Rename local variables
felixauringer Aug 7, 2020
23d4ff1
Completely revise all formatting tests
felixauringer Aug 7, 2020
80b05bf
Fix some linting issues, formatted OmegaPrint-Core
T4rikA Aug 7, 2020
776cad4
Format all tests with OmegaPrint
Paula-Kli Aug 7, 2020
b57231b
Add a first draft for class comments of the whole project
Paula-Kli Jul 30, 2020
e39db2c
Add two characters that were missing
Paula-Kli Aug 1, 2020
3bba2d4
Change some wording and add a class comment to TestUI
Paula-Kli Aug 2, 2020
6b4d426
Change small wording issues in the class comments
Paula-Kli Aug 2, 2020
d59a5d1
Clarify the class comment of OPUserInterface
Paula-Kli Aug 3, 2020
7e05c43
Adapt comments to new architecture and make small changes
felixauringer Aug 7, 2020
9e19803
Add some information about comments
Paula-Kli Aug 7, 2020
cb14df6
Capitalize one character in OPCommentExtractor class comment
Paula-Kli Aug 7, 2020
4844735
Format extension methods according to omegaPrint
Paula-Kli Aug 7, 2020
9292476
Add history and usage images to readme
PatriciaSowa Aug 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
dev: ![CI](https://github.com/hpi-swa-teaching/OhmPrettyPrint/workflows/CI/badge.svg?branch=dev)
master: ![CI](https://github.com/hpi-swa-teaching/OhmPrettyPrint/workflows/CI/badge.svg?branch=master)

OmegaPrint is a tool which prettifies your code in a consistent way. It uses [Ohm/S](https://github.com/hpi-swa/Ohm-S) as a parser.

## How to install
```smalltalk
Metacello new
baseline: 'OhmPrettyPrint';
baseline: 'OmegaPrint';
repository: 'github://HPI-SWA-Teaching/OhmPrettyPrint:dev/packages';
load
```

## Usage
After installing OmegaPrint you will find a button in all your code holders (for example the browser).
![Hovering over formatter selection](/screenshots/hover_formatting_selection.png)
![Formatter selection clicked](/screenshots/click_formatting_selection.png)

Selecting OmegaPrint will show you a prettified version of your code. Be aware that comments are not fully implemented yet.

For more information about the implementation visit our [wiki](https://github.com/hpi-swa-teaching/OhmPrettyPrint/wiki).

## History
- 2020: Tarik Alnawa, Felix Auringer, Paula Klinke, Patricia Sowa
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*OmegaPrint-Core
isModeStyleable
"determine whether the current mode can be styled"
^ self showingSource or: [ self showingPrettyPrint ] or: [ self isShowingOmegaPrint ]
^ self showingSource
or: [ self showingPrettyPrint ]
or: [ self isShowingOmegaPrint ]
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
omegaPrintString
"returns a string whether omegaPrint is displayed"
^ ((contentsSymbol = #omegaPrint)
ifTrue: ['<yes>']
ifFalse: ['<no>']) , 'omegaPrint'
ifTrue: [ '<yes>' ]
ifFalse: [ '<no>' ]) , 'omegaPrint'
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ sourceStringPrettifiedAndDiffed
selector := self selectedMessageName.
(class isNil or: [ selector isNil ]) ifTrue: [ ^ 'missing' ].
sourceString := class
ultimateSourceCodeAt: selector
ifAbsent: [ ^ 'error' ].
ultimateSourceCodeAt: selector
ifAbsent: [ ^ 'error' ].
self
validateMessageSource: sourceString
forSelector: selector
inClass: class.
(#(#prettyPrint #prettyDiffs) includes: contentsSymbol)
ifTrue: [ prettifierClass := class prettyPrinterClass ].
(#omegaPrint = contentsSymbol)
ifTrue: [ prettifierClass := OPPrinter ].
prettifierClass ifNotNil:
[ sourceString := prettifierClass
format: sourceString
in: class
notifying: nil ].
self showingAnyKindOfDiffs
ifTrue: [ sourceString := self diffFromPriorSourceFor: sourceString ].
(#( #prettyPrint #prettyDiffs ) includes: contentsSymbol) ifTrue: [ prettifierClass := class prettyPrinterClass ].
(#omegaPrint = contentsSymbol) ifTrue: [ prettifierClass := OPPrinter ].
prettifierClass ifNotNil: [ sourceString := prettifierClass
format: sourceString
in: class
notifying: nil ].
self showingAnyKindOfDiffs ifTrue: [ sourceString := self diffFromPriorSourceFor: sourceString ].
^ sourceString
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"class" : {
},
"instance" : {
"isModeStyleable" : "PK 6/1/2020 18:27",
"isShowingOmegaPrint" : "fau 8/4/2020 10:22",
"omegaPrintString" : "fau 8/4/2020 10:22",
"sourceStringPrettifiedAndDiffed" : "PK 6/3/2020 13:21",
"toggleOmegaPrint" : "PS 8/4/2020 07:04" } }
"isModeStyleable" : "fau 8/5/2020 19:51",
"isShowingOmegaPrint" : "fau 8/5/2020 19:51",
"omegaPrintString" : "PK 8/7/2020 17:49",
"sourceStringPrettifiedAndDiffed" : "PK 8/7/2020 17:49",
"toggleOmegaPrint" : "fau 8/5/2020 19:51" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
An OPCommentExtractor can extract comments from a given node. Therefore it directly accesses the interval stream which is a hack but it is currently not possible any other way. The following methods are the most important:
commentNodesAfterMethod: expects a MethodDeclarationNode and returns the comments after the method. This is a special case as nodes only offer the method skippedSpacesNodes which returns the spaces nodes before the node.
commentNodesBefore: uses the method skippedSpacesNodes of OhmNode to return the comment nodes before this node.


commentMap
- A Bag of Integers
- It stores the start of the intervals for which the OPCommentExtractor already extracted a valid comment.
- Using this, the same comment cannot be extracted twice.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extraction
collectCommentNodes: aNode

| spaceNodes |
spaceNodes := aNode firstChild children.
^ spaceNodes select: [ :each | each firstChild ruleName = #comment ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
after method
commentNodesAfterMethod: aNode

^ (self commentNodesAtEndOfSourceMap: aNode) , (self commentNodesAfterSourceMap: aNode)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
comments
commentAfterSourceMap: aNode
after method
commentNodesAfterSourceMap: aNode

| interval |
interval := aNode sourceMap size + 1 to: aNode unformattedSourceCode size.
^ self
extractCommentFrom: interval
extractCommentNodesFrom: interval
with: aNode
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
after method
commentNodesAtEndOfSourceMap: aNode

| reversedSourceMap interval |
reversedSourceMap := aNode sourceMap reversed.
interval := self findCommentInterval: reversedSourceMap.
^ self
extractCommentNodesFrom: interval
with: aNode
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
before node
commentNodesBefore: aNode

| commentNodes |
(self commentMap includes: aNode interval start) ifTrue: [ ^ {} ].
commentNodes := self collectCommentNodes: aNode skippedSpacesNodes.
commentNodes ifNotEmpty: [ self commentMap add: aNode interval start ].
^ commentNodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extraction
extractCommentNodesFrom: anInterval with: aNode

| spacesNode |
spacesNode := (OhmExplicitSendsSmalltalk
match: (self
extractWhitespaceFrom: anInterval
with: aNode)
startingFrom: #spaces) cst.
^ self collectCommentNodes: spacesNode
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extraction
extractWhitespaceFrom: anInterval with: aNode

^ aNode unformattedSourceCode
copyFrom: anInterval start
to: anInterval stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
after method
findCommentInterval: aReversedSourceMap

| reversedIntervalStart intervalStart |
reversedIntervalStart := (aReversedSourceMap findFirst: [ :each | each size > 1 ]) - 1.
intervalStart := (aReversedSourceMap size - reversedIntervalStart) + 1.
^ intervalStart to: aReversedSourceMap size
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
foundCommentBefore: aNode

^ self commentMap includes: aNode interval start
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
initialize-release
initialize

super initialize.
self commentMap: Bag new
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"class" : {
},
"instance" : {
"collectCommentNodes:" : "fau 8/5/2020 22:13",
"commentMap" : "fau 8/5/2020 14:05",
"commentMap:" : "fau 8/5/2020 14:05",
"commentNodesAfterMethod:" : "fau 8/5/2020 22:16",
"commentNodesAfterSourceMap:" : "fau 8/5/2020 22:15",
"commentNodesAtEndOfSourceMap:" : "TA 8/7/2020 15:07",
"commentNodesBefore:" : "fau 8/5/2020 22:14",
"extractCommentNodesFrom:with:" : "fau 8/5/2020 22:13",
"extractWhitespaceFrom:with:" : "fau 8/5/2020 14:49",
"findCommentInterval:" : "TA 8/7/2020 15:11",
"foundCommentBefore:" : "fau 8/6/2020 10:45",
"initialize" : "fau 8/5/2020 14:06" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "OmegaPrint-Core",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "PK 8/7/2020 16:53",
"instvars" : [
"commentMap" ],
"name" : "OPCommentExtractor",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
1 change: 1 addition & 0 deletions packages/OmegaPrint-Core.package/OPPrinter.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The OPPrinter offers an interface for the codeHolder with format:in:notifying. It then calls the method evaluate:startingFrom: which creates an OhmMatchResult with the OhmExplicitSendsSmalltalk grammar. The CST of this match result then gets evaluated by OPSourceRewriter in order to prettify the code.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ evaluate: aString startingFrom: aSymbol
matchResult := OhmExplicitSendsSmalltalk
match: aString
startingFrom: aSymbol.
evaluator := OhmExplicitSendsSmalltalk synthesizedAttribute: OPPrinter new.
evaluator := OhmExplicitSendsSmalltalk synthesizedAttribute: OPSourceRewriter new.
^ evaluator value: matchResult cst

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
{
"class" : {
"evaluate:startingFrom:" : "fau 8/5/2020 10:29",
"format:in:notifying:" : "TA 7/30/2020 18:07" },
"evaluate:startingFrom:" : "fau 8/5/2020 13:34",
"format:in:notifying:" : "TA 8/7/2020 15:48" },
"instance" : {
"BinaryMessageSend:with:and:" : "TA 8/4/2020 13:12",
"BlockLiteralNormal:with:and:and:and:" : "fau 8/5/2020 09:40",
"ByteArrayLiteral:with:and:and:" : "fau 8/5/2020 09:49",
"CascadedMessages:with:and:and:" : "fau 8/4/2020 11:56",
"ExecutableCode:with:and:and:" : "TA 8/4/2020 13:11",
"ExpressionBinaryCascade:with:and:" : "TA 7/29/2020 15:00",
"ExpressionOperandCascade:with:and:" : "TA 7/29/2020 15:00",
"ExpressionUnaryCascade:with:and:" : "TA 7/29/2020 15:00",
"FinalStatement:with:and:and:" : "TA 8/4/2020 13:13",
"KeywordMessageSend:with:and:" : "fau 8/4/2020 21:26",
"LiteralArrayLiteral:with:and:and:" : "PK 8/2/2020 19:49",
"LiteralArrayLiteralInLiteralArray:with:and:and:and:" : "PK 8/2/2020 19:49",
"MethodDeclaration:with:and:and:" : "fau 8/5/2020 09:13",
"MoreExecutableCode:with:and:" : "TA 8/4/2020 13:32",
"NestedExpression:with:and:and:" : "PS 7/30/2020 15:30",
"ObjectArrayLiteral:with:and:and:" : "fau 8/5/2020 08:24",
"ObjectArrayLiteralElementNormal:with:and:" : "PS 7/30/2020 15:31",
"Pragma:with:and:and:" : "PS 7/30/2020 15:31",
"PragmaValuesKeyword:with:" : "TA 8/4/2020 13:11",
"Pragmas:with:" : "TA 8/4/2020 13:12",
"Statements:with:and:" : "fau 8/4/2020 13:03",
"cascadeWith:and:" : "TA 8/4/2020 14:14",
"commentAfterSourceMap:" : "PS 8/4/2020 06:24",
"commentAtEndOfSourceMap:" : "fau 8/1/2020 10:08",
"commentMap" : "fau 8/1/2020 10:09",
"commentMap:" : "fau 8/1/2020 10:09",
"decreaseIndentation" : "fau 5/26/2020 09:46",
"defaultExpression:" : "fau 8/4/2020 22:48",
"extractCommentFrom:with:" : "fau 8/5/2020 10:30",
"include:between:and:" : "fau 8/5/2020 08:26",
"increaseIndentation" : "fau 5/26/2020 09:46",
"indentation" : "fau 5/26/2020 10:39",
"indentation:" : "fau 5/26/2020 10:39",
"initialize" : "fau 7/31/2020 16:50",
"join:separatedBy:" : "fau 8/4/2020 22:11",
"lastComment:" : "fau 8/5/2020 10:03",
"literalArrayWith:" : "fau 8/5/2020 09:49",
"newline" : "fau 8/5/2020 10:20",
"spaceInBlockWith:and:and:" : "fau 8/5/2020 07:36",
"spaces:with:" : "fau 8/5/2020 09:52",
"value:" : "fau 8/5/2020 11:06",
"valueWithComment:with:" : "fau 8/5/2020 10:36" } }
} }
Loading