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

Methods with comments in args can be written wrongly #50

Open
dionisiydk opened this issue Sep 20, 2018 · 6 comments
Open

Methods with comments in args can be written wrongly #50

dionisiydk opened this issue Sep 20, 2018 · 6 comments

Comments

@dionisiydk
Copy link

Following tests are failed:

testWriteMethodDefinitionWithStrangeComment
	| writer def stream |
	writer := TonelWriter new.
	stream := String new writeStream.
	def := MCMethodDefinition
		className: #Object
		classIsMeta: false
		selector: #a:b:
		category: 'accessing'
		timeStamp: nil
		source:
			'a: "b:" arg1 b: arg2
	^ 42'.
	writer writeMethodDefinition: def on: stream.
	self
		assert: stream contents
		equals:
			('
{ #category : #accessing }
Object >> a: "b:" arg1 b: arg2 [
	^ 42
]
' withLineEndings: OSPlatform current lineEnding)

Problem with algorithm which extracts method name line from sources:

TonelWritter>>selectorIsComplete: keywords in: aString
	| start |
	start := 1.
	keywords
		do: [ :each |
			| index |
			index := aString
				findString: each
				startingAt: start
				caseSensitive: true.
			index = 0
				ifTrue: [ ^ false ].
			start := index + each size ].
	^ true
@dionisiydk
Copy link
Author

Why not reusing RBParser for all this parsing? It could be like:

methodNode := RBParser new 
    initializeParserWith: source;
    parseMessagePattern.
methodNode source: source.
^methodNode selectorAndArgumentNames

@dionisiydk
Copy link
Author

The main method can be rewritten as:

TonelWriter>>splitMethodSource: aMethodDefinition into: aBlock
	
	| source methodNode declaration body |
	source := aMethodDefinition source.
	methodNode := RBParser new 
    initializeParserWith: source;
    parseMessagePattern.
	methodNode source: source.
	declaration := methodNode selectorAndArgumentNames.

	body := source allButFirst: methodNode bodyStart - 1.
	aBlock
		value: (declaration trimLeft withLineEndings: self newLine)
		value: (body withLineEndings: self newLine)

It requires fix in #selectorAndArgumentNames because it does not take into account comments before selector. And it requires #bodyStart:

RBMethodNode>>bodyStart
	^ self arguments
		ifEmpty: [self keywordsPositions first + self selector size]
		ifNotEmpty: [self arguments last stop + 1]

@estebanlm
Copy link
Contributor

That was like that in the first version.
But... so far that's not possible because Tonel is designed to be ported to different dialects and some of them do not have RBParser available (we could put that into a dialect dependent package, but well...).

@dionisiydk
Copy link
Author

dionisiydk commented Sep 20, 2018 via email

@estebanlm
Copy link
Contributor

at least Gemstone and Squeak have MC.
(and I was targeting Gemstone compatibility)

@dalehenrich
Copy link

We've got RBParser as well and I have just about finished creating an RBParser-based Tonel reader for Rowan ... I can share the RBParser implementation (NewTonelParser. RBTonelParser, and RBTonelScanner) if there's interest...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants