summaryrefslogtreecommitdiff
path: root/deepcrow/src/parser.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-08-20 08:16:58 -0700
committerMike Buland <mike@xagasoft.com>2026-08-20 08:16:58 -0700
commit12c7b851d866401ac4a32c746ed237b051aa3dd3 (patch)
treed8c13033a295f9caa7d9ee388ca64272d5dcfa15 /deepcrow/src/parser.rs
parentd1e78b4a3454984db74ebf2a302a64b985ce6de4 (diff)
downloaddeepcrow-main.tar.gz
deepcrow-main.tar.bz2
deepcrow-main.tar.xz
deepcrow-main.zip
Making progress cleaning up.HEADmain
Diffstat (limited to '')
-rw-r--r--deepcrow/src/parser.rs217
1 files changed, 108 insertions, 109 deletions
diff --git a/deepcrow/src/parser.rs b/deepcrow/src/parser.rs
index 529c58e..5c6680e 100644
--- a/deepcrow/src/parser.rs
+++ b/deepcrow/src/parser.rs
@@ -36,9 +36,9 @@ impl<'a> Context<'a> {
36 } 36 }
37 37
38 /* 38 /*
39 pub fn check_unwrapped<T: Fn( &TokenType, &TokenType ) -> bool>(&self, context: &str, f: T) -> Result<bool> { 39 pub fn check_unwrapped<T: Fn( &SymbolType, &SymbolType ) -> bool>(&self, context: &str, f: T) -> CrimResult<bool> {
40 if self.cur().is_none() || self.peek().is_none() { 40 if self.cur().is_none() || self.peek().is_none() {
41 Err(DeepCrowError::eos( context )) 41 Err(CrimError::eos( context ))
42 } else { 42 } else {
43 Ok(f( self.cur().unwrap().symbol(), self.peek().unwrap().symbol())) 43 Ok(f( self.cur().unwrap().symbol(), self.peek().unwrap().symbol()))
44 } 44 }
@@ -51,35 +51,34 @@ impl<'a> Context<'a> {
51} 51}
52 52
53trait SymbolHelper { 53trait SymbolHelper {
54 fn is<T: Fn( &TokenType ) -> bool>(&self, context: &str, f: T ) -> Result<bool>; 54 fn is<T: Fn( &SymbolType ) -> bool>(&self, context: &str, f: T ) -> CrimResult<bool>;
55 #[allow(dead_code)] 55 #[allow(dead_code)]
56 fn is_valid_tag_name(&self) -> Result<bool>; 56 fn is_valid_tag_name(&self) -> CrimResult<bool>;
57} 57}
58 58
59impl<'a> SymbolHelper for Option<Symbol<'a>> { 59impl<'a> SymbolHelper for Option<Symbol<'a>> {
60 fn is<T: Fn( &TokenType ) -> bool>(&self, context: &str, f: T ) -> Result<bool> { 60 fn is<T: Fn( &SymbolType ) -> bool>(&self, context: &str, f: T ) -> CrimResult<bool> {
61 if let Some(st) = self { 61 if let Some(st) = self {
62 Ok(f( &st.symbol() )) 62 Ok(f( &st.symbol() ))
63 } else { 63 } else {
64 Err(DeepCrowError::eos( context )) 64 Err(CrimError::eos( context ))
65 } 65 }
66 } 66 }
67 67
68 fn is_valid_tag_name(&self) -> Result<bool> { 68 fn is_valid_tag_name(&self) -> CrimResult<bool> {
69 if let Some(st) = self { 69 if let Some(st) = self {
70 Ok(match st.symbol() { 70 Ok(match st.symbol() {
71 TokenType::Identifier(_) | 71 TokenType::Identifier("view") |
72 TokenType::View | 72 TokenType::Identifier("output") |
73 TokenType::Output | 73 TokenType::Identifier("loop") |
74 TokenType::Loop | 74 TokenType::Identifier("if") |
75 TokenType::If | 75 TokenType::Identifier("elif") |
76 TokenType::ElIf | 76 TokenType::Identifier("else") |
77 TokenType::Else | 77 TokenType::Identifier("show") => true,
78 TokenType::Show => true,
79 _ => false 78 _ => false
80 }) 79 })
81 } else { 80 } else {
82 Err(DeepCrowError::parse( 81 Err(CrimError::parse(
83 Position::none(), 82 Position::none(),
84 "Unexpeceted end of stream.".to_string() 83 "Unexpeceted end of stream.".to_string()
85 )) 84 ))
@@ -183,17 +182,17 @@ impl Parser {
183 } 182 }
184 } 183 }
185 184
186 fn lex_error<T>(&self, error: &Symbol) -> Result<T> { 185 fn lex_error<T>(&self, error: &Symbol) -> CrimResult<T> {
187 if let TokenType::Error{what} = error.symbol() { 186 if let SymbolType::Error{what} = error.symbol() {
188 Err(DeepCrowError::parse( *error.start(), 187 Err(CrimError::parse( *error.start(),
189 format!("What: {:?}", *what) 188 format!("What: {:?}", *what)
190 )) 189 ))
191 } else { 190 } else {
192 Err(DeepCrowError::parse( Position::none(), "Not an error?".into())) 191 Err(CrimError::parse( Position::none(), "Not an error?".into()))
193 } 192 }
194 } 193 }
195 194
196 pub fn parse(&self, src: &str, source: usize ) -> Result<Vec<View>> { 195 pub fn parse(&self, src: &str, source: usize ) -> CrimResult<Vec<View>> {
197 let ll = Lexer::new( src ); 196 let ll = Lexer::new( src );
198 let mut ctx = Context::new( ll, source ); 197 let mut ctx = Context::new( ll, source );
199 198
@@ -201,24 +200,24 @@ impl Parser {
201 self.p_input( &mut ctx ) 200 self.p_input( &mut ctx )
202 } 201 }
203 202
204 fn p_input(&self, ctx: &mut Context ) -> Result<Vec<View>> { 203 fn p_input(&self, ctx: &mut Context ) -> CrimResult<Vec<View>> {
205 let mut tags = Vec::new(); 204 let mut tags = Vec::new();
206 loop { 205 loop {
207 if ctx.cur().is_none() { 206 if ctx.cur().is_none() {
208 break; 207 break;
209 } 208 }
210 match ctx.cur().unwrap().symbol() { 209 match ctx.cur().unwrap().symbol() {
211 TokenType::Text(_) => { /* Skip top level text */ } 210 SymbolType::Text(_) => { /* Skip top level text */ }
212 TokenType::StartFlat => { 211 SymbolType::StartFlat => {
213 let tb = self.parse_tag( ctx )?; 212 let tb = self.parse_tag( ctx )?;
214 let tb = self.parse_tag_set( ctx, tb )?; 213 let tb = self.parse_tag_set( ctx, tb )?;
215 tags.push( tb ); 214 tags.push( tb );
216 } 215 }
217 TokenType::Error{..} => { 216 SymbolType::Error{..} => {
218 self.lex_error( &ctx.cur().unwrap() )?; 217 self.lex_error( &ctx.cur().unwrap() )?;
219 } 218 }
220 _ => { 219 _ => {
221 return Err(DeepCrowError::parse( 220 return Err(CrimError::parse(
222 *ctx.cur().unwrap().start(), 221 *ctx.cur().unwrap().start(),
223 format!("Unexpected symbol {:?} found looking for tags.", ctx.cur().unwrap().symbol() ) 222 format!("Unexpected symbol {:?} found looking for tags.", ctx.cur().unwrap().symbol() )
224 )); 223 ));
@@ -231,11 +230,11 @@ impl Parser {
231 for tag in tags { 230 for tag in tags {
232 let start_pos = tag.start_pos(); 231 let start_pos = tag.start_pos();
233 let name = tag.name().clone(); 232 let name = tag.name().clone();
234 if tag.is_name(&TokenType::View) && 233 if tag.is_name(&SymbolType::View) &&
235 let BuildResult::View(view) = tag.build( ctx )? { 234 let BuildResult::View(view) = tag.build( ctx )? {
236 views.push( view ); 235 views.push( view );
237 } else { 236 } else {
238 return Err(DeepCrowError::parse( 237 return Err(CrimError::parse(
239 start_pos, 238 start_pos,
240 format!("Expected view at root, found {:?}", name ) 239 format!("Expected view at root, found {:?}", name )
241 )); 240 ));
@@ -244,28 +243,28 @@ impl Parser {
244 Ok(views) 243 Ok(views)
245 } 244 }
246 245
247 fn parse_tag<'a>(&self, ctx: &mut Context<'a>) -> Result<TagBuilder<'a>> { 246 fn parse_tag<'a>(&self, ctx: &mut Context<'a>) -> CrimResult<TagBuilder<'a>> {
248 let start_sym = ctx.cur().unwrap(); 247 let start_sym = ctx.cur().unwrap();
249 let mut tb = TagBuilder::new(&start_sym); 248 let mut tb = TagBuilder::new(&start_sym);
250 249
251 if ctx.next().is_some() { 250 if ctx.next().is_some() {
252 match ctx.cur().unwrap().symbol() { 251 match ctx.cur().unwrap().symbol() {
253 TokenType::View | TokenType::Show | TokenType::Loop | 252 SymbolType::View | SymbolType::Show | SymbolType::Loop |
254 TokenType::If | TokenType::ElIf | TokenType::Else | 253 SymbolType::If | SymbolType::ElIf | SymbolType::Else |
255 TokenType::Output => { 254 SymbolType::Output => {
256 let name_sym = ctx.cur().unwrap(); 255 let name_sym = ctx.cur().unwrap();
257 ctx.next(); 256 ctx.next();
258 tb.set_name( name_sym ); 257 tb.set_name( name_sym );
259 } 258 }
260 _ => { 259 _ => {
261 return Err(DeepCrowError::parse( 260 return Err(CrimError::parse(
262 *ctx.cur().unwrap().start(), 261 *ctx.cur().unwrap().start(),
263 "Unexpected symbol".to_string() 262 "Unexpected symbol".to_string()
264 )); 263 ));
265 } 264 }
266 } 265 }
267 } else { 266 } else {
268 return Err(DeepCrowError::eos("tag type")); 267 return Err(CrimError::eos("tag type"));
269 } 268 }
270 269
271 if tb.can_have_params() || tb.can_have_expr() { 270 if tb.can_have_params() || tb.can_have_expr() {
@@ -277,11 +276,11 @@ impl Parser {
277 276
278 if let Some(end_sym) = ctx.cur() { 277 if let Some(end_sym) = ctx.cur() {
279 match end_sym.symbol() { 278 match end_sym.symbol() {
280 TokenType::EndPoint | TokenType::EndFlat => { 279 SymbolType::EndPoint | SymbolType::EndFlat => {
281 tb.set_end( &end_sym )?; 280 tb.set_end( &end_sym )?;
282 } 281 }
283 _ => { 282 _ => {
284 return Err(DeepCrowError::parse( 283 return Err(CrimError::parse(
285 *end_sym.start(), 284 *end_sym.start(),
286 format!("Unexpected symbol {:?} looking for end of tag.", end_sym.symbol()) 285 format!("Unexpected symbol {:?} looking for end of tag.", end_sym.symbol())
287 )); 286 ));
@@ -294,21 +293,21 @@ impl Parser {
294 Ok(tb) 293 Ok(tb)
295 } 294 }
296 295
297 fn parse_tag_set<'a>(&self, ctx: &mut Context<'a>, mut base: TagBuilder<'a>) -> Result<TagBuilder<'a>> { 296 fn parse_tag_set<'a>(&self, ctx: &mut Context<'a>, mut base: TagBuilder<'a>) -> CrimResult<TagBuilder<'a>> {
298 if base.is_unary() { 297 if base.is_unary() {
299 return Ok(base); 298 return Ok(base);
300 } 299 }
301 300
302 loop { 301 loop {
303 if ctx.cur().is_none() { 302 if ctx.cur().is_none() {
304 return Err(DeepCrowError::eos(format!("close tag for {:?}", base.name()).as_str())); 303 return Err(CrimError::eos(format!("close tag for {:?}", base.name()).as_str()));
305 } 304 }
306 match ctx.cur().unwrap().symbol() { 305 match ctx.cur().unwrap().symbol() {
307 TokenType::Text(s) => { 306 SymbolType::Text(s) => {
308 base.add_child(Entry::Token(Token::Text(s.to_string()))); 307 base.add_child(Entry::Token(Token::Text(s.to_string())));
309 ctx.next(); 308 ctx.next();
310 } 309 }
311 TokenType::StartFlat | TokenType::StartPoint => { 310 SymbolType::StartFlat | SymbolType::StartPoint => {
312 let tb = self.parse_tag( ctx )?; 311 let tb = self.parse_tag( ctx )?;
313 312
314 match tb.tag_type() { 313 match tb.tag_type() {
@@ -320,13 +319,13 @@ impl Parser {
320 return Ok(base); 319 return Ok(base);
321 } 320 }
322 TagType::MultinaryClose => { 321 TagType::MultinaryClose => {
323 if (tb.is_name(&TokenType::If) && 322 if (tb.is_name(&SymbolType::If) &&
324 (base.is_name(&TokenType::ElIf) || 323 (base.is_name(&SymbolType::ElIf) ||
325 base.is_name(&TokenType::Else))) || 324 base.is_name(&SymbolType::Else))) ||
326 tb.is_name(base.name().unwrap().symbol()) { 325 tb.is_name(base.name().unwrap().symbol()) {
327 return Ok(base); 326 return Ok(base);
328 } else { 327 } else {
329 return Err(DeepCrowError::parse( 328 return Err(CrimError::parse(
330 *tb.name().unwrap().start(), 329 *tb.name().unwrap().start(),
331 format!("Found {:?} looking for close of {:?}", tb.name().unwrap().symbol(), base.name().unwrap().symbol()) 330 format!("Found {:?} looking for close of {:?}", tb.name().unwrap().symbol(), base.name().unwrap().symbol())
332 )); 331 ));
@@ -336,15 +335,15 @@ impl Parser {
336 base.add_child(Entry::TagBuilder(tb)); 335 base.add_child(Entry::TagBuilder(tb));
337 } 336 }
338 TagType::Unknown => { 337 TagType::Unknown => {
339 return Err(DeepCrowError::broken(base.start_pos(), "Found unknown tag when looking for something else.")); 338 return Err(CrimError::broken(base.start_pos(), "Found unknown tag when looking for something else."));
340 } 339 }
341 } 340 }
342 } 341 }
343 TokenType::Error{..} => { 342 SymbolType::Error{..} => {
344 return self.lex_error( &ctx.cur().unwrap() ); 343 return self.lex_error( &ctx.cur().unwrap() );
345 } 344 }
346 _ => { 345 _ => {
347 return Err(DeepCrowError::parse( 346 return Err(CrimError::parse(
348 *ctx.cur().unwrap().start(), 347 *ctx.cur().unwrap().start(),
349 format!("Unexpected token: {:?}", ctx.cur().unwrap().symbol()), 348 format!("Unexpected token: {:?}", ctx.cur().unwrap().symbol()),
350 )); 349 ));
@@ -353,18 +352,18 @@ impl Parser {
353 } 352 }
354 } 353 }
355 354
356 fn parse_tag_params(&self, ctx: &mut Context, tb: &mut TagBuilder ) -> Result<()> { 355 fn parse_tag_params(&self, ctx: &mut Context, tb: &mut TagBuilder ) -> CrimResult<()> {
357 loop { 356 loop {
358 if ctx.cur().is_none() { 357 if ctx.cur().is_none() {
359 return Err(DeepCrowError::eos("tag parameters")); 358 return Err(CrimError::eos("tag parameters"));
360 } 359 }
361 match ctx.cur().unwrap().symbol() { 360 match ctx.cur().unwrap().symbol() {
362 TokenType::Literal(s) => { 361 SymbolType::LiteralStr(s) => {
363 tb.add_param( ParamValue::Literal(s.to_string()) ); 362 tb.add_param( ParamValue::LiteralStr(s.to_string()) );
364 ctx.next(); 363 ctx.next();
365 } 364 }
366 TokenType::Identifier(_) | TokenType::Sharp => { 365 SymbolType::Token(_) | SymbolType::Sharp => {
367 if ctx.peek().is("tag data", |s| *s == TokenType::Equals)? { 366 if ctx.peek().is("tag data", |s| *s == SymbolType::Equals)? {
368 break; 367 break;
369 } 368 }
370 tb.add_param( self.parse_identifier( ctx )? ); 369 tb.add_param( self.parse_identifier( ctx )? );
@@ -377,23 +376,23 @@ impl Parser {
377 Ok(()) 376 Ok(())
378 } 377 }
379 378
380 fn parse_identifier(&self, ctx: &mut Context ) -> Result<ParamValue> { 379 fn parse_identifier(&self, ctx: &mut Context ) -> CrimResult<ParamValue> {
381 let mut id = Identifier::new(); 380 let mut id = Identifier::new();
382 381
383 if ctx.cur().is("identifier",|s| matches!( s, TokenType::Sharp))? { 382 if ctx.cur().is("identifier",|s| matches!( s, SymbolType::Sharp))? {
384 id.push( IdentifierValue::Root ); 383 id.push( IdentifierValue::Root );
385 ctx.next(); 384 ctx.next();
386 } 385 }
387 loop { 386 loop {
388 if ctx.cur().is("identifier",|s| matches!( s, TokenType::Identifier(_) ))? { 387 if ctx.cur().is("identifier",|s| matches!( s, SymbolType::Token(_) ))? {
389 if let TokenType::Identifier(s) = ctx.cur().unwrap().symbol() { 388 if let SymbolType::Token(s) = ctx.cur().unwrap().symbol() {
390 id.push( IdentifierValue::Name(s.to_string()) ); 389 id.push( IdentifierValue::Name(s.to_string()) );
391 } 390 }
392 } else { 391 } else {
393 return Err(DeepCrowError::parse( ctx.cur().unwrap().start().clone(), format!("Expeceted identifier, found {:?}", ctx.cur().unwrap().symbol() ) ) ); 392 return Err(CrimError::parse( ctx.cur().unwrap().start().clone(), format!("Expeceted identifier, found {:?}", ctx.cur().unwrap().symbol() ) ) );
394 } 393 }
395 394
396 if !ctx.next().is("identifier seperator",|s| *s == TokenType::Period )? { 395 if !ctx.next().is("identifier seperator",|s| *s == SymbolType::Period )? {
397 break; 396 break;
398 } 397 }
399 ctx.next(); 398 ctx.next();
@@ -402,19 +401,19 @@ impl Parser {
402 Ok(ParamValue::Identifier(id)) 401 Ok(ParamValue::Identifier(id))
403 } 402 }
404 403
405 fn parse_tag_props(&self, ctx: &mut Context, tb: &mut TagBuilder ) -> Result<()> { 404 fn parse_tag_props(&self, ctx: &mut Context, tb: &mut TagBuilder ) -> CrimResult<()> {
406 loop { 405 loop {
407 if ctx.cur().is_none() { 406 if ctx.cur().is_none() {
408 return Err(DeepCrowError::eos("tag properties")); 407 return Err(CrimError::eos("tag properties"));
409 } 408 }
410 if let TokenType::Identifier(s) = ctx.cur().unwrap().symbol() { 409 if let SymbolType::Token(s) = ctx.cur().unwrap().symbol() {
411 if ctx.peek().is_some_and(|s|s.check_type(|t| matches!(t,TokenType::Equals))) { 410 if ctx.peek().is_some_and(|s|s.check_type(|t| matches!(t,SymbolType::Equals))) {
412 ctx.next(); 411 ctx.next();
413 if let Some(sym) = ctx.next() && 412 if let Some(sym) = ctx.next() &&
414 let TokenType::Literal(lv) = sym.symbol() { 413 let SymbolType::LiteralStr(lv) = sym.symbol() {
415 tb.add_prop( s.to_string(), lv.to_string() ); 414 tb.add_prop( s.to_string(), lv.to_string() );
416 } else { 415 } else {
417 return Err(DeepCrowError::parse(Position::none(),"Expected quoted literal string".to_string())); 416 return Err(CrimError::parse(Position::none(),"Expected quoted literal string".to_string()));
418 } 417 }
419 } else { 418 } else {
420 break; 419 break;
@@ -447,15 +446,15 @@ type EntryList<'a> = Vec<Entry<'a>>;
447 446
448trait EntryListConverter { 447trait EntryListConverter {
449 fn has_outputs(&self) -> bool; 448 fn has_outputs(&self) -> bool;
450 fn to_outputs(&mut self, ctx: &mut Context ) -> Result<Vec<Output>>; 449 fn to_outputs(&mut self, ctx: &mut Context ) -> CrimResult<Vec<Output>>;
451 fn to_tokens(&mut self, ctx: &mut Context) -> Result<Vec<Token>>; 450 fn to_tokens(&mut self, ctx: &mut Context) -> CrimResult<Vec<Token>>;
452} 451}
453 452
454impl<'a> EntryListConverter for EntryList<'a> { 453impl<'a> EntryListConverter for EntryList<'a> {
455 fn has_outputs(&self) -> bool { 454 fn has_outputs(&self) -> bool {
456 self.iter().any(|e| 455 self.iter().any(|e|
457 if let Entry::TagBuilder(tb) = e 456 if let Entry::TagBuilder(tb) = e
458 && tb.is_name(&TokenType::Output) { 457 && tb.is_name(&SymbolType::Output) {
459 true 458 true
460 } else { 459 } else {
461 false 460 false
@@ -463,7 +462,7 @@ impl<'a> EntryListConverter for EntryList<'a> {
463 ) 462 )
464 } 463 }
465 464
466 fn to_outputs(&mut self, ctx: &mut Context) -> Result<Vec<Output>> { 465 fn to_outputs(&mut self, ctx: &mut Context) -> CrimResult<Vec<Output>> {
467 let mut outputs = Vec::new(); 466 let mut outputs = Vec::new();
468 467
469 if self.has_outputs() { 468 if self.has_outputs() {
@@ -489,7 +488,7 @@ impl<'a> EntryListConverter for EntryList<'a> {
489 Ok(outputs) 488 Ok(outputs)
490 } 489 }
491 490
492 fn to_tokens(&mut self, ctx: &mut Context) -> Result<Vec<Token>> { 491 fn to_tokens(&mut self, ctx: &mut Context) -> CrimResult<Vec<Token>> {
493 let mut tokens : Vec<Token> = Vec::new(); 492 let mut tokens : Vec<Token> = Vec::new();
494 for e in self.drain(..) { 493 for e in self.drain(..) {
495 match e { 494 match e {
@@ -500,7 +499,7 @@ impl<'a> EntryListConverter for EntryList<'a> {
500 if let BuildResult::Token(token) = tb.build(ctx)? { 499 if let BuildResult::Token(token) = tb.build(ctx)? {
501 tokens.push( token ); 500 tokens.push( token );
502 } else { 501 } else {
503 return Err(DeepCrowError::broken( Position::none(), "Non-token result built.")); 502 return Err(CrimError::broken( Position::none(), "Non-token result built."));
504 } 503 }
505 } 504 }
506 } 505 }
@@ -522,7 +521,7 @@ struct TagBuilder<'a> {
522 521
523#[derive(Debug)] 522#[derive(Debug)]
524enum ParamValue { 523enum ParamValue {
525 Literal(String), 524 LiteralStr(String),
526 Identifier(Identifier), 525 Identifier(Identifier),
527} 526}
528 527
@@ -545,25 +544,25 @@ impl<'a> TagBuilder<'a> {
545 } 544 }
546 } 545 }
547 546
548 pub fn set_end(&mut self, end: &Symbol) -> Result<()> { 547 pub fn set_end(&mut self, end: &Symbol) -> CrimResult<()> {
549 if *self.start.symbol() == TokenType::StartFlat { 548 if *self.start.symbol() == SymbolType::StartFlat {
550 if *end.symbol() == TokenType::EndFlat { 549 if *end.symbol() == SymbolType::EndFlat {
551 self.tag_type = TagType::Unary; 550 self.tag_type = TagType::Unary;
552 } else if *end.symbol() == TokenType::EndPoint { 551 } else if *end.symbol() == SymbolType::EndPoint {
553 self.tag_type = TagType::MultinaryOpen; 552 self.tag_type = TagType::MultinaryOpen;
554 } else { 553 } else {
555 return Err(DeepCrowError::broken( *end.start(), "Invalid bracket token type.")); 554 return Err(CrimError::broken( *end.start(), "Invalid bracket token type."));
556 } 555 }
557 } else if *self.start.symbol() == TokenType::StartPoint { 556 } else if *self.start.symbol() == SymbolType::StartPoint {
558 if *end.symbol() == TokenType::EndFlat { 557 if *end.symbol() == SymbolType::EndFlat {
559 self.tag_type = TagType::MultinaryClose; 558 self.tag_type = TagType::MultinaryClose;
560 } else if *end.symbol() == TokenType::EndPoint { 559 } else if *end.symbol() == SymbolType::EndPoint {
561 self.tag_type = TagType::MultinaryMid; 560 self.tag_type = TagType::MultinaryMid;
562 } else { 561 } else {
563 return Err(DeepCrowError::broken( *end.start(), "Invalid bracket token type.")); 562 return Err(CrimError::broken( *end.start(), "Invalid bracket token type."));
564 } 563 }
565 } else { 564 } else {
566 return Err(DeepCrowError::broken( *self.start.start(), "Invalid bracket token type.")); 565 return Err(CrimError::broken( *self.start.start(), "Invalid bracket token type."));
567 } 566 }
568 Ok(()) 567 Ok(())
569 } 568 }
@@ -582,18 +581,18 @@ impl<'a> TagBuilder<'a> {
582*/ 581*/
583 pub fn can_have_params(&self) -> bool { 582 pub fn can_have_params(&self) -> bool {
584 match self.name.unwrap().symbol() { 583 match self.name.unwrap().symbol() {
585 TokenType::View | TokenType::Output | TokenType::Loop => true, 584 SymbolType::View | SymbolType::Output | SymbolType::Loop => true,
586 TokenType::Show | TokenType::If | TokenType::ElIf | 585 SymbolType::Show | SymbolType::If | SymbolType::ElIf |
587 TokenType::Else => false, 586 SymbolType::Else => false,
588 _ => false, 587 _ => false,
589 } 588 }
590 } 589 }
591 590
592 pub fn can_have_expr(&self) -> bool { 591 pub fn can_have_expr(&self) -> bool {
593 match self.name.unwrap().symbol() { 592 match self.name.unwrap().symbol() {
594 TokenType::View | TokenType::Output | TokenType::Loop => false, 593 SymbolType::View | SymbolType::Output | SymbolType::Loop => false,
595 TokenType::Show | TokenType::If | TokenType::ElIf | 594 SymbolType::Show | SymbolType::If | SymbolType::ElIf |
596 TokenType::Else => true, 595 SymbolType::Else => true,
597 _ => false, 596 _ => false,
598 } 597 }
599 } 598 }
@@ -611,7 +610,7 @@ impl<'a> TagBuilder<'a> {
611 } 610 }
612 } 611 }
613*/ 612*/
614 pub fn is_name(&self, name: &TokenType<'a>) -> bool { 613 pub fn is_name(&self, name: &SymbolType<'a>) -> bool {
615 if let Some(a) = self.name { 614 if let Some(a) = self.name {
616 a.symbol() == name 615 a.symbol() == name
617 } else { 616 } else {
@@ -659,14 +658,14 @@ impl<'a> TagBuilder<'a> {
659 self.tag_type 658 self.tag_type
660 } 659 }
661 660
662 pub fn build(mut self, ctx: &mut Context ) -> Result<BuildResult> { 661 pub fn build(mut self, ctx: &mut Context ) -> CrimResult<BuildResult> {
663 if let Some(sym) = self.name { 662 if let Some(sym) = self.name {
664 match sym.symbol() { 663 match sym.symbol() {
665 TokenType::View => { 664 SymbolType::View => {
666 let name = if let ParamValue::Literal(s) = self.params.swap_remove(0) { 665 let name = if let ParamValue::LiteralStr(s) = self.params.swap_remove(0) {
667 s.to_string() 666 s.to_string()
668 } else { 667 } else {
669 return Err(DeepCrowError::parse(Position::none(), "Expected string literal for view name.".to_string())); 668 return Err(CrimError::parse(Position::none(), "Expected string literal for view name.".to_string()));
670 }; 669 };
671 Ok(BuildResult::View(View { 670 Ok(BuildResult::View(View {
672 name: name, 671 name: name,
@@ -676,23 +675,23 @@ impl<'a> TagBuilder<'a> {
676 layout: self.props.get("layout").cloned(), 675 layout: self.props.get("layout").cloned(),
677 })) 676 }))
678 } 677 }
679 TokenType::Output => { 678 SymbolType::Output => {
680 let name = if let ParamValue::Literal(s) = self.params.swap_remove(0) { 679 let name = if let ParamValue::LiteralStr(s) = self.params.swap_remove(0) {
681 s.to_string() 680 s.to_string()
682 } else { 681 } else {
683 return Err(DeepCrowError::parse(Position::none(), "Expected string literal for output name.".into())); 682 return Err(CrimError::parse(Position::none(), "Expected string literal for output name.".into()));
684 }; 683 };
685 Ok(BuildResult::Output(Output { 684 Ok(BuildResult::Output(Output {
686 name: name, 685 name: name,
687 code: self.children.to_tokens(ctx)?, 686 code: self.children.to_tokens(ctx)?,
688 })) 687 }))
689 } 688 }
690 TokenType::Loop => { 689 SymbolType::Loop => {
691 let id = if let ParamValue::Identifier(id) 690 let id = if let ParamValue::Identifier(id)
692 = self.params.swap_remove(0) { 691 = self.params.swap_remove(0) {
693 id 692 id
694 } else { 693 } else {
695 return Err(DeepCrowError::parse( 694 return Err(CrimError::parse(
696 Position::none(), 695 Position::none(),
697 "Identifier for loop variable name.".into()) 696 "Identifier for loop variable name.".into())
698 ); 697 );
@@ -701,24 +700,24 @@ impl<'a> TagBuilder<'a> {
701 Token::Loop(id, self.children.to_tokens(ctx)?) 700 Token::Loop(id, self.children.to_tokens(ctx)?)
702 )) 701 ))
703 } 702 }
704 TokenType::Show => { 703 SymbolType::Show => {
705 let id = if let ParamValue::Identifier(id) 704 let id = if let ParamValue::Identifier(id)
706 = self.params.swap_remove(0) { 705 = self.params.swap_remove(0) {
707 id 706 id
708 } else { 707 } else {
709 return Err(DeepCrowError::parse( 708 return Err(CrimError::parse(
710 Position::none(), 709 Position::none(),
711 "Identifier for show variable name.".into()) 710 "Identifier for show variable name.".into())
712 ); 711 );
713 }; 712 };
714 Ok(BuildResult::Token(Token::Show(id, self.props))) 713 Ok(BuildResult::Token(Token::Show(id, self.props)))
715 } 714 }
716 TokenType::If => { 715 SymbolType::If => {
717 let id = if let ParamValue::Identifier(id) 716 let id = if let ParamValue::Identifier(id)
718 = self.params.swap_remove(0) { 717 = self.params.swap_remove(0) {
719 id 718 id
720 } else { 719 } else {
721 return Err(DeepCrowError::parse( 720 return Err(CrimError::parse(
722 Position::none(), 721 Position::none(),
723 "Identifier for if variable name.".into()) 722 "Identifier for if variable name.".into())
724 ); 723 );
@@ -726,7 +725,7 @@ impl<'a> TagBuilder<'a> {
726 725
727 let is_else = if self.chain.len() == 1 && 726 let is_else = if self.chain.len() == 1 &&
728 let Entry::TagBuilder(tb) = &self.chain[0] && 727 let Entry::TagBuilder(tb) = &self.chain[0] &&
729 tb.is_name(&TokenType::Else) && 728 tb.is_name(&SymbolType::Else) &&
730 tb.params.len() == 0 { 729 tb.params.len() == 0 {
731 true 730 true
732 } else { 731 } else {
@@ -740,11 +739,11 @@ impl<'a> TagBuilder<'a> {
740 } 739 }
741 Ok(BuildResult::Token(Token::If(id, self.children.to_tokens(ctx)?, self.chain.to_tokens(ctx)?))) 740 Ok(BuildResult::Token(Token::If(id, self.children.to_tokens(ctx)?, self.chain.to_tokens(ctx)?)))
742 } 741 }
743 TokenType::ElIf => { 742 SymbolType::ElIf => {
744 let id = if let ParamValue::Identifier(id) = self.params.swap_remove(0) { 743 let id = if let ParamValue::Identifier(id) = self.params.swap_remove(0) {
745 id 744 id
746 } else { 745 } else {
747 return Err(DeepCrowError::parse( 746 return Err(CrimError::parse(
748 Position::none(), 747 Position::none(),
749 "Identifier for elif variable name.".into()) 748 "Identifier for elif variable name.".into())
750 ); 749 );
@@ -755,7 +754,7 @@ impl<'a> TagBuilder<'a> {
755 // ...but I can't do that right now. 754 // ...but I can't do that right now.
756 let is_else = if self.chain.len() == 1 && 755 let is_else = if self.chain.len() == 1 &&
757 let Entry::TagBuilder(tb) = &self.chain[0] && 756 let Entry::TagBuilder(tb) = &self.chain[0] &&
758 tb.is_name(&TokenType::Else) && 757 tb.is_name(&SymbolType::Else) &&
759 tb.params.len() == 0 { 758 tb.params.len() == 0 {
760 true 759 true
761 } else { 760 } else {
@@ -771,15 +770,15 @@ impl<'a> TagBuilder<'a> {
771 770
772 Ok(BuildResult::Token(Token::If(id, self.children.to_tokens(ctx)?, self.chain.to_tokens(ctx)?))) 771 Ok(BuildResult::Token(Token::If(id, self.children.to_tokens(ctx)?, self.chain.to_tokens(ctx)?)))
773 } 772 }
774 TokenType::Else => { 773 SymbolType::Else => {
775 Ok(BuildResult::Token(Token::If(Identifier::new(), self.children.to_tokens(ctx)?, self.chain.to_tokens(ctx)?))) 774 Ok(BuildResult::Token(Token::If(Identifier::new(), self.children.to_tokens(ctx)?, self.chain.to_tokens(ctx)?)))
776 } 775 }
777 _ => { 776 _ => {
778 Err(DeepCrowError::parse( self.start_pos(), "Bad tag type".into())) 777 Err(CrimError::parse( self.start_pos(), "Bad tag type".into()))
779 } 778 }
780 } 779 }
781 } else { 780 } else {
782 Err(DeepCrowError::parse(self.start_pos(), "Bad tag type".into())) 781 Err(CrimError::parse(self.start_pos(), "Bad tag type".into()))
783 } 782 }
784 } 783 }
785} 784}