| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | ! Copyright (C) 2007 Daniel Ehrenberg | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-08-30 22:58:20 -04:00
										 |  |  | USING: namespaces parser lexer kernel sequences words quotations math | 
					
						
							|  |  |  | accessors ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | IN: multiline | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-04 22:38:23 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | : next-line-text ( -- str )
 | 
					
						
							| 
									
										
										
										
											2008-08-31 03:28:58 -04:00
										 |  |  |     lexer get dup next-line line-text>> ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : (parse-here) ( -- )
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:12:50 -05:00
										 |  |  |     next-line-text [ | 
					
						
							|  |  |  |         dup ";" =
 | 
					
						
							|  |  |  |         [ drop lexer get next-line ] | 
					
						
							|  |  |  |         [ % "\n" % (parse-here) ] if
 | 
					
						
							|  |  |  |     ] [ ";" unexpected-eof ] if* ;
 | 
					
						
							| 
									
										
										
										
											2008-09-04 22:38:23 -04:00
										 |  |  | PRIVATE>
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : parse-here ( -- str )
 | 
					
						
							| 
									
										
										
										
											2008-05-07 02:38:34 -04:00
										 |  |  |     [ (parse-here) ] "" make but-last
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  |     lexer get next-line ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : STRING: | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |     CREATE-WORD | 
					
						
							| 
									
										
										
										
											2008-02-12 16:52:47 -05:00
										 |  |  |     parse-here 1quotation define-inline ; parsing | 
					
						
							| 
									
										
										
										
											2007-12-11 17:23:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-04 22:38:23 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							| 
									
										
										
										
											2007-12-12 00:33:36 -05:00
										 |  |  | : (parse-multiline-string) ( start-index end-text -- end-index )
 | 
					
						
							| 
									
										
										
										
											2008-08-31 03:28:58 -04:00
										 |  |  |     lexer get line-text>> [ | 
					
						
							| 
									
										
										
										
											2008-02-07 18:12:50 -05:00
										 |  |  |         2dup start
 | 
					
						
							|  |  |  |         [ rot dupd >r >r swap subseq % r> r> length + ] [ | 
					
						
							|  |  |  |             rot tail % "\n" % 0
 | 
					
						
							|  |  |  |             lexer get next-line swap (parse-multiline-string) | 
					
						
							|  |  |  |         ] if*
 | 
					
						
							|  |  |  |     ] [ nip unexpected-eof ] if* ;
 | 
					
						
							| 
									
										
										
										
											2008-09-04 22:38:23 -04:00
										 |  |  | PRIVATE>
 | 
					
						
							| 
									
										
										
										
											2007-12-11 17:23:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-12 00:33:36 -05:00
										 |  |  | : parse-multiline-string ( end-text -- str )
 | 
					
						
							| 
									
										
										
										
											2007-12-11 17:23:56 -05:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2008-08-30 22:58:20 -04:00
										 |  |  |         lexer get column>> swap (parse-multiline-string) | 
					
						
							|  |  |  |         lexer get (>>column) | 
					
						
							| 
									
										
										
										
											2008-05-07 02:38:34 -04:00
										 |  |  |     ] "" make rest but-last ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 17:23:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <" | 
					
						
							| 
									
										
										
										
											2007-12-12 00:33:36 -05:00
										 |  |  |     "\">" parse-multiline-string parsed ; parsing | 
					
						
							| 
									
										
										
										
											2008-03-05 15:51:01 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : /* "*/" parse-multiline-string drop ; parsing |