Tree printing
This commit is contained in:
+13
-4
@@ -9,11 +9,13 @@ TokenType :: enum {
|
||||
Bold,
|
||||
BreakLine,
|
||||
Heading,
|
||||
Paragraph,
|
||||
}
|
||||
|
||||
TokenMode :: enum {
|
||||
Start,
|
||||
End,
|
||||
Modeless,
|
||||
}
|
||||
|
||||
TokenValue :: union {
|
||||
@@ -23,12 +25,13 @@ TokenValue :: union {
|
||||
}
|
||||
|
||||
Token :: struct {
|
||||
type: TokenType,
|
||||
value: TokenValue,
|
||||
child: [dynamic]Token,
|
||||
type: TokenType,
|
||||
value: TokenValue,
|
||||
children: [dynamic]Token,
|
||||
}
|
||||
|
||||
token_tree := [dynamic]Token{}
|
||||
current_token := &token_tree[0]
|
||||
|
||||
replace_text :: proc(text: string, start: int, len_: int, repl: string) -> string {
|
||||
builder := strings.builder_make(context.temp_allocator)
|
||||
@@ -54,14 +57,20 @@ parse_header :: proc(line: string) -> (int, string) {
|
||||
}
|
||||
|
||||
parse :: proc(lines: []string, allocator := context.allocator) -> [dynamic]Token {
|
||||
token_tree := [dynamic]Token{}
|
||||
append(&token_tree, Token{TokenType.Paragraph, TokenMode.Start, nil})
|
||||
current_token := &token_tree[0]
|
||||
|
||||
for untrimmed_line in lines {
|
||||
line := strings.trim_space(untrimmed_line)
|
||||
|
||||
if len(line) == 0 {
|
||||
append(&token_tree, Token{TokenType.BreakLine, TokenMode.Start, nil})
|
||||
append(¤t_token.children, Token{TokenType.BreakLine, TokenMode.Modeless, nil})
|
||||
continue
|
||||
}
|
||||
|
||||
append(¤t_token.children, Token{TokenType.Text, line, nil})
|
||||
|
||||
// lvl, text := parse_header(trimmed)
|
||||
// is_header := lvl > 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user