Allow pub-keyword for impl-block
This commit is contained in:
		
							parent
							
								
									a6a903a45d
								
							
						
					
					
						commit
						9d5a20e76a
					
				| @ -1,5 +1,4 @@ | |||||||
| import std::print; | import std::print; | ||||||
| import std::from_str; |  | ||||||
| import std::add_char; | import std::add_char; | ||||||
| import std::set_char; | import std::set_char; | ||||||
| import std::free_string; | import std::free_string; | ||||||
| @ -8,7 +7,7 @@ import std::add_num_to_str; | |||||||
| import std::concat_strings; | import std::concat_strings; | ||||||
| 
 | 
 | ||||||
| fn main() { | fn main() { | ||||||
|     let mut test = from_str("hello"); |     let mut test = String::new(); | ||||||
| 
 | 
 | ||||||
|     concat_strings(&mut test, from_str(" world")); |     concat_strings(&mut test, from_str(" world")); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -11,6 +11,17 @@ struct String { | |||||||
|     must_be_freed: bool, |     must_be_freed: bool, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl String { | ||||||
|  |     pub fn new() -> String { | ||||||
|  |         String { | ||||||
|  |             inner: char::alloca(0), | ||||||
|  |             length: 0, | ||||||
|  |             max_length: 0, | ||||||
|  |             must_be_freed: true, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| impl binop (lhs: String) + (rhs: *char) -> String { | impl binop (lhs: String) + (rhs: *char) -> String { | ||||||
|     let mut new = lhs; |     let mut new = lhs; | ||||||
|     let added = from_str(rhs); |     let added = from_str(rhs); | ||||||
|  | |||||||
| @ -1052,7 +1052,9 @@ impl Parse for AssociatedFunctionBlock { | |||||||
|         let ty = stream.parse::<Type>()?; |         let ty = stream.parse::<Type>()?; | ||||||
|         stream.expect(Token::BraceOpen)?; |         stream.expect(Token::BraceOpen)?; | ||||||
|         let mut functions = Vec::new(); |         let mut functions = Vec::new(); | ||||||
|         while let Some(Token::FnKeyword) = stream.peek() { |         loop { | ||||||
|  |             match stream.peek() { | ||||||
|  |                 Some(Token::FnKeyword) | Some(Token::PubKeyword) => { | ||||||
|                     let mut fun: FunctionDefinition = stream.parse()?; |                     let mut fun: FunctionDefinition = stream.parse()?; | ||||||
|                     fun.0.self_kind = match fun.0.self_kind { |                     fun.0.self_kind = match fun.0.self_kind { | ||||||
|                         SelfKind::Owned(_) => SelfKind::Owned(ty.0.clone()), |                         SelfKind::Owned(_) => SelfKind::Owned(ty.0.clone()), | ||||||
| @ -1062,6 +1064,9 @@ impl Parse for AssociatedFunctionBlock { | |||||||
|                     }; |                     }; | ||||||
|                     functions.push(fun); |                     functions.push(fun); | ||||||
|                 } |                 } | ||||||
|  |                 _ => break, | ||||||
|  |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         stream.expect(Token::BraceClose)?; |         stream.expect(Token::BraceClose)?; | ||||||
|         Ok(AssociatedFunctionBlock(ty, functions)) |         Ok(AssociatedFunctionBlock(ty, functions)) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user