PPCompositeParser subclass: #PPJsonGrammar instanceVariableNames: 'members pair string value elements number object array trueToken falseToken nullToken char stringToken numberToken charEscape charNormal charOctal' classVariableNames: 'CharacterTable' poolDictionaries: '' category: 'PetitJson-Core'! !PPJsonGrammar methodsFor: 'accessing' stamp: 'lr 7/28/2010 08:17'! start ^ value end! ! !PPJsonGrammar methodsFor: 'grammar' stamp: 'lr 7/28/2010 08:12'! array ^ $[ asParser token trim , elements optional , $] asParser token trim! ! !PPJsonGrammar methodsFor: 'grammar' stamp: 'lr 7/28/2010 08:12'! elements ^ value separatedBy: $, asParser token trim! ! !PPJsonGrammar methodsFor: 'grammar' stamp: 'lr 7/28/2010 08:12'! members ^ pair separatedBy: $, asParser token trim! ! !PPJsonGrammar methodsFor: 'grammar' stamp: 'lr 7/28/2010 08:12'! object ^ ${ asParser token trim , members optional , $} asParser token trim! ! !PPJsonGrammar methodsFor: 'grammar' stamp: 'lr 7/28/2010 08:19'! pair ^ stringToken , $: asParser token trim , value! ! !PPJsonGrammar methodsFor: 'grammar' stamp: 'lr 12/6/2009 13:31'! value ^ stringToken / numberToken / object / array / trueToken / falseToken / nullToken! ! !PPJsonGrammar methodsFor: 'primitives' stamp: 'lr 7/28/2010 09:40'! char ^ charEscape / charOctal / charNormal! ! !PPJsonGrammar methodsFor: 'primitives' stamp: 'lr 7/28/2010 10:14'! charEscape ^ $\ asParser , (PPPredicateObjectParser anyOf: (String withAll: CharacterTable keys))! ! !PPJsonGrammar methodsFor: 'primitives' stamp: 'lr 7/28/2010 09:59'! charNormal ^ PPPredicateObjectParser anyExceptAnyOf: '\"'! ! !PPJsonGrammar methodsFor: 'primitives' stamp: 'lr 7/28/2010 09:45'! charOctal ^ '\u' asParser , (#hex asParser min: 4 max: 4)! ! !PPJsonGrammar methodsFor: 'primitives' stamp: 'lr 7/28/2010 08:14'! number ^ $- asParser optional , #digit asParser plus , ($. asParser , #digit asParser plus) optional , (($e asParser / $E asParser) , ($- asParser / $+ asParser) optional , #digit asParser plus) optional! ! !PPJsonGrammar methodsFor: 'primitives' stamp: 'lr 7/28/2010 09:47'! string ^ $" asParser , char star , $" asParser! ! !PPJsonGrammar methodsFor: 'tokens' stamp: 'lr 7/28/2010 08:12'! falseToken ^ 'false' asParser token trim! ! !PPJsonGrammar methodsFor: 'tokens' stamp: 'lr 7/28/2010 08:12'! nullToken ^ 'null' asParser token trim! ! !PPJsonGrammar methodsFor: 'tokens' stamp: 'lr 7/28/2010 08:12'! numberToken ^ number token trim! ! !PPJsonGrammar methodsFor: 'tokens' stamp: 'lr 7/28/2010 08:12'! stringToken ^ string token trim! ! !PPJsonGrammar methodsFor: 'tokens' stamp: 'lr 7/28/2010 08:12'! trueToken ^ 'true' asParser token trim! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! PPJsonGrammar class instanceVariableNames: ''! !PPJsonGrammar class methodsFor: 'initialization' stamp: 'lr 7/28/2010 09:35'! initialize CharacterTable := Dictionary new. CharacterTable at: $\ put: $\; at: $/ put: $/; at: $" put: $"; at: $b put: Character backspace; at: $f put: Character newPage; at: $n put: Character lf; at: $r put: Character cr; at: $t put: Character tab! ! PPJsonGrammar subclass: #PPJsonParser instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'PetitJson-Core'! !PPJsonParser methodsFor: 'grammar' stamp: 'lr 12/6/2009 13:29'! array ^ super array ==> [ :nodes | Array withAll: (nodes second ifNil: [ #() ]) ]! ! !PPJsonParser methodsFor: 'grammar' stamp: 'lr 12/6/2009 13:25'! elements ^ super elements ==> [ :nodes | nodes reject: [ :each | each isKindOf: PPToken ] ]! ! !PPJsonParser methodsFor: 'grammar' stamp: 'lr 12/6/2009 13:26'! members ^ super members ==> [ :nodes | nodes reject: [ :each | each isKindOf: PPToken ] ]! ! !PPJsonParser methodsFor: 'grammar' stamp: 'lr 7/28/2010 08:19'! object ^ super object ==> [ :nodes | (nodes second ifNil: [ #() ]) inject: Dictionary new into: [ :result :each | result add: each; yourself ] ]! ! !PPJsonParser methodsFor: 'grammar' stamp: 'lr 7/28/2010 08:18'! pair ^ super pair map: [ :key :sep :val | key -> val ]! ! !PPJsonParser methodsFor: 'primitives' stamp: 'lr 7/28/2010 10:14'! charEscape ^ super charEscape ==> [ :nodes | CharacterTable at: nodes last ]! ! !PPJsonParser methodsFor: 'primitives' stamp: 'lr 7/28/2010 10:15'! charOctal ^ super charOctal ==> [ :nodes | Character value: (nodes last allButFirst inject: nodes last first digitValue into: [ :result :each | (result << 4) + each digitValue ]) ]! ! !PPJsonParser methodsFor: 'tokens' stamp: 'lr 12/6/2009 12:48'! falseToken ^ super falseToken ==> [ :token | false ]! ! !PPJsonParser methodsFor: 'tokens' stamp: 'lr 12/6/2009 12:48'! nullToken ^ super nullToken ==> [ :token | nil ]! ! !PPJsonParser methodsFor: 'tokens' stamp: 'lr 10/28/2010 19:28'! numberToken ^ super numberToken ==> [ :token | (token value copyWithout: $+) asLowercase asNumber ]! ! !PPJsonParser methodsFor: 'tokens' stamp: 'lr 7/28/2010 10:06'! stringToken ^ string trim ==> [ :nodes | String withAll: nodes second ]! ! !PPJsonParser methodsFor: 'tokens' stamp: 'lr 12/6/2009 12:49'! trueToken ^ super trueToken ==> [ :token | true ]! ! PPJsonGrammar initialize!