| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | ! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2009-03-18 18:03:38 -04:00
										 |  |  | USING: kernel arrays accessors fry sequences regexp.classes | 
					
						
							|  |  |  | math.ranges math ;
 | 
					
						
							| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | IN: regexp.ast | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: negation term ;
 | 
					
						
							|  |  |  | C: <negation> negation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: from-to n m ;
 | 
					
						
							|  |  |  | C: <from-to> from-to | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: at-least n ;
 | 
					
						
							|  |  |  | C: <at-least> at-least | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-25 13:22:12 -05:00
										 |  |  | TUPLE: tagged-epsilon tag ;
 | 
					
						
							|  |  |  | C: <tagged-epsilon> tagged-epsilon | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-04 01:36:03 -05:00
										 |  |  | CONSTANT: epsilon T{ tagged-epsilon { tag t } } | 
					
						
							| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-19 17:48:46 -05:00
										 |  |  | TUPLE: concatenation first second ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <concatenation> ( seq -- concatenation )
 | 
					
						
							| 
									
										
										
										
											2009-04-06 18:32:20 -04:00
										 |  |  |     [ epsilon ] [ [ ] [ concatenation boa ] map-reduce ] if-empty ;
 | 
					
						
							| 
									
										
										
										
											2009-02-19 17:48:46 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: alternation first second ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <alternation> ( seq -- alternation )
 | 
					
						
							| 
									
										
										
										
											2009-04-06 18:32:20 -04:00
										 |  |  |     [ ] [ alternation boa ] map-reduce ;
 | 
					
						
							| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: star term ;
 | 
					
						
							|  |  |  | C: <star> star | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: with-options tree options ;
 | 
					
						
							|  |  |  | C: <with-options> with-options | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: options on off ;
 | 
					
						
							|  |  |  | C: <options> options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-16 18:53:38 -04:00
										 |  |  | SINGLETONS: unix-lines dotall multiline case-insensitive reversed-regexp ;
 | 
					
						
							| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <maybe> ( term -- term' )
 | 
					
						
							|  |  |  |     f <concatenation> 2array <alternation> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <plus> ( term -- term' )
 | 
					
						
							|  |  |  |     dup <star> 2array <concatenation> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : repetition ( n term -- term' )
 | 
					
						
							|  |  |  |     <array> <concatenation> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: <times> ( term times -- term' )
 | 
					
						
							| 
									
										
										
										
											2009-03-18 18:03:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | M: at-least <times> | 
					
						
							|  |  |  |     n>> swap [ repetition ] [ <star> ] bi 2array <concatenation> ;
 | 
					
						
							| 
									
										
										
										
											2009-03-18 18:03:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : to-times ( term n -- ast )
 | 
					
						
							| 
									
										
										
										
											2012-07-16 18:45:21 -04:00
										 |  |  |     [ drop epsilon ] | 
					
						
							| 
									
										
										
										
											2009-08-13 20:21:44 -04:00
										 |  |  |     [ dupd 1 - to-times 2array <concatenation> <maybe> ] | 
					
						
							| 
									
										
										
										
											2012-07-16 18:45:21 -04:00
										 |  |  |     if-zero ;
 | 
					
						
							| 
									
										
										
										
											2009-03-18 18:03:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | M: from-to <times> | 
					
						
							| 
									
										
										
										
											2009-03-18 18:03:38 -04:00
										 |  |  |     [ n>> swap repetition ] | 
					
						
							|  |  |  |     [ [ m>> ] [ n>> ] bi - to-times ] 2bi
 | 
					
						
							|  |  |  |     2array <concatenation> ;
 | 
					
						
							| 
									
										
										
										
											2009-02-18 13:27:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : char-class ( ranges ? -- term )
 | 
					
						
							| 
									
										
										
										
											2009-02-19 19:28:54 -05:00
										 |  |  |     [ <or-class> ] dip [ <not-class> ] when ;
 | 
					
						
							| 
									
										
										
										
											2009-02-20 18:54:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-11 16:51:54 -04:00
										 |  |  | TUPLE: lookahead term ;
 | 
					
						
							| 
									
										
										
										
											2009-02-20 18:54:48 -05:00
										 |  |  | C: <lookahead> lookahead | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-11 16:51:54 -04:00
										 |  |  | TUPLE: lookbehind term ;
 | 
					
						
							| 
									
										
										
										
											2009-02-20 18:54:48 -05:00
										 |  |  | C: <lookbehind> lookbehind |