tests/PPLambdaParser.st
changeset 375 e2b2f08d054e
parent 184 dff934a0213f
child 376 a2656b27cace
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/PPLambdaParser.st	Fri Oct 03 01:36:33 2014 +0100
@@ -0,0 +1,74 @@
+"{ Package: 'stx:goodies/petitparser' }"
+
+PPCompositeParser subclass:#PPLambdaParser
+	instanceVariableNames:'expression abstraction application variable'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitTests-Examples'
+!
+
+
+!PPLambdaParser class methodsFor:'curch-booleans'!
+
+and
+	^ self parse: '\p.\q.((p q) p)'
+!
+
+false
+	^ self parse: '\x.\y.y'
+!
+
+ifthenelse
+	^ self parse: '\p.p'
+!
+
+not
+	^ self parse: '\p.\a.\b.((p b) a)'
+!
+
+or
+	^ self parse: '\p.\q.((p p) q)'
+!
+
+true
+	^ self parse: '\x.\y.x'
+! !
+
+!PPLambdaParser methodsFor:'accessing'!
+
+start
+	^ expression end
+! !
+
+!PPLambdaParser methodsFor:'productions'!
+
+abstraction
+	^ $\ asParser trim , variable , $. asParser trim , expression ==> [ :node | Array with: node second with: node fourth ]
+!
+
+application
+	^ $( asParser trim , expression , expression , $) asParser trim ==> [ :node | Array with: node second with: node third ]
+!
+
+expression
+	^ variable / abstraction / application
+!
+
+variable
+	^ (#letter asParser , #word asParser star) flatten trim
+! !
+
+!PPLambdaParser class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLambdaParser.st,v 1.4 2014-03-04 14:34:00 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLambdaParser.st,v 1.4 2014-03-04 14:34:00 cg Exp $'
+!
+
+version_SVN
+    ^ '$Id: PPLambdaParser.st,v 1.4 2014-03-04 14:34:00 cg Exp $'
+! !
+