[squeak-dev] The Trunk: Compiler-mt.439.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Jun 15 17:14:23 UTC 2020


Marcel Taeumel uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-mt.439.mcz

==================== Summary ====================

Name: Compiler-mt.439
Author: mt
Time: 15 June 2020, 7:14:22.86019 pm
UUID: fe605039-7601-ad4d-9a16-4d86b168d33e
Ancestors: Compiler-mt.438

Like in ShoutCore-mt.82, improve readability of code for dispatching to custom pragma parsers.

=============== Diff against Compiler-mt.438 ===============

Item was changed:
  ----- Method: Parser>>pragmaStatement (in category 'pragmas') -----
  pragmaStatement
+ 	"Parse a pragma statement. The leading '<' has already been consumed. The 'here' token is the first one in the pragma. Use that token to dispatch to a custom pragma-parsing method if one can be found with a selector that matches it.
- 	"Read a single pragma statement. Dispatch to the first available pragma parser using the current token as a simple getter to be called on self. If no pragma parser can be found, parse it as usual in the keywords form.
  	
  	Note that custom pragma parsers need to fulfill two requirements:
+ 		- method selector must match the current token as simple getter,
- 		(1) method selector must match the current token as simple getter,
  				e.g., <apicall: ...> matches #apicall or <primitive: ...> matches #primitive
+ 		- method must have pragma <pragmaParser> to be called."
- 		(2) method must declare <pragmaParser> to be called.
- 	This is for the protection of the parser's (message) namespace."
  	
+ 	"0) Early exit"
- 	| parserSelector |
  	(hereType = #keyword or: [ hereType = #word or: [ hereType = #binary ] ])
  		ifFalse: [  ^ self expected: 'pragma declaration' ].
  
+ 	"1) Do not consider one-word pragmas such as <primitive> and <foobar>. Only keyword pragmas."
+ 	here last == $: ifTrue: [
+ 		"2) Avoid interning new symbols for made-up pragmas such as #my for <my: 1 pragma: 2>."
+ 		(Symbol lookup: here allButLast) ifNotNil: [:parserSelector |
+ 			Parser methodDict at: parserSelector ifPresent: [:parserMethod |
+ 				"3) Only call methods that claim to be a custom pragma parser via <pragmaParser>."
+ 				(parserMethod hasPragma: #pragmaParser)
+ 					ifTrue: [^ self executeMethod: parserMethod]]]].
- 	(here last == $:
- 		and: [(parserSelector := Symbol lookup: here allButLast) notNil])
- 			ifFalse: ["Quick exit to not break one-word pragmas such as <primitive> and <foobar>; also avoid interning new symbols for made-up pragmas such as for <my: 1 new: 2 pragma: 3> not interning #my."
- 				^ self pragmaStatementKeywords].
  
+ 	"X) No custom pragma parser found. Use the default one."
- 	Parser methodDict
- 		at: parserSelector
- 		ifPresent: [:parserMethod |
- 			(parserMethod pragmas
- 				anySatisfy: [:pragma | pragma keyword == #pragmaParser])
- 					ifTrue: [^ self executeMethod: parserMethod]].
- 
  	^ self pragmaStatementKeywords!



More information about the Squeak-dev mailing list