package core:c/frontend/tokenizer
⌘K
Ctrl+K
or
/
Overview
Example:
package demo
import tokenizer "core:c/frontend/tokenizer"
import preprocessor "core:c/frontend/preprocessor"
import "core:fmt"
main :: proc() {
t := &tokenizer.Tokenizer{};
tokenizer.init_defaults(t);
cpp := &preprocessor.Preprocessor{};
cpp.warn, cpp.err = t.warn, t.err;
preprocessor.init_lookup_tables(cpp);
preprocessor.init_default_macros(cpp);
cpp.include_paths = {"my/path/to/include"};
tok := tokenizer.tokenize_file(t, "the/source/file.c", 1);
tok = preprocessor.preprocess(cpp, tok);
if tok != nil {
for t := tok; t.kind != .EOF; t = t.next {
fmt.println(t.lit);
}
}
fmt.println("[Done]");
}
Index
Constants (0)
This section is empty.
Variables (2)
Procedures (41)
- add_hide_set
- add_new_file
- advance_rune
- advance_rune_n
- allow_next_to_be_newline
- char_width
- copy_token
- default_error_handler
- default_is_keyword
- default_warn_handler
- digit_val
- display_width
- error
- error_offset
- hide_set_contains
- hide_set_intersection
- hide_set_union
- in_range
- init_defaults
- inline_tokenize
- is_digit
- is_ident0
- is_ident1
- new_eof
- new_hide_set
- peek
- peek_str
- scan
- scan_comment
- scan_escape
- scan_identifier
- scan_literal_prefix
- scan_number
- scan_punct
- scan_rune
- scan_string
- skip_whitespace
- tokenize
- tokenize_file
- warn
- warn_offset
Procedure Groups (0)
This section is empty.
Types
Error_Handler ¶
Related Procedures With Parameters
Pos ¶
Related Procedures With Parameters
Token ¶
Token :: struct { kind: Token_Kind, next: ^Token, lit: string, pos: Pos, file: ^File, line_delta: int, at_bol: bool, has_space: bool, type_hint: Token_Type_Hint, val: Token_Value, prefix: string, // Preprocessor values hide_set: ^Hide_Set, origin: ^Token, }
Related Procedures With Parameters
Related Procedures With Returns
Token_Kind ¶
Token_Kind :: enum int { Invalid, Ident, Punct, Keyword, Char, String, Number, PP_Number, Comment, EOF, }
Related Procedures With Returns
Token_Type_Hint ¶
Token_Type_Hint :: enum u8 { None, Int, Long, Long_Long, Unsigned_Int, Unsigned_Long, Unsigned_Long_Long, Float, Double, Long_Double, UTF_8, UTF_16, UTF_32, UTF_Wide, }
Tokenizer ¶
Tokenizer :: struct { // Immutable data path: string, src: []u8, // Tokenizing state ch: rune, offset: int, read_offset: int, line_offset: int, line_count: int, // Extra information for tokens at_bol: bool, has_space: bool, // Mutable data err: Error_Handler, warn: Error_Handler, error_count: int, warning_count: int, }
Related Procedures With Parameters
Constants
This section is empty.
Variables
token_name ¶
token_name: [Token_Kind]string = …
Procedures
advance_rune ¶
advance_rune :: proc(t: ^Tokenizer) {…}
char_width ¶
Returns the number of columns needed to display a given character in a fixed-width font. Based on https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
init_defaults ¶
init_defaults :: proc(t: ^Tokenizer, err: Error_Handler = default_error_handler, warn: Error_Handler = default_warn_handler) {…}
is_ident0 ¶
[https://www.sigbus.info/n1570#D] C11 allows ASCII and some multibyte characters in certan Unicode ranges to be used in an identifier.
is_ident0 returns true if a given character is acceptable as the first character of an identifier.
is_ident1 ¶
is_ident0 returns true if a given character is acceptable as a non-first character of an identifier.
scan_number ¶
scan_number :: proc(t: ^Tokenizer, seen_decimal_point: bool) -> (Token_Kind, string) {…}
scan_punct ¶
scan_punct :: proc(t: ^Tokenizer, ch: rune) -> (kind: Token_Kind) {…}
skip_whitespace ¶
skip_whitespace :: proc(t: ^Tokenizer) {…}
tokenize_file ¶
tokenize_file :: proc(t: ^Tokenizer, path: string, id: int, loc := #caller_location) -> ^Token {…}
Procedure Groups
This section is empty.
Source Files
Generation Information
Generated with odin version dev-2024-11 (vendor "odin") Windows_amd64 @ 2024-11-16 21:10:09.760575800 +0000 UTC