SystemOrganization addCategory: #PetitMSE! PPCompositeParser subclass: #PPMSEGrammar instanceVariableNames: 'elements element attributeValue attribute identifierName primitive reference id string number boolean attributeName integerReference nameReference' classVariableNames: '' poolDictionaries: '' category: 'PetitMSE'! !PPMSEGrammar commentStamp: '' prior: 0! This defines a parser for the MSE format. Instance Variables: elements element elementName elementId ! PPMSEGrammar subclass: #PPMSEArrayParser instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'PetitMSE'! !PPMSEArrayParser methodsFor: 'accessing' stamp: 'tg 7/27/2010 22:26'! attribute ^ super attribute ==> [:token | Array with: (token at: 2) with: (token at: 3) ]! ! !PPMSEArrayParser methodsFor: 'accessing' stamp: 'tg 7/28/2010 00:13'! attributeName ^ super attributeName ==> [:token | token value ]! ! !PPMSEArrayParser methodsFor: 'accessing' stamp: 'tg 7/27/2010 22:26'! attributeValue ^ super attributeValue! ! !PPMSEArrayParser methodsFor: 'values' stamp: 'tg 7/28/2010 00:20'! boolean ^ super boolean ==> [:token | token value = 'true' ifTrue: [true] ifFalse: [token value = 'false' ifTrue: [false] ifFalse: [nil]]] ! ! !PPMSEArrayParser methodsFor: 'accessing' stamp: 'tg 7/27/2010 22:26'! element ^ super element ==> [:token | Array with: (token at: 2) with: (token at: 3) with: (token at: 4) ]! ! !PPMSEArrayParser methodsFor: 'accessing' stamp: 'tg 7/27/2010 22:26'! elements ^ super elements ==> [:token | token second ]! ! !PPMSEArrayParser methodsFor: 'accessing' stamp: 'tg 7/28/2010 00:08'! id ^ super id ==> [:token | Array with: 'id' with: (token at: 3) value asNumber ]! ! !PPMSEArrayParser methodsFor: 'accessing' stamp: 'tg 7/28/2010 00:04'! identifierName ^ super identifierName ==> [:token | token value ]! ! !PPMSEArrayParser methodsFor: 'values' stamp: 'tg 7/28/2010 07:59'! integerReference ^ super integerReference ==> [:token | Array with: 'ref' with: token "(token at: 3) asNumber" ]! ! !PPMSEArrayParser methodsFor: 'values' stamp: 'tg 7/28/2010 07:57'! nameReference ^ super nameReference ==> [:token | Array with: 'ref' with: token ]! ! !PPMSEArrayParser methodsFor: 'values' stamp: 'tg 7/27/2010 22:27'! number ^ super number ==> [ :token | token value asNumber ]! ! !PPMSEArrayParser methodsFor: 'values' stamp: 'tg 7/27/2010 22:27'! primitive ^ super primitive! ! !PPMSEArrayParser methodsFor: 'values' stamp: 'tg 7/28/2010 01:00'! string ^ super string ==> [:token | token value ]! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/28/2010 00:13'! attribute ^ ($( asParser token , attributeName , attributeValue , $) asParser token) trim! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/28/2010 00:13'! attributeName ^ self identifierName! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/31/2010 00:39'! attributeValue ^ (primitive / reference / element) star! ! !PPMSEGrammar methodsFor: 'values' stamp: 'tg 7/27/2010 22:49'! boolean ^ ('true' asParser / 'false' asParser) token trim! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/28/2010 07:47'! element ^ ($( asParser token , identifierName , id optional , attribute star , $) asParser token) trim! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/27/2010 22:30'! elements ^ $( asParser trim , element trim star , $) asParser trim! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/28/2010 00:07'! id ^ ($( asParser trim , 'id:' asParser trim , #digit asParser star token trim , $) asParser) trim! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/28/2010 00:19'! identifierName ^ (#word asParser star flatten , ( $. asParser flatten , #word asParser star flatten ==> [:token | token first, token second] ) optional) token trim! ! !PPMSEGrammar methodsFor: 'values' stamp: 'tg 7/28/2010 07:51'! integerReference ^ ($( asParser trim , 'ref:' asParser trim , #digit asParser star flatten trim , $) asParser) token trim! ! !PPMSEGrammar methodsFor: 'values' stamp: 'tg 7/28/2010 07:59'! nameReference ^ ($( asParser trim , 'ref:' asParser trim , #word asParser star token , $) asParser trim) token! ! !PPMSEGrammar methodsFor: 'values' stamp: 'tg 7/27/2010 22:30'! number ^ ($- asParser optional , #digit asParser plus , ($. asParser , #digit asParser plus) optional) token trim! ! !PPMSEGrammar methodsFor: 'values' stamp: 'tg 7/27/2010 10:43'! primitive ^ string / number / boolean" , unlimited"! ! !PPMSEGrammar methodsFor: 'values' stamp: 'tg 7/28/2010 07:51'! reference ^ integerReference / nameReference! ! !PPMSEGrammar methodsFor: 'accessing' stamp: 'tg 7/25/2010 17:59'! start ^ elements end! ! !PPMSEGrammar methodsFor: 'values' stamp: 'tg 7/28/2010 01:00'! string ^ ( $' asParser , ( $' asParser negate ) star token , $' asParser ==> #second ) trim! ! PPCompositeParserTest subclass: #PPMSEArrayParserTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'PetitMSE'! !PPMSEArrayParserTest methodsFor: 'accessing' stamp: 'tg 7/27/2010 22:33'! parserClass ^ PPMSEArrayParser! ! !PPMSEArrayParserTest methodsFor: 'testing' stamp: 'tg 7/25/2010 20:10'! testEmpty self assert: '()' is: #(). self assert: '( )' is: #(). self assert: ' ( ) ' is: #()! ! !PPMSEArrayParserTest methodsFor: 'testing' stamp: 'tg 7/28/2010 00:04'! testOneElement self assert: '((X))' is: #(('X' nil #())). self assert: '((X.Y))' is: #(('X.Y' nil #())). ! ! !PPMSEArrayParserTest methodsFor: 'testing' stamp: 'tg 7/27/2010 21:18'! testOneElementWithBooleanAttribute self assert: '((X.Y (attribute true)))' is: #(('X.Y' nil #(('attribute' true))))! ! !PPMSEArrayParserTest methodsFor: 'testing' stamp: 'tg 7/27/2010 21:17'! testOneElementWithId self assert: '((FAMIX.Class (id: 1)))' is: #(('FAMIX.Class' #('id' 1) #())). self assert: '( ( FAMIX.Class (id: 1) ) )' is: #(('FAMIX.Class' #('id' 1) #())). self assert: '( ( FAMIX.Class (id: 1) ) )' is: #(('FAMIX.Class' #('id' 1) #())). self assert: '( (FAMIX.Class (id: 1) ) )' is: #(('FAMIX.Class' #('id' 1) #()))! ! !PPMSEArrayParserTest methodsFor: 'testing' stamp: 'tg 7/28/2010 07:46'! testOneElementWithMultipleSubElements self assert: '( (X (id: 1) (sub (Y (id: 11))(Z (id: 12))) ) )' is: #(#('X' #('id' 1) #(#('sub' #(#('Y' #('id' 11) #()) #('Z' #('id' 12) #())))))). self assert: '( (X (id: 1) (sub (Y (id: 11)) (Z (id: 12))) ) )' is: #(#('X' #('id' 1) #(#('sub' #(#('Y' #('id' 11) #()) #('Z' #('id' 12) #()))))))! ! !PPMSEArrayParserTest methodsFor: 'testing' stamp: 'tg 7/27/2010 21:01'! testOneElementWithNumericAttribute self assert: '((X.Y (attribute 2)))' is: #(('X.Y' nil #(('attribute' 2)))). self assert: '((X.Y (attribute 2.1)))' is: #(('X.Y' nil #(('attribute' 2.1)))). self assert: '((X.Y (attribute 1234.567)))' is: #(('X.Y' nil #(('attribute' 1234.567))))! ! !PPMSEArrayParserTest methodsFor: 'testing' stamp: 'tg 7/27/2010 21:21'! testOneElementWithStringAttribute self assert: '((FAMIX.Class (name ''Something'')))' is: #(('FAMIX.Class' nil #(('name' 'Something')))). self assert: '((FAMIX.Class (attribute ''as:.,>