skyscraper 0.1.0

XPath for HTML web scraping
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
use crate::vecpointer::VecPointer;

/// Enum representing all possible symbols output by the lexer.
#[derive(Debug)]
#[derive(PartialEq)]
pub enum Symbol {
    /// The start of a new tag. Example: `<{{string}}`.
    StartTag(String),

    /// The start of an end tag. Example: `</{{string}}`.
    EndTag(String),

    /// End *and* close a tag. Example: `/>`.
    TagCloseAndEnd,

    /// End a tag. Example: `>`.
    TagClose,

    /// Assignment sign. Example: `=`.
    AssignmentSign,

    /// A quoted string literal. Contained string does not include quotes. Example: `"{{string}}"`.
    Literal(String),

    /// Text contained in tags.
    Text(String),

    /// An identifier written in a tag declaration.
    Identifier(String),

    /// Xml comments. Example: `<!--{{string}}-->`.
    Comment(String),
}

pub fn lex(text: &str) -> Result<Vec<Symbol>, &'static str> {
    let mut symbols: Vec<Symbol> = Vec::new();

    let chars = text.chars().collect();
    let mut pointer = VecPointer::new(chars);

    let mut has_open_tag = false;

    while let Some(c) = pointer.current() {
        if let Some(s) = is_comment(&mut pointer) {
            symbols.push(s);
        } else if let Some(s) = is_start_tag(&mut pointer) {
            has_open_tag = true;
            symbols.push(s);
        } else if let Some(s) = is_end_tag(&mut pointer) {
            has_open_tag = true;
            symbols.push(s);
        } else if let Some(s) = is_tag_close_and_end(&mut pointer) {
            has_open_tag = false;
            symbols.push(s);
        } else if let Some(s) = is_tag_close(&mut pointer) {
            has_open_tag = false;
            symbols.push(s);
        } else if let Some(s) = is_assignment_sign(&mut pointer) {
            symbols.push(s);
        } else if let Some(s) = is_literal(&mut pointer, has_open_tag) {
            symbols.push(s);
        } else if let Some(s) = is_identifier(&mut pointer, has_open_tag) {
            symbols.push(s);
        } else if let Some(s) = is_text(&mut pointer, has_open_tag) {
            symbols.push(s);
        } else {
            if !c.is_whitespace(){
                // Unknown symbol, move on ¯\_(ツ)_/¯
                eprintln!("Unknown symbol {}", c);
            }
            pointer.next();
        }
    }
    Ok(symbols)
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a StartTag [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// StartTag is defined as `<{{String}}`
/// 
/// Has additional checks to make sure it is not an end tag.
fn is_start_tag(pointer: &mut VecPointer<char>) -> Option<Symbol> {
    if let (Some('<'), Some(c2)) = (pointer.current(), pointer.peek()) {
        if c2 != '/' {
            let mut name: Vec<char> = Vec::new();
            loop {
                match pointer.next() {
                    Some(' ') | Some('>') | Some('/') => break,
                    Some(c) => {
                        name.push(c);
                    },
                    None => break,
                };
            }
            let name: String = name.into_iter().collect();
    
            return Some(Symbol::StartTag(name));
        }

        return None;
    }
    None
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to an EndTag [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// EndTag is defined as `</{{String}}`
fn is_end_tag(pointer: &mut VecPointer<char>) -> Option<Symbol> {
    if let (Some('<'), Some('/')) = (pointer.current(), pointer.peek()) {
        pointer.next(); // peeked before, move up now
        
        let mut name: Vec<char> = Vec::new();
        loop {
            match pointer.next() {
                Some(' ') | Some('>') => break,
                Some(c) => {
                    name.push(c);
                },
                None => break,
            };
        }
        let name: String = name.into_iter().collect();

        return Some(Symbol::EndTag(name));
    }
    None
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a Comment [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// Comment is defined as `<!--{{String}}-->`
fn is_comment(pointer: &mut VecPointer<char>) -> Option<Symbol> {
    if let (Some('<'), Some('!'), Some('-'), Some('-')) = (pointer.current(), pointer.peek(), pointer.peek_add(2), pointer.peek_add(3)) {
        pointer.next_add(3); // peeked before, move up now

        let mut text: Vec<char> = Vec::new();
        while let Some(c) = pointer.next() {
            if is_end_comment(pointer) {
                let name: String = text.into_iter().collect();
                return Some(Symbol::Comment(name));
            }
            text.push(c);
        }
    }
    None
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to the end of a Comment [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// This is a helper method not used directly in the lexer.
/// 
/// The end of a comment is defined as `-->`
fn is_end_comment(pointer: &mut VecPointer<char>) -> bool {
    if let (Some('-'), Some('-'), Some('>')) = (pointer.current(), pointer.peek(), pointer.peek_add(2)) {
        pointer.next_add(3); // peeked before, move up now; 2+1 to end after comment

        return true;
    }
    false
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a TagClose [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// TagClose is defined as `>`
fn is_tag_close(pointer: &mut VecPointer<char>) -> Option<Symbol> {
    if let Some('>') = pointer.current() {
        pointer.next(); // move up for later
        return Some(Symbol::TagClose);
    }
    None
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a TagCloseAndEnd [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// TagCloseAndEnd is defined as `/>`
fn is_tag_close_and_end(pointer: &mut VecPointer<char>) -> Option<Symbol> {
    if let (Some('/'), Some('>')) = (pointer.current(), pointer.peek()) {
        pointer.next_add(2); // move up for later
        return Some(Symbol::TagCloseAndEnd);
    }
    None
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a AssignmentSign [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// AssignmentSign is defined as `=`
fn is_assignment_sign(pointer: &mut VecPointer<char>) -> Option<Symbol> {
    if let Some('=') = pointer.current() {
        pointer.next(); // move up for later
        return Some(Symbol::AssignmentSign);
    }
    None
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a Literal [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// Literal is defined as `"{{String}}"` inside a tag definition.
fn is_literal(pointer: &mut VecPointer<char>, has_open_tag: bool) -> Option<Symbol> {
    if !has_open_tag {
        return None;
    }

    if let Some('"') = pointer.current() {         
        let mut text: Vec<char> = Vec::new();
        loop {
            match pointer.next() {
                Some('"') => break,
                Some(c) => {
                    text.push(c);
                },
                None => break,
            };
        }
        let name: String = text.into_iter().collect();

        pointer.next(); // skip over closing `"`

        return Some(Symbol::Literal(name));
    }
    None
}

lazy_static! {
    /// List of characters that end an Identifier [Symbol](Symbol).
    static ref INAVLID_ID_CHARS: Vec<char> = vec![' ', '<', '>', '/', '=', '"'];
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a Identifier [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// Identifier is defined as any text inside a tag definition.
fn is_identifier(pointer: &mut VecPointer<char>, has_open_tag: bool) -> Option<Symbol> {
    if !has_open_tag {
        return None;
    }

    if let Some(c) = pointer.current() {
        if !INAVLID_ID_CHARS.contains(&c) {
            let mut text: Vec<char> = vec![c];
            loop {
                match pointer.next() {
                    Some(c) if INAVLID_ID_CHARS.contains(&c) => break,
                    Some(c) => {
                        text.push(c);
                    },
                    None => break,
                };
            }
            let name: String = text.into_iter().collect();
    
            return Some(Symbol::Identifier(name));
        }
        return None;
    }
    None
}

lazy_static! {
    /// List of characters that end a Text [Symbol](Symbol).
    static ref INAVLID_TEXT_CHARS: Vec<char> = vec!['<', '>'];
}

/// Checks if the [TextPointer](TextPointer) is currently pointing to a Text [Symbol](Symbol).
/// If true it will move the text pointer to the next symbol, otherwise it will not change the pointer.
/// 
/// Text is defined as any text outside a tag definition.
fn is_text(pointer: &mut VecPointer<char>, has_open_tag: bool) -> Option<Symbol> {
    if has_open_tag {
        return None;
    }

    if let Some(c) = pointer.current() {
        if !INAVLID_TEXT_CHARS.contains(&c) {
            let start_index = pointer.index;
            let mut has_non_whitespace = false;

            let mut text: Vec<char> = vec![c];
            loop {
                match pointer.next() {
                    Some(c) if INAVLID_TEXT_CHARS.contains(&c) => break,
                    Some(c) => {
                        if !c.is_whitespace() {
                            has_non_whitespace = true;
                        }

                        text.push(c);
                    },
                    None => break,
                };
            }
            let name: String = text.into_iter().collect();
    
            if has_non_whitespace {
                return Some(Symbol::Text(name));
            } else {
                // roll back pointer
                pointer.index = start_index;
                return None;
            }
        }
        return None;
    }
    None
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn is_start_tag_finds_and_moves_pointer() {
        // arrange
        let chars = "<a>".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_start_tag(&mut pointer).unwrap();

        // assert
        assert_eq!(Symbol::StartTag(String::from("a")), result);
        assert_eq!(2, pointer.index);
    }

    #[test]
    fn is_start_tag_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_start_tag(&mut pointer);

        // assert
        assert!(matches!(result, None));
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_end_tag_works() {
        // arrange
        let chars = "</c>".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_end_tag(&mut pointer).unwrap();

        // assert
        assert_eq!(Symbol::EndTag(String::from("c")), result);
        assert_eq!(3, pointer.index);
    }

    #[test]
    fn is_end_tag_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_end_tag(&mut pointer);

        // assert
        assert!(matches!(result, None));
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_comment_works() {
        // arrange
        let chars = "<!--bean is-nice -->".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_comment(&mut pointer).unwrap();

        // assert
        assert_eq!(Symbol::Comment(String::from("bean is-nice ")), result);
        assert_eq!(20, pointer.index);
    }

    #[test]
    fn is_comment_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_comment(&mut pointer);

        // assert
        assert_eq!(None, result);
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_end_comment_works() {
        // arrange
        let chars = "-->".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_end_comment(&mut pointer);

        // assert
        assert_eq!(true, result);
        assert_eq!(3, pointer.index);
    }

    #[test]
    fn is_end_comment_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_end_comment(&mut pointer);

        // assert
        assert_eq!(false, result);
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_tag_close_works() {
        // arrange
        let chars = ">".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_tag_close(&mut pointer).unwrap();

        // assert
        assert_eq!(Symbol::TagClose, result);
        assert_eq!(1, pointer.index);
    }

    #[test]
    fn is_tag_close_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_tag_close(&mut pointer);

        // assert
        assert_eq!(None, result);
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_tag_close_and_end_works() {
        // arrange
        let chars = "/>".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_tag_close_and_end(&mut pointer).unwrap();

        // assert
        assert_eq!(Symbol::TagCloseAndEnd, result);
        assert_eq!(2, pointer.index);
    }

    #[test]
    fn is_tag_close_and_end_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_tag_close_and_end(&mut pointer);

        // assert
        assert_eq!(None, result);
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_assignment_sign_works() {
        // arrange
        let chars = "=".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_assignment_sign(&mut pointer).unwrap();

        // assert
        assert_eq!(Symbol::AssignmentSign, result);
        assert_eq!(1, pointer.index);
    }

    #[test]
    fn is_assignment_sign_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_assignment_sign(&mut pointer);

        // assert
        assert_eq!(None, result);
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_literal_works() {
        // arrange
        let chars = r###""yo""###.chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_literal(&mut pointer, true).unwrap();

        // assert
        assert_eq!(Symbol::Literal(String::from("yo")), result);
        assert_eq!(4, pointer.index);
    }

    #[test]
    fn is_literal_does_not_move_pointer_if_not_found() {
        // arrange
        let chars = "abcd".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_literal(&mut pointer, true);

        // assert
        assert!(matches!(result, None));
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_identifier_works() {
        // arrange
        let chars = "foo bar".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_identifier(&mut pointer, true).unwrap();

        // assert
        assert_eq!(Symbol::Identifier(String::from("foo")), result);
        assert_eq!(3, pointer.index);
    }

    #[test]
    fn is_identifier_not_move_pointer_if_not_found() {
        // arrange
        let chars = " ".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_identifier(&mut pointer, true);

        // assert
        assert!(matches!(result, None));
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn is_text_works() {
        // arrange
        let chars = "foo bar".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_text(&mut pointer, false).unwrap();

        // assert
        assert_eq!(Symbol::Text(String::from("foo bar")), result);
        assert_eq!(7, pointer.index);
    }

    #[test]
    fn is_text_not_move_pointer_if_not_found() {
        // arrange
        let chars = "<".chars().collect();
        let mut pointer = VecPointer::new(chars);

        // act
        let result = is_text(&mut pointer, false);

        // assert
        assert!(matches!(result, None));
        assert_eq!(0, pointer.index);
    }

    #[test]
    fn lex_works() {
        // arrange
        let text = "<start-tag id=\"bean\"><!--comment--><inner/>hello</end-tag>";

        // act
        let result = lex(text).unwrap();

        // assert
        let expected = vec![
            Symbol::StartTag(String::from("start-tag")),
            Symbol::Identifier(String::from("id")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("bean")),
            Symbol::TagClose,
            Symbol::Comment(String::from("comment")),
            Symbol::StartTag(String::from("inner")),
            Symbol::TagCloseAndEnd,
            Symbol::Text(String::from("hello")),
            Symbol::EndTag(String::from("end-tag")),
            Symbol::TagClose];

        assert_eq!(expected, result);
    }

    #[test]
    fn lex_should_work_with_html() {
        // arrange
        let html = r###"<!DOCTYPE html>
        <!-- saved from url=(0026)https://www.rust-lang.org/ -->
        <html lang="en-US">
            <head>
                <title>Rust Programming Language</title>
                <meta name="viewport" content="width=device-width,initial-scale=1.0">
        
                <!-- Twitter card -->
                <meta name="twitter:card" content="summary">
            </head>
            <body>
                <main>
                    <section id="language-values" class="green">
                        <div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
                            <header class="pb0">
                                <h2>
                                Why Rust?
                                </h2>
                            </header>
                            <div class="flex-none flex-l">
                                <section class="w-100 pv2 pv0-l mt4">
                                    <h3 class="f2 f1-l">Performance</h3>
                                    <p class="f3 lh-copy">
                                    Rust is blazingly fast and memory-efficient: with no runtime or
                                    garbage collector, it can power performance-critical services, run on
                                    embedded devices, and easily integrate with other languages.
                                    </p>
                                </section>
                            </div>
                        </div>
                    </section>
                </main>
                <script src="./Rust Programming Language_files/languages.js.download"/>
            </body>
        </html>"###;

        // act
        let result = lex(html).unwrap();

        // assert
        let expected = vec![
            Symbol::StartTag(String::from("!DOCTYPE")),
            Symbol::Identifier(String::from("html")),
            Symbol::TagClose,
            Symbol::Comment(String::from(" saved from url=(0026)https://www.rust-lang.org/ ")),
            Symbol::StartTag(String::from("html")),
            Symbol::Identifier(String::from("lang")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("en-US")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("head")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("title")),
            Symbol::TagClose,
            Symbol::Text(String::from("Rust Programming Language")),
            Symbol::EndTag(String::from("title")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("meta")),
            Symbol::Identifier(String::from("name")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("viewport")),
            Symbol::Identifier(String::from("content")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("width=device-width,initial-scale=1.0")),
            Symbol::TagClose,
            Symbol::Comment(String::from(" Twitter card ")),
            Symbol::StartTag(String::from("meta")),
            Symbol::Identifier(String::from("name")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("twitter:card")),
            Symbol::Identifier(String::from("content")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("summary")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("head")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("body")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("main")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("section")),
            Symbol::Identifier(String::from("id")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("language-values")),
            Symbol::Identifier(String::from("class")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("green")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("div")),
            Symbol::Identifier(String::from("class")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("w-100 mw-none ph3 mw8-m mw9-l center f3")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("header")),
            Symbol::Identifier(String::from("class")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("pb0")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("h2")),
            Symbol::TagClose,
            Symbol::Text(String::from(r#"
                                Why Rust?
                                "#)),
            Symbol::EndTag(String::from("h2")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("header")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("div")),
            Symbol::Identifier(String::from("class")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("flex-none flex-l")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("section")),
            Symbol::Identifier(String::from("class")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("w-100 pv2 pv0-l mt4")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("h3")),
            Symbol::Identifier(String::from("class")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("f2 f1-l")),
            Symbol::TagClose,
            Symbol::Text(String::from("Performance")),
            Symbol::EndTag(String::from("h3")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("p")),
            Symbol::Identifier(String::from("class")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("f3 lh-copy")),
            Symbol::TagClose,
            Symbol::Text(String::from(r#"
                                    Rust is blazingly fast and memory-efficient: with no runtime or
                                    garbage collector, it can power performance-critical services, run on
                                    embedded devices, and easily integrate with other languages.
                                    "#)),
            Symbol::EndTag(String::from("p")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("section")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("div")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("div")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("section")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("main")),
            Symbol::TagClose,
            Symbol::StartTag(String::from("script")),
            Symbol::Identifier(String::from("src")),
            Symbol::AssignmentSign,
            Symbol::Literal(String::from("./Rust Programming Language_files/languages.js.download")),
            Symbol::TagCloseAndEnd,
            Symbol::EndTag(String::from("body")),
            Symbol::TagClose,
            Symbol::EndTag(String::from("html")),
            Symbol::TagClose,
        ];
        
        // looping makes debugging much easier than just asserting the entire vectors are equal
        for (e, r) in expected.into_iter().zip(result) {
            assert_eq!(e, r);
        }
    }
}