SystemOrganization addCategory: #PetitCSV! PPCompositeParser subclass: #PPCommaSeparatedParser instanceVariableNames: 'row cell rows endOfLine whitespace nonComma' classVariableNames: '' poolDictionaries: '' category: 'PetitCSV'! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'tg 7/17/2010 21:15'! cell ^ whitespace star , nonComma star flatten , whitespace star ==> [ :nodes | nodes second value ]! ! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'lr 6/11/2010 15:39'! endOfLine ^ #newline asParser token "(#cr asParser , #lf asParser optional) / #lf asParser"! ! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'tg 7/17/2010 21:14'! nonComma ^ PPPredicateObjectParser anyExceptAnyOf: {Character space . Character tab . Character cr . Character lf . $, }! ! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'tg 7/17/2010 16:40'! number ^ ($- asParser optional , #digit asParser plus , ($. asParser , #digit asParser plus) optional) token ==> [ :nodes | nodes first value asNumber ]! ! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'lr 6/11/2010 15:38'! row ^ (cell delimitedBy: $, asParser token) ==> [ :nodes | nodes reject: [ :each | each class = PPToken ] ]! ! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'lr 6/11/2010 15:38'! rows ^ (row delimitedBy: endOfLine) ==> [ :nodes | nodes reject: [ :each | each class = PPToken ] ]! ! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'tg 6/11/2010 15:05'! start ^ rows end! ! !PPCommaSeparatedParser methodsFor: 'as yet unclassified' stamp: 'lr 6/12/2010 09:20'! whitespace ^ PPPredicateObjectParser anyOf: (Array with: Character space with: Character tab)! ! PPCompositeParserTest subclass: #PPCommaSeparatedParserTest instanceVariableNames: 'row cell rows' classVariableNames: '' poolDictionaries: '' category: 'PetitCSV'! !PPCommaSeparatedParserTest methodsFor: 'as yet unclassified' stamp: 'tg 6/11/2010 14:55'! parserClass ^ PPCommaSeparatedParser! ! !PPCommaSeparatedParserTest methodsFor: 'as yet unclassified' stamp: 'tg 7/17/2010 21:15'! testCell self assert: '123' is: #(('123')). self assert: 'abc' is: #(('abc')). self assert: 'ASDASD123' is: #(('ASDASD123')). ! ! !PPCommaSeparatedParserTest methodsFor: 'as yet unclassified' stamp: 'tg 7/17/2010 21:12'! testSingleLine self assert: '1 , 2, 3' is: #(('1' '2' '3')). self assert: 'a1 , 2, 3' is: #(('a1' '2' '3')). self assert: 'a , 2, 3' is: #(('a' '2' '3')). ! ! !PPCommaSeparatedParserTest methodsFor: 'as yet unclassified' stamp: 'tg 7/17/2010 16:46'! testTwoLines self assert: '1 2' is: {{'1'} .{'2'}}! !