support #true and #false literals
This commit is contained in:
		
							parent
							
								
									d810e42666
								
							
						
					
					
						commit
						6614f8fc4f
					
				
							
								
								
									
										28
									
								
								src/read.c
								
								
								
								
							
							
						
						
									
										28
									
								
								src/read.c
								
								
								
								
							|  | @ -48,6 +48,19 @@ peek(struct pic_port *port) | ||||||
|   return c; |   return c; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static bool | ||||||
|  | expect(struct pic_port *port, const char *str) | ||||||
|  | { | ||||||
|  |   char c; | ||||||
|  | 
 | ||||||
|  |   while ((c = *str++) != 0) { | ||||||
|  |     if (c != next(port)) | ||||||
|  |       return false; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return true; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static bool | static bool | ||||||
| isdelim(char c) | isdelim(char c) | ||||||
| { | { | ||||||
|  | @ -250,13 +263,26 @@ read_boolean(pic_state *pic, struct pic_port *port, char c) | ||||||
|   UNUSED(pic); |   UNUSED(pic); | ||||||
|   UNUSED(port); |   UNUSED(port); | ||||||
| 
 | 
 | ||||||
|   /* TODO: support #true and #false */ |   if (! isdelim(peek(port))) { | ||||||
|  |     if (c == 't') { | ||||||
|  |       if (! expect(port, "rue")) { | ||||||
|  |         goto fail; | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       if (! expect(port, "alse")) { | ||||||
|  |         goto fail; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   if (c == 't') { |   if (c == 't') { | ||||||
|     return pic_true_value(); |     return pic_true_value(); | ||||||
|   } else { |   } else { | ||||||
|     return pic_false_value(); |     return pic_false_value(); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |  fail: | ||||||
|  |   read_error(pic, "illegal character during reading boolean literal"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static pic_value | static pic_value | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Yuichi Nishiwaki
						Yuichi Nishiwaki