Matthew Fulmer uploaded a new version of Compiler to project The Inbox:
http://source.squeak.org/inbox/Compiler-mtf.184.mcz ==================== Summary ==================== Name: Compiler-mtf.184 Author: mtf Time: 6 January 2011, 2:14:13.972 pm UUID: 59cf24c3-ab24-450b-b00a-152363bb2391 Ancestors: Compiler-mtf.136, Compiler-nice.183 support methods with positional arguments. Needed by OpenGL in Croquet =============== Diff against Compiler-nice.183 =============== Item was added: + ----- Method: Parser>>matrixExpression: (in category 'expression types') ----- + matrixExpression: primary + "primaryExpression [ ... ] -> index node" + | start rcvrNode selector args msgStart msgStop | + self primaryExpression ifFalse:[^false]. + (hereType == #leftBracket) ifFalse:[^primary]. + start := self startOfNextToken. + rcvrNode := parseNode. + selector := WriteStream on: (String new: 32). + args := OrderedCollection new. + [ self advance. + parseNode := nil. + self primaryExpression ifFalse:[^self expected:'expression']. + args size = 0 + ifTrue:[selector nextPutAll:'matrixAt:'] + ifFalse:[selector nextPutAll:'at:']. + args add: parseNode. + here == #, ] whileTrue. + (self match: #rightBracket) ifFalse:[^self expected:']']. + + msgStart := start. + msgStop := self endOfLastToken. + (primary not and:[hereType == #leftArrow]) ifTrue:[ + selector nextPutAll:'put:'. + start := self startOfNextToken. + self advance. + self expression ifFalse: [^self expected: 'Expression']. + (parseNode isKindOf: BlockNode) ifFalse:[ + parseNode := BlockNode new + arguments: #() + statements: (OrderedCollection with: parseNode) + returns: false + from: encoder. + ]. + args add: parseNode]. + parseNode := MessageNode new + receiver: rcvrNode + selector: selector contents asSymbol + arguments: args + precedence: 1 + from: encoder + sourceRange: (msgStart to: msgStop). + primary ifTrue:[^true]. + (self messagePart: 3 repeat: true) + ifTrue: [hereType == #semicolon ifTrue: [self cascade]]. + ^ true! Item was changed: ----- Method: Parser>>messagePart:repeat: (in category 'expression types') ----- messagePart: level repeat: repeat + | start receiver selector args precedence words keywordStart type | - | start receiver selector args precedence words keywordStart | [receiver := parseNode. (hereType == #keyword and: [level >= 3]) ifTrue: [start := self startOfNextToken. selector := WriteStream on: (String new: 32). args := OrderedCollection new. words := OrderedCollection new. [hereType == #keyword] whileTrue: [keywordStart := self startOfNextToken + requestorOffset. selector nextPutAll: self advance. words addLast: (keywordStart to: self endOfLastToken + requestorOffset). + (self matrixExpression: true) ifFalse: [^self expected: 'Argument']. - self primaryExpression ifFalse: [^self expected: 'Argument']. self messagePart: 2 repeat: true. args addLast: parseNode]. (Symbol hasInterned: selector contents ifTrue: [ :sym | selector := sym]) ifFalse: [ selector := self correctSelector: selector contents wordIntervals: words exprInterval: (start to: self endOfLastToken) ifAbort: [ ^ self fail ] ]. precedence := 3] ifFalse: [((hereType == #binary or: [hereType == #verticalBar]) and: [level >= 2]) ifTrue: [start := self startOfNextToken. + selector := self advance asSymbol. + (self matrixExpression: true) ifFalse: [^self expected: 'Argument']. - selector := self advance asOctetString asSymbol. - self primaryExpression ifFalse: [^self expected: 'Argument']. self messagePart: 1 repeat: true. args := Array with: parseNode. precedence := 2] + ifFalse: [(hereType == #word or:[hereType == #positionalMessage]) - ifFalse: [hereType == #word ifTrue: [start := self startOfNextToken. + type := hereType. selector := self advance. + type == #word ifTrue:[ + args := #(). + ] ifFalse:[ + args := self positionalArgs. + selector := selector,'/', args size printString. + ]. - args := #(). words := OrderedCollection with: (start + requestorOffset to: self endOfLastToken + requestorOffset). (Symbol hasInterned: selector ifTrue: [ :sym | selector := sym]) ifFalse: [ selector := self correctSelector: selector wordIntervals: words exprInterval: (start to: self endOfLastToken) ifAbort: [ ^ self fail ] ]. precedence := 1] ifFalse: [^args notNil]]]. parseNode := MessageNode new receiver: receiver selector: selector arguments: args precedence: precedence from: encoder sourceRange: (start to: self endOfLastToken). repeat] whileTrue: []. + ^true + ! - ^true! Item was added: + ----- Method: Parser>>positionalArgs (in category 'positional messages') ----- + positionalArgs + "Parse a series of positional arguments, separated by comma." + | args | + (hereType == #rightParenthesis) ifTrue:[self advance. ^#()]. + args := WriteStream on: (Array new: 3). + [ + self positionalArgsExpression ifFalse:[^self expected: 'argument']. + args nextPut: parseNode. + hereType == #rightParenthesis ifTrue:[self advance. ^args contents]. + here == #, ifFalse:[^self expected: 'comma']. + self advance. + ] repeat. + ! Item was added: + ----- Method: Parser>>positionalArgsExpression (in category 'positional messages') ----- + positionalArgsExpression + "Just like #expression just keep track of commas" + (hereType == #word and: [tokenType == #leftArrow]) + ifTrue: [^ self assignment: self variable]. + hereType == #leftBrace + ifTrue: [self braceExpression] + ifFalse: [self primaryExpression ifFalse: [^ false]]. + (here == #, or:[hereType == #rightParenthesis]) ifTrue:[^true]. + ^self positionalMessagePart: 3 repeat: true! Item was added: + ----- Method: Parser>>positionalMessagePart:repeat: (in category 'positional messages') ----- + positionalMessagePart: level repeat: repeat + "Just like #messagePart but keep track of comma" + | start receiver selector args precedence words keywordStart type | + [receiver := parseNode. + (hereType == #keyword and: [level >= 3]) + ifTrue: + [start := self startOfNextToken. + selector := WriteStream on: (String new: 32). + args := OrderedCollection new. + words := OrderedCollection new. + [hereType == #keyword] + whileTrue: + [keywordStart := self startOfNextToken + requestorOffset. + selector nextPutAll: self advance. + words addLast: (keywordStart to: self endOfLastToken + requestorOffset). + self primaryExpression ifFalse: [^self expected: 'Argument']. + self messagePart: 2 repeat: true. + args addLast: parseNode]. + (Symbol hasInterned: selector contents ifTrue: [ :sym | selector := sym]) + ifFalse: [ selector := self correctSelector: selector contents + wordIntervals: words + exprInterval: (start to: self endOfLastToken) + ifAbort: [ ^ self fail ] ]. + precedence := 3] + ifFalse: [((hereType == #binary or: [hereType == #verticalBar]) + and: [level >= 2 and:[here ~= #,]]) + ifTrue: + [start := self startOfNextToken. + selector := self advance asSymbol. + self primaryExpression ifFalse: [^self expected: 'Argument']. + self messagePart: 1 repeat: true. + args := Array with: parseNode. + precedence := 2] + ifFalse: [(hereType == #word or:[hereType == #positionalMessage]) + ifTrue: + [start := self startOfNextToken. + type := hereType. + selector := self advance. + type == #word ifTrue:[ + args := #(). + ] ifFalse:[ + args := self positionalArgs. + selector := selector,'/', args size printString. + ]. + words := OrderedCollection with: (start + requestorOffset to: self endOfLastToken + requestorOffset). + (Symbol hasInterned: selector ifTrue: [ :sym | selector := sym]) + ifFalse: [ selector := self correctSelector: selector + wordIntervals: words + exprInterval: (start to: self endOfLastToken) + ifAbort: [ ^ self fail ] ]. + precedence := 1] + ifFalse: [^args notNil]]]. + parseNode := MessageNode new + receiver: receiver + selector: selector + arguments: args + precedence: precedence + from: encoder + sourceRange: (start to: self endOfLastToken). + repeat] + whileTrue: []. + ^true! |
Free forum by Nabble | Edit this page |