Debian Codegraph @

src/lexer.rs

raw symbols SCIP
1 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
2 pub(craterust-analyzer cargo doxygen-rs 0.4.2 crate/) enum LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem# {
3 Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
4 Parenrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Paren#(char),
5 Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
6 Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
7 NewLinerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#NewLine#,
8 }
9
10 pub(craterust-analyzer cargo doxygen-rs 0.4.2 crate/) fn lexrust-analyzer cargo doxygen-rs 0.4.2 lexer/lex().(input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#> {
11 let mut result = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
12
13 for c in input.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() {
14 match c {
15 '@' => {
16 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#(c.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()));
17 }
18 '\\' => {
19 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = result.last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() {
20 match value {
21 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#(v) => {
22 if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&mut A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&mut A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&mut A`][`PartialEq<&B>`]eq()."\\" {
23 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()."\\"
24 } else {
25 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#(c.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
26 }
27 }
28 _ => result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#(c.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())),
29 }
30 } else {
31 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#(c.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()));
32 }
33 }
34 '{' | '}' => {
35 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Parenrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Paren#(c));
36 }
37 ' ' => {
38 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = result.last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() {
39 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(v, LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#) {
40 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#);
41 }
42 }
43 }
44 '\n' => {
45 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::NewLinerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#NewLine#);
46 }
47 _ => {
48 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = result.last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() {
49 match v {
50 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#(v) => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&c.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
51 _ => result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<char>`]from().(c))),
52 }
53 } else {
54 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<char>`]from().(c)))
55 }
56 }
57 }
58 }
59
60 result
61 }
62
63 #[cfg(test)]
64 mod testrust-analyzer cargo doxygen-rs 0.4.2 lexer/test/ {
65 use superrust-analyzer cargo doxygen-rs 0.4.2 lexer/::*;
66
67 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
68 fn basic_notationrust-analyzer cargo doxygen-rs 0.4.2 lexer/test/basic_notation().() {
69 let result = lexrust-analyzer cargo doxygen-rs 0.4.2 lexer/lex().("@name Memory Management".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
71 result,
72 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
73 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#("@".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
74 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("name".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
75 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
76 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Memory".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
77 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
78 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Management".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
79 ]
80 );
81
82 let result = lexrust-analyzer cargo doxygen-rs 0.4.2 lexer/lex().("\\name Memory Management".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
83 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
84 result,
85 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
86 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#("\\".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
87 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("name".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
88 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
89 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Memory".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
90 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
91 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Management".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
92 ]
93 );
94
95 let result = lexrust-analyzer cargo doxygen-rs 0.4.2 lexer/lex().("\\\\name Memory Management".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
96 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
97 result,
98 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
99 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#("\\\\".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
100 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("name".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
101 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
102 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Memory".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
103 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
104 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Management".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
105 ]
106 );
107 }
108
109 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
110 fn basic_groupsrust-analyzer cargo doxygen-rs 0.4.2 lexer/test/basic_groups().() {
111 let result = lexrust-analyzer cargo doxygen-rs 0.4.2 lexer/lex().("@{\n* @name Memory Management\n@}".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
112 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
113 result,
114 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
115 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#("@".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
116 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Parenrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Paren#('{'),
117 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::NewLinerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#NewLine#,
118 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("*".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
119 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
120 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#("@".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
121 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("name".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
122 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
123 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Memory".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
124 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Spacerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Space#,
125 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Wordrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Word#("Management".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
126 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::NewLinerust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#NewLine#,
127 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Atrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#At#("@".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
128 LexItemrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#::Parenrust-analyzer cargo doxygen-rs 0.4.2 lexer/LexItem#Paren#('}')
129 ]
130 );
131 }
132 }