Odin rewrite #1
@@ -35,15 +35,6 @@ print_token :: proc(token: Token, depth: int) {
|
||||
value_str = v
|
||||
case int:
|
||||
value_str = fmt.aprintf("%d", v, allocator = context.temp_allocator)
|
||||
case TokenMode:
|
||||
switch v {
|
||||
case TokenMode.Start:
|
||||
value_str = "Start"
|
||||
case TokenMode.End:
|
||||
value_str = "End"
|
||||
case TokenMode.Modeless:
|
||||
value_str = "Modeless"
|
||||
}
|
||||
}
|
||||
|
||||
if value_str != "" {
|
||||
|
||||
+2
-9
@@ -12,16 +12,9 @@ TokenType :: enum {
|
||||
Paragraph,
|
||||
}
|
||||
|
||||
TokenMode :: enum {
|
||||
Start,
|
||||
End,
|
||||
Modeless,
|
||||
}
|
||||
|
||||
TokenValue :: union {
|
||||
string,
|
||||
int,
|
||||
TokenMode,
|
||||
}
|
||||
|
||||
Token :: struct {
|
||||
@@ -58,14 +51,14 @@ 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})
|
||||
append(&token_tree, Token{TokenType.Paragraph, nil, nil})
|
||||
current_token := &token_tree[0]
|
||||
|
||||
for untrimmed_line in lines {
|
||||
line := strings.trim_space(untrimmed_line)
|
||||
|
||||
if len(line) == 0 {
|
||||
append(¤t_token.children, Token{TokenType.BreakLine, TokenMode.Modeless, nil})
|
||||
append(¤t_token.children, Token{TokenType.BreakLine, nil, nil})
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user