compiler/PPCAbstractCharacterNode.st
changeset 452 9f4558b3be66
parent 438 20598d7ce9fa
equal deleted inserted replaced
438:20598d7ce9fa 452:9f4558b3be66
    11 
    11 
    12 
    12 
    13 !PPCAbstractCharacterNode methodsFor:'accessing'!
    13 !PPCAbstractCharacterNode methodsFor:'accessing'!
    14 
    14 
    15 character
    15 character
    16 	^ character
    16     ^ character
    17 !
    17 !
    18 
    18 
    19 character: char
    19 character: char
    20 	character := char
    20     character := char
    21 !
    21 !
    22 
    22 
    23 prefix
    23 prefix
    24 	^ #char
    24     ^ #char
    25 ! !
    25 ! !
    26 
    26 
    27 !PPCAbstractCharacterNode methodsFor:'analysis'!
    27 !PPCAbstractCharacterNode methodsFor:'analysis'!
    28 
    28 
    29 acceptsEpsilon
    29 acceptsEpsilon
    30 	^ false
    30     ^ false
    31 !
    31 !
    32 
    32 
    33 firstCharSet
    33 firstCharSet
    34 	^ PPCharSetPredicate on: [:e | e = character ]
    34     ^ PPCharSetPredicate on: [:e | e = character ]
       
    35 !
       
    36 
       
    37 recognizedSentencesPrim
       
    38     ^ Array with: character asString
    35 ! !
    39 ! !
    36 
    40 
    37 !PPCAbstractCharacterNode methodsFor:'comparison'!
    41 !PPCAbstractCharacterNode methodsFor:'comparison'!
    38 
    42 
    39 = anotherNode
    43 = anotherNode
    40 	super = anotherNode ifFalse: [ ^ false ].
    44     super = anotherNode ifFalse: [ ^ false ].
    41 	^ character = anotherNode character.
    45     ^ character = anotherNode character.
    42 !
    46 !
    43 
    47 
    44 hash
    48 hash
    45 	^ super hash bitXor: character hash
    49     ^ super hash bitXor: character hash
    46 ! !
    50 ! !
    47 
    51 
    48 !PPCAbstractCharacterNode methodsFor:'compiling'!
    52 !PPCAbstractCharacterNode methodsFor:'compiling'!
    49 
    53 
    50 body: compiler
    54 body: compiler
    51 	| id |
    55     | id |
    52 	
    56     
    53 	character ppcPrintable ifTrue: [ 
    57     character ppcPrintable ifTrue: [ 
    54 		id := character storeString 
    58         id := character storeString 
    55 	] ifFalse: [ 
    59     ] ifFalse: [ 
    56 		id := compiler idFor: character prefixed: #char.
    60         id := compiler idFor: character prefixed: #char.
    57 		compiler addConstant: (Character value: character asInteger) as: id .
    61         compiler addConstant: (Character value: character asInteger) as: id .
    58 	].
    62     ].
    59 	
    63     
    60 	compiler add: '(context peek == ', id, ')'.
    64     compiler add: '(context peek == ', id, ')'.
    61 	compiler indent.
    65     compiler indent.
    62 	compiler add: 'ifFalse: [ self error: ''', character asInteger asString, ' expected'' at: context position ] '.
    66     compiler add: 'ifFalse: [ self error: ''', character asInteger asString, ' expected'' at: context position ] '.
    63 	compiler add: 'ifTrue: [ context next ].'.
    67     compiler add: 'ifTrue: [ context next ].'.
    64 	compiler dedent.
    68     compiler dedent.
       
    69 ! !
       
    70 
       
    71 !PPCAbstractCharacterNode methodsFor:'printing'!
       
    72 
       
    73 printNameOn: aStream
       
    74     super printNameOn: aStream.
       
    75 
       
    76     character = $" ifTrue: [ 
       
    77         "this is hack to allow for printing '' in comments..."
       
    78         aStream nextPutAll: ', '; nextPutAll: '$'''''.
       
    79         ^ self
       
    80     ].
       
    81 
       
    82     aStream nextPutAll: ', '; print: character
    65 ! !
    83 ! !
    66 
    84 
    67 !PPCAbstractCharacterNode class methodsFor:'documentation'!
    85 !PPCAbstractCharacterNode class methodsFor:'documentation'!
    68 
    86 
    69 version_HG
    87 version_HG