The Trunk: ShoutCore-mt.82.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: ShoutCore-mt.82.mcz

commits-2
Marcel Taeumel uploaded a new version of ShoutCore to project The Trunk:
http://source.squeak.org/trunk/ShoutCore-mt.82.mcz

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

Name: ShoutCore-mt.82
Author: mt
Time: 15 June 2020, 7:12:43.61019 pm
UUID: 4354ca0d-a509-b247-8ee1-4a05fb6bc5b3
Ancestors: ShoutCore-mt.81

Improve readability of code for dispatching to custom pragma parsers.

=============== Diff against ShoutCore-mt.81 ===============

Item was added:
+ ----- Method: SHParserST80>>parsePragmaDefault (in category 'parse pragma') -----
+ parsePragmaDefault
+ "Parse unary, binary, and keyword pragmas."
+
+ self currentTokenType
+ caseOf: {
+ [ #name ] -> [
+ self scanPast: #pragmaUnary.
+ self failUnless: currentToken = '>'.
+ self scanPast: #primitiveOrExternalCallEnd ].
+ [ #binary ] -> [ self parsePragmaBinary ].
+ [ #keyword ] -> [ self parsePragmaKeyword ] }
+ otherwise: [ self fail ": 'Invalid External Function Calling convention'" ]. !

Item was changed:
  ----- Method: SHParserST80>>parsePragmaStatement (in category 'parse pragma') -----
  parsePragmaStatement
+ "Parse a pragma statement. The leading '<' has already been consumed. The currentToken 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.
-
- | parserSelector |
- (currentToken last == $:
- and: [(parserSelector := Symbol lookup: currentToken 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 parsePragmaStatementKeywords].
 
+ Note that custom pragma parsers need to fulfill two requirements:
+ - 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."
- SHParserST80 methodDict
- at: parserSelector
- ifPresent: [:parserMethod |
- (parserMethod pragmas
- anySatisfy: [:pragma | pragma keyword == #pragmaParser])
- ifTrue: [^ self executeMethod: parserMethod]].
 
+ "1) Do not consider one-word pragmas such as <primitive> and <foobar>. Only keyword pragmas."
+ currentToken last == $: ifTrue: [
+ "2) Avoid interning new symbols for made-up pragmas such as #my for <my: 1 pragma: 2>."
+ (Symbol lookup: currentToken allButLast) ifNotNil: [:parserSelector |
+ SHParserST80 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]]]].
+
+ "X) No custom pragma parser found. Use the default one."
+ ^ self parsePragmaDefault!
- ^ self parsePragmaStatementKeywords!

Item was removed:
- ----- Method: SHParserST80>>parsePragmaStatementKeywords (in category 'parse pragma') -----
- parsePragmaStatementKeywords
-
- self currentTokenType
- caseOf: {
- [ #name ] -> [
- self scanPast: #pragmaUnary.
- self failUnless: currentToken = '>'.
- self scanPast: #primitiveOrExternalCallEnd ].
- [ #binary ] -> [ self parsePragmaBinary ].
- [ #keyword ] -> [ self parsePragmaKeyword ] }
- otherwise: [ self fail ": 'Invalid External Function Calling convention'" ]. !