parsers/smalltalk/PPSmalltalkParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 03 Nov 2014 11:30:59 +0000
changeset 407 a0e6299c7337
parent 390 17ba167b8ee1
permissions -rw-r--r--
Removed unused / obsolete methods from PPToken * remove PPToken class>>on:start:stop * remove PPToken>>initializeOn:start:stop
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
385
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser/parsers/smalltalk' }"
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
PPSmalltalkGrammar subclass:#PPSmalltalkParser
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
	instanceVariableNames:''
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
	classVariableNames:''
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
	poolDictionaries:''
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
	category:'PetitSmalltalk-Core'
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
PPSmalltalkParser comment:'Enhances the Smalltalk grammar with production actions to build parse-tree nodes of the refactoring browser.'
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
390
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
    13
385
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
!PPSmalltalkParser methodsFor:'accessing'!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
startExpression
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
	"Make the sequence node has a method node as its parent and that the source is set."
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
	^ ([ :stream | stream collection ] asParser and , super startExpression) map: [ :source :node | 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
		(RBMethodNode selector: #doIt body: node)
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
			source: source.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
		(node statements size = 1 and: [ node temporaries isEmpty ])
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
			ifTrue: [ node statements first ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
			ifFalse: [ node ] ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
startMethod
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
	"Make sure the method node has the source code properly set."
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
	
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
	^ ([ :stream | stream collection ] asParser and , super startMethod)
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
		map: [ :source :node | node source: source ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
! !
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
!PPSmalltalkParser methodsFor:'grammar'!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
array
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
	^ super array map: [ :openNode :statementNodes :closeNode |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
		(self buildArray: statementNodes)
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
			left: openNode start;
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
			right: closeNode start;
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
			yourself ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
expression
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
	^ super expression map: [ :variableNodes :expressionNodes | self build: expressionNodes assignment: variableNodes ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
method
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
	^ super method map: [ :methodNode :bodyNode | 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
		methodNode pragmas: bodyNode first.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
		methodNode body: bodyNode second.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
		self buildMethod: methodNode ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
methodDeclaration
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
	^ super methodDeclaration ==> [ :nodes |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
		RBMethodNode 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
			selectorParts: nodes first
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
			arguments: nodes second ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
methodSequence
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
	^ super methodSequence map: [ :periodNodes1 :pragmaNodes1 :periodNodes2 :tempNodes :periodNodes3 :pragmaNodes2 :periodNodes4 :statementNodes |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
		Array
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
			with: pragmaNodes1 , pragmaNodes2
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
			with: (self build: tempNodes sequence: periodNodes1 , periodNodes2 , periodNodes3 , periodNodes4 , statementNodes) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
parens
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
	^ super parens map: [ :openToken :expressionNode :closeToken | expressionNode addParenthesis: (openToken start to: closeToken start) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
pragma
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
	^ super pragma ==> [ :nodes | 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
		(RBPragmaNode selectorParts: nodes second first arguments: nodes second second)
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
			addComments: nodes first comments;
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
			addComments: nodes last comments;
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
			left: nodes first start;
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
			right: nodes last start;
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
			yourself ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
return
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
	^ super return map: [ :token :expressionNode | RBReturnNode return: token start value: expressionNode ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
sequence
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
	^ super sequence map: [ :tempNodes :periodNodes :statementNodes | self build: tempNodes sequence: periodNodes , statementNodes ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
variable
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
	^ super variable ==> [ :token | RBVariableNode identifierToken: token ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    93
! !
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
!PPSmalltalkParser methodsFor:'grammar-blocks'!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97
block
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    98
	^ super block map: [ :leftToken :blockNode :rightToken | blockNode left: leftToken start; right: rightToken start ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   100
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   101
blockArgument
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   102
	^ super blockArgument ==> #second
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   103
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   104
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   105
blockBody
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   106
	^ super blockBody
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   107
		==> [ :nodes | 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
			| result |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
			result := RBBlockNode arguments: nodes first first body: nodes last.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   110
			nodes first last ifNotNil: [ result bar: nodes first last start ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   111
			result ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
! !
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   113
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   114
!PPSmalltalkParser methodsFor:'grammar-literals'!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   115
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
arrayLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   117
	^ super arrayLiteral ==> [ :nodes | RBLiteralArrayNode startPosition: nodes first start contents: nodes second stopPosition: nodes last start isByteArray: false ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   118
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   119
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   120
arrayLiteralArray
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121
	^ super arrayLiteralArray ==> [ :nodes | RBLiteralArrayNode startPosition: nodes first start contents: nodes second stopPosition: nodes last start isByteArray: false ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   122
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   123
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   124
byteLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   125
	^ super byteLiteral ==> [ :nodes | RBLiteralArrayNode startPosition: nodes first start contents: nodes second stopPosition: nodes last start isByteArray: true ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   126
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   127
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   128
byteLiteralArray
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
	^ super byteLiteralArray ==> [ :nodes | RBLiteralArrayNode startPosition: nodes first start contents: nodes second stopPosition: nodes last start isByteArray: true ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   130
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
charLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
	^ super charLiteral ==> [ :token | RBLiteralValueNode literalToken: ((RBLiteralToken value: token inputValue second start: token start stop: token stop) comments: token comments; yourself) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   134
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   135
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   136
falseLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   137
	^ super falseLiteral ==> [ :token | RBLiteralValueNode literalToken: ((RBLiteralToken value: false start: token start stop: token stop) comments: token comments; yourself) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   138
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   139
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   140
nilLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   141
	^ super nilLiteral ==> [ :token | RBLiteralValueNode literalToken: ((RBLiteralToken value: nil start: token start stop: token stop) comments: token comments; yourself) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   142
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   143
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   144
numberLiteral
386
a409905f7f2d Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 385
diff changeset
   145
    ((Smalltalk respondsTo: #isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ 
a409905f7f2d Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 385
diff changeset
   146
        ^ super numberLiteral ==> [ :token | RBLiteralValueNode literalToken: ((RBNumberLiteralToken value: (Number readSmalltalkSyntaxFrom: token inputValue) start: token start stop: token stop source: token inputValue) comments: token comments; yourself) ]
a409905f7f2d Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 385
diff changeset
   147
    ] ifFalse:[ 
a409905f7f2d Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 385
diff changeset
   148
        ^ super numberLiteral ==> [ :token | RBLiteralValueNode literalToken: ((RBNumberLiteralToken value: (Number readFrom: token inputValue) start: token start stop: token stop source: token inputValue) comments: token comments; yourself) ]
a409905f7f2d Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 385
diff changeset
   149
    ]
a409905f7f2d Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 385
diff changeset
   150
a409905f7f2d Smalltalk parser almost fixed (except few pragma-related tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 385
diff changeset
   151
    "Modified: / 07-10-2014 / 23:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
385
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   152
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   153
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   154
stringLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   155
	^ super stringLiteral ==> [ :token | RBLiteralValueNode literalToken: ((RBLiteralToken value: (self buildString: token inputValue) start: token start stop: token stop) comments: token comments; yourself) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   156
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   157
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   158
symbolLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   159
	^ super symbolLiteral ==> [ :tokens | RBLiteralValueNode literalToken: ((RBLiteralToken value: (self buildString: tokens last inputValue) asSymbol start: tokens first start stop: tokens last stop) comments: tokens last comments; yourself) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   160
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   161
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   162
symbolLiteralArray
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   163
	^ super symbolLiteralArray ==> [ :token | RBLiteralValueNode literalToken: ((RBLiteralToken value: (self buildString: token inputValue) asSymbol start: token start stop: token stop) comments: token comments; yourself) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   164
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   165
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   166
trueLiteral
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   167
	^ super trueLiteral ==> [ :token | RBLiteralValueNode literalToken: ((RBLiteralToken value: true start: token start stop: token stop) comments: token comments; yourself) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   168
! !
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   169
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   170
!PPSmalltalkParser methodsFor:'grammar-messages'!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   171
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   172
binaryExpression
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   173
	^ super binaryExpression map: [ :receiverNode :messageNodes | self build: receiverNode messages: messageNodes ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   174
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   175
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   176
cascadeExpression
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   177
	^ super cascadeExpression map: [ :receiverNode :messageNodes | self build: receiverNode cascade: messageNodes ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   178
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   179
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   180
keywordExpression
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   181
	^ super keywordExpression map: [ :receiveNode :messageNode | self build: receiveNode messages: (Array with: messageNode) ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   182
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   183
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   184
unaryExpression
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   185
	^ super unaryExpression map: [ :receiverNode :messageNodes | self build: receiverNode messages: messageNodes ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   186
! !
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   187
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   188
!PPSmalltalkParser methodsFor:'private'!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   189
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   190
addStatements: aCollection into: aNode
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   191
	aCollection isNil 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   192
		ifTrue: [ ^ aNode ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   193
	aCollection do: [ :each |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   194
		each class == PPSmalltalkToken
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   195
			ifFalse: [ aNode addNode:  each ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   196
			ifTrue: [
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   197
				aNode statements isEmpty
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   198
					ifTrue: [ aNode addComments: each comments ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   199
					ifFalse: [ aNode statements last addComments: each comments ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   200
				aNode periods: (aNode periods asOrderedCollection
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   201
					addLast: each start;
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   202
					yourself) ] ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   203
	^ aNode
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   204
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   205
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   206
build: aNode assignment: anArray
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   207
	^ anArray isEmpty
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   208
		ifTrue: [ aNode ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   209
		ifFalse: [
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   210
			anArray reverse 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   211
				inject: aNode
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   212
				into: [ :result :each |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   213
					RBAssignmentNode 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   214
						variable: each first
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   215
						value: result
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   216
						position: each second start ] ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   217
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   218
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   219
build: aNode cascade: anArray 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   220
	| messages semicolons |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   221
	^ (anArray isNil or: [ anArray isEmpty ]) 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   222
		ifTrue: [ aNode ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   223
		ifFalse: [
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   224
			messages := OrderedCollection new: anArray size + 1.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   225
			messages addLast: aNode.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   226
			semicolons := OrderedCollection new.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   227
			anArray do: [ :each | 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   228
				messages addLast: (self 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   229
					build: aNode receiver
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   230
					messages: (Array with: each second)).
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   231
				semicolons addLast: each first start ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   232
			RBCascadeNode messages: messages semicolons: semicolons ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   233
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   234
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   235
build: aNode messages: anArray 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   236
	^ (anArray isNil or: [ anArray isEmpty ]) 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   237
		ifTrue: [ aNode ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   238
		ifFalse: [
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   239
			anArray 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   240
				inject: aNode
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   241
				into: [ :rec :msg | 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   242
					msg isNil 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   243
						ifTrue: [ rec ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   244
						ifFalse: [
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   245
							RBMessageNode 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   246
								receiver: rec
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   247
								selectorParts: msg first
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   248
								arguments: msg second ] ] ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   249
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   250
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   251
build: aTempCollection sequence: aStatementCollection
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   252
	| result |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   253
	result := self
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   254
		addStatements: aStatementCollection
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   255
		into: RBSequenceNode new.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   256
	aTempCollection isEmpty ifFalse: [
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   257
		result
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   258
			leftBar: aTempCollection first start
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   259
			temporaries: aTempCollection second
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   260
			rightBar: aTempCollection last start ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   261
	^ result
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   262
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   263
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   264
buildArray: aStatementCollection
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   265
	^ self addStatements: aStatementCollection into: RBArrayNode new
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   266
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   267
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   268
buildMethod: aMethodNode
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   269
	aMethodNode selectorParts 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   270
		do: [ :each | aMethodNode addComments: each comments ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   271
	aMethodNode arguments
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   272
		do: [ :each | aMethodNode addComments: each token comments ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   273
	aMethodNode pragmas do: [ :pragma |
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   274
		aMethodNode addComments: pragma comments.
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   275
		pragma selectorParts 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   276
			do: [ :each | aMethodNode addComments: each comments ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   277
		pragma arguments do: [ :each | 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   278
			each isLiteralArray
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   279
				ifFalse: [ aMethodNode addComments: each token comments ] ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   280
		pragma comments: nil ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   281
	^ aMethodNode
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   282
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   283
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   284
buildString: aString 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   285
	(aString isEmpty or: [ aString first ~= $' or: [ aString last ~= $' ] ])
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   286
		ifTrue: [ ^ aString ].
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   287
	^ (aString 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   288
		copyFrom: 2
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   289
		to: aString size - 1) 
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   290
		copyReplaceAll: ''''''
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   291
		with: ''''
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   292
! !
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   293
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   294
!PPSmalltalkParser methodsFor:'token'!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   295
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   296
binaryToken
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   297
	^ super binaryToken ==> [ :token | (RBBinarySelectorToken value: token inputValue start: token start) comments: token comments; yourself ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   298
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   299
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   300
identifierToken
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   301
	^ super identifierToken ==> [ :token | (RBIdentifierToken value: token inputValue start: token start) comments: token comments; yourself ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   302
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   303
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   304
keywordToken
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   305
	^ super keywordToken ==> [ :token | (RBKeywordToken value: token inputValue start: token start) comments: token comments; yourself ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   306
!
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   307
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   308
unaryToken
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   309
	^ super unaryToken ==> [ :token | (RBIdentifierToken value: token inputValue start: token start) comments: token comments; yourself ]
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   310
! !
44a36ed4e484 Commited a Smalltalk parser (MC package PetitSmalltalk)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   311
390
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
   312
!PPSmalltalkParser class methodsFor:'documentation'!
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
   313
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
   314
version_HG
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
   315
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
   316
    ^ '$Changeset: <not expanded> $'
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
   317
! !
17ba167b8ee1 Updated to PetitSmalltalk-JanKurs.75
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 386
diff changeset
   318