Add digit, number and string parser to peg
							parent
							
								
									8aed4d6b26
								
							
						
					
					
						commit
						d45ed669f8
					
				| 
						 | 
				
			
			@ -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 ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue