From d45ed669f81b9ece4a59bc4869af4e6faf6c08e6 Mon Sep 17 00:00:00 2001 From: Chris Double Date: Thu, 20 Dec 2007 11:39:42 +1300 Subject: [PATCH] Add digit, number and string parser to peg --- extra/peg/peg.factor | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 7fa1fb90e5..411a47b9bd 100644 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Chris Double. ! See http://factorcode.org/license.txt for BSD license. USING: kernel sequences strings namespaces math assocs shuffle - vectors arrays combinators.lib memoize ; + vectors arrays combinators.lib memoize math.parser ; IN: peg TUPLE: parse-result remaining ast ; @@ -265,3 +265,16 @@ MEMO: delay ( parser -- parser ) MEMO: list-of ( items separator -- parser ) hide over 2array seq repeat0 [ concat ] action 2array seq [ unclip 1vector swap first append ] action ; + +MEMO: 'digit' ( -- parser ) + [ digit? ] satisfy [ digit> ] action ; + +MEMO: 'integer' ( -- parser ) + 'digit' repeat1 [ 10 swap digits>integer ] action ; + +MEMO: 'string' ( -- parser ) + [ + [ CHAR: " = ] satisfy hide , + [ CHAR: " = not ] satisfy repeat0 , + [ CHAR: " = ] satisfy hide , + ] { } make seq [ first >string ] action ;