| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | ! Copyright (C) 2007 Daniel Ehrenberg | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:40 -04:00
										 |  |  | USING: namespaces make parser lexer kernel sequences words | 
					
						
							| 
									
										
										
										
											2009-01-20 17:12:09 -05:00
										 |  |  | quotations math accessors locals ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | IN: multiline | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-18 04:44:54 -04:00
										 |  |  | ERROR: bad-heredoc identifier ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-04 22:38:23 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							| 
									
										
										
										
											2011-09-03 13:17:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : rest-of-line ( -- seq )
 | 
					
						
							|  |  |  |     lexer get [ line-text>> ] [ column>> ] bi tail ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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* ;
 | 
					
						
							| 
									
										
										
										
											2011-09-03 13:17:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-04 22:38:23 -04:00
										 |  |  | PRIVATE>
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-03 13:17:30 -04:00
										 |  |  | ERROR: text-found-before-eol string ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | : parse-here ( -- str )
 | 
					
						
							| 
									
										
										
										
											2011-09-03 13:17:30 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         rest-of-line dup [ drop ] [ text-found-before-eol ] if-empty
 | 
					
						
							|  |  |  |         (parse-here) | 
					
						
							|  |  |  |     ] "" make but-last ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 01:39:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 02:27:50 -04:00
										 |  |  | SYNTAX: STRING: | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |     CREATE-WORD | 
					
						
							| 
									
										
										
										
											2008-12-15 20:44:56 -05:00
										 |  |  |     parse-here 1quotation | 
					
						
							| 
									
										
										
										
											2009-03-21 02:27:50 -04:00
										 |  |  |     (( -- string )) define-inline ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 17:23:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-04 22:38:23 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							| 
									
										
										
										
											2009-01-20 17:12:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 17:05:14 -04:00
										 |  |  | :: (scan-multiline-string) ( i end -- j )
 | 
					
						
							| 
									
										
										
										
											2009-01-20 17:12:09 -05:00
										 |  |  |     lexer get line-text>> :> text | 
					
						
							|  |  |  |     text [ | 
					
						
							| 
									
										
										
										
											2009-01-21 01:44:43 -05:00
										 |  |  |         end text i start* [| j | | 
					
						
							|  |  |  |             i j text subseq % j end length +
 | 
					
						
							|  |  |  |         ] [ | 
					
						
							|  |  |  |             text i short tail % CHAR: \n , | 
					
						
							| 
									
										
										
										
											2009-01-20 17:12:09 -05:00
										 |  |  |             lexer get next-line | 
					
						
							| 
									
										
										
										
											2009-08-17 17:05:14 -04:00
										 |  |  |             0 end (scan-multiline-string) | 
					
						
							| 
									
										
										
										
											2008-02-07 18:12:50 -05:00
										 |  |  |         ] if*
 | 
					
						
							| 
									
										
										
										
											2009-01-20 17:12:09 -05:00
										 |  |  |     ] [ end unexpected-eof ] if ;
 | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2009-08-17 17:05:14 -04:00
										 |  |  | :: (parse-multiline-string) ( end-text skip-n-chars -- str )
 | 
					
						
							| 
									
										
										
										
											2007-12-11 17:23:56 -05:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2009-01-20 17:12:09 -05:00
										 |  |  |         lexer get
 | 
					
						
							| 
									
										
										
										
											2009-08-17 17:05:14 -04:00
										 |  |  |         [ skip-n-chars + end-text (scan-multiline-string) ] | 
					
						
							| 
									
										
										
										
											2009-01-20 17:12:09 -05:00
										 |  |  |         change-column drop
 | 
					
						
							|  |  |  |     ] "" make ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 17:23:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-18 04:44:54 -04:00
										 |  |  | :: advance-same-line ( text -- )
 | 
					
						
							|  |  |  |     lexer get [ text length + ] change-column drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :: (parse-til-line-begins) ( begin-text -- )
 | 
					
						
							|  |  |  |     lexer get still-parsing? [ | 
					
						
							|  |  |  |         lexer get line-text>> begin-text sequence= [ | 
					
						
							|  |  |  |             begin-text advance-same-line | 
					
						
							|  |  |  |         ] [ | 
					
						
							|  |  |  |             lexer get line-text>> % "\n" % | 
					
						
							|  |  |  |             lexer get next-line | 
					
						
							|  |  |  |             begin-text (parse-til-line-begins) | 
					
						
							|  |  |  |         ] if
 | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         begin-text bad-heredoc | 
					
						
							|  |  |  |     ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : parse-til-line-begins ( begin-text -- seq )
 | 
					
						
							|  |  |  |     [ (parse-til-line-begins) ] "" make ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 17:05:14 -04:00
										 |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : parse-multiline-string ( end-text -- str )
 | 
					
						
							|  |  |  |     1 (parse-multiline-string) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 02:27:50 -04:00
										 |  |  | SYNTAX: /* "*/" parse-multiline-string drop ;
 | 
					
						
							| 
									
										
										
										
											2009-08-17 17:05:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | SYNTAX: HEREDOC: | 
					
						
							| 
									
										
										
										
											2009-08-18 04:44:54 -04:00
										 |  |  |     lexer get skip-blank | 
					
						
							|  |  |  |     rest-of-line | 
					
						
							|  |  |  |     lexer get next-line | 
					
						
							| 
									
										
										
										
											2009-10-28 14:38:27 -04:00
										 |  |  |     parse-til-line-begins suffix! ;
 | 
					
						
							| 
									
										
										
										
											2009-08-18 04:44:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | SYNTAX: DELIMITED: | 
					
						
							|  |  |  |     lexer get skip-blank | 
					
						
							|  |  |  |     rest-of-line | 
					
						
							| 
									
										
										
										
											2009-08-17 17:05:14 -04:00
										 |  |  |     lexer get next-line | 
					
						
							| 
									
										
										
										
											2009-10-28 14:38:27 -04:00
										 |  |  |     0 (parse-multiline-string) suffix! ;
 |