compiler/PPCPredicateNode.st
changeset 391 553a5456963b
child 392 9b297f0d949c
equal deleted inserted replaced
390:17ba167b8ee1 391:553a5456963b
       
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
       
     2 
       
     3 PPCAbstractPredicateNode subclass:#PPCPredicateNode
       
     4 	instanceVariableNames:''
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitCompiler-Nodes'
       
     8 !
       
     9 
       
    10 PPCPredicateNode comment:''
       
    11 !
       
    12 
       
    13 !PPCPredicateNode methodsFor:'as yet unclassified'!
       
    14 
       
    15 bodyOfPredicate: compiler
       
    16 	| id |
       
    17 	id := (compiler idFor: predicate prefixed: #predicate).
       
    18 	compiler addConstant: predicate as: id.
       
    19 
       
    20 	compiler addOnLine: '(context atEnd not and: [ ', id , ' value: context uncheckedPeek])'.
       
    21 	compiler indent.
       
    22 	compiler add: 'ifFalse: [ self error: ''predicate not found'' ]'.
       
    23 	compiler add: 'ifTrue: [ context next ].'.
       
    24 	compiler dedent.	
       
    25 !
       
    26 
       
    27 rewrite: changeStatus
       
    28 	| charSet |
       
    29 	
       
    30 	(predicate class == PPCharSetPredicate) ifTrue: [ 
       
    31 		charSet := predicate.
       
    32 	].
       
    33 	charSet := PPCharSetPredicate on: predicate.
       
    34 	
       
    35 	(charSet equals: (PPCharSetPredicate on: [ :char | char isLetter])) ifTrue: [ 
       
    36 		changeStatus change.
       
    37 		^ PPCMessagePredicateNode new
       
    38 			name: name;
       
    39 			message: #isLetter;
       
    40 			predicate: predicate;
       
    41 			yourself
       
    42 	].
       
    43 
       
    44 	(charSet equals: (PPCharSetPredicate on: [ :char | char isDigit])) ifTrue: [ 
       
    45 		changeStatus change.
       
    46 		^ PPCMessagePredicateNode new
       
    47 			name: name;
       
    48 			message: #isDigit;
       
    49 			predicate: predicate;
       
    50 			yourself
       
    51 	].
       
    52 
       
    53 	(charSet equals: (PPCharSetPredicate on: [ :char | char isAlphaNumeric])) ifTrue: [ 
       
    54 		changeStatus change.
       
    55 		^ PPCMessagePredicateNode new
       
    56 			name: name;
       
    57 			message: #isAlphaNumeric;
       
    58 			predicate: predicate;
       
    59 			yourself
       
    60 	].
       
    61 
       
    62 	(charSet equals: (PPCharSetPredicate on: [ :char | char isSeparator])) ifTrue: [ 
       
    63 		changeStatus change.
       
    64 		^ PPCMessagePredicateNode new
       
    65 			name: name;
       
    66 			message: #isSeparator;
       
    67 			predicate: predicate;
       
    68 			yourself
       
    69 	].
       
    70 
       
    71 
       
    72 	(charSet equals: (PPCharSetPredicate on: [ :char | true ])) ifTrue: [ 
       
    73 		changeStatus change.
       
    74 		^ PPCAnyNode new
       
    75 			name: name;
       
    76 			yourself
       
    77 	].
       
    78 
       
    79 	changeStatus change.
       
    80 	^ PPCCharSetPredicateNode new
       
    81 		name: name;
       
    82 		predicate: charSet;
       
    83 		yourself.
       
    84 ! !
       
    85