Token_Type_Symbol,
Token_Type_Literal_String,
+ Token_Type_Literal_Char,
Token_Type_Literal_Integer,
Token_Type_Literal_Float,
Token_Type_Literal_True,
"TOKEN_TYPE_SYMBOL",
"TOKEN_TYPE_LITERAL_STRING",
+ "TOKEN_TYPE_LITERAL_CHAR",
"TOKEN_TYPE_LITERAL_INTEGER",
"TOKEN_TYPE_LITERAL_FLOAT",
"true",
goto token_parsed;
}
- // String literal
- if (*tk.text == '"') {
+ // String/Character literal
+ if (*tk.text == '"' || *tk.text == '\'') {
u64 len = 0;
u64 slash_count = 0;
+ char ch = *tk.text;
INCREMENT_CURR_TOKEN(tokenizer);
- while (!(*tokenizer->curr == '"' && slash_count == 0)) {
+ while (!(*tokenizer->curr == ch && slash_count == 0)) {
len++;
// if (*tokenizer->curr == '\n') {
INCREMENT_CURR_TOKEN(tokenizer);
tk.text++;
- tk.type = Token_Type_Literal_String;
+ tk.type = ch == '"' ? Token_Type_Literal_String : Token_Type_Literal_Char;
tk.length = len;
goto token_parsed;
}
break;
}
+ case Token_Type_Literal_Char: {
+ AstNumLit* char_lit = make_node(AstNumLit, Ast_Kind_NumLit);
+ char_lit->flags |= Ast_Flag_Comptime;
+ char_lit->type_node = (AstType *) &basic_type_int_unsized;
+ char_lit->token = expect_token(parser, Token_Type_Literal_Char);
+ char_lit->was_char_literal = 1;
+
+ i8 dest = '\0';
+ i32 length = string_process_escape_seqs((char *) &dest, char_lit->token->text, 1);
+ char_lit->value.i = (u32) dest;
+
+ if (length != 1) {
+ onyx_report_error(char_lit->token->pos, Error_Critical, "Expected only a single character in character literal.");
+ }
+
+ retval = (AstTyped *) char_lit;
+ break;
+ }
+
case '#': {
if (parse_possible_directive(parser, "file_contents")) {
AstFileContents* fc = make_node(AstFileContents, Ast_Kind_File_Contents);
while (peek_token(token_offset)->type == Token_Type_Symbol) {
token_offset += 1;
- if (peek_token(token_offset)->type == '\'') token_offset += 1;
+ if (peek_token(token_offset)->type == '~') token_offset += 1;
if (peek_token(token_offset)->type != ',') break;
token_offset += 1;
AstNode* sym_node = make_symbol(parser->allocator, local_sym);
bh_arr_push(local_compound->exprs, (AstTyped *) sym_node);
- if (!consume_token_if_next(parser, '\'')) {
+ if (!consume_token_if_next(parser, '~')) {
AstLocal* new_local = make_local(parser->allocator, local_sym, NULL);
if (prev_local == NULL) {
first_local = new_local;
// If the token after the symbol is a comma, assume this is a compound declaration.
if (peek_token(1)->type == ',' ||
- (peek_token(1)->type == '\'' && peek_token(2)->type == ',')) {
+ (peek_token(1)->type == '~' && peek_token(2)->type == ',')) {
return parse_possible_compound_symbol_declaration(parser, ret);
}
case u8 {
value := *(cast(&u8) v.data);
- if value > 31 {
+ if formatting.interpret_numbers {
output->write(value);
} else {
// Used by dyn_str
//
+to_dyn_str :: (x: str, allocator := context.allocator) -> dyn_str {
+ return (package core.array).make(x, allocator);
+}
+
delete :: macro (x: &dyn_str, idx: u32) -> u8 {
return (package core.array).delete(x, idx);
}
@conv.Custom_Parse_Proc.{ Date }
(d: &Date, text: str, _: Allocator) -> bool {
year, t := string.bisect(text, #char "-");
- month, t' := string.bisect(t, #char "-");
- day, t' := string.bisect(t, #char "-");
+ month, t~ := string.bisect(t, #char "-");
+ day, t~ := string.bisect(t, #char "-");
d.year = ~~ conv.str_to_i64(year);
d.month = ~~ (conv.str_to_i64(month) - 1);
// You're trying to declare a new variable k, while using the old variable
// s in the same declaration. To get around this issue, there is a special
// syntax you can use that tell the compiler that s is a not a new
- // variable, but the same one as above. You simple place a ' after the
+ // variable, but the same one as above. You simple place a ~ after the
// variable that you want to reuse.
- k, s' := multiple_returns();
+ k, s~ := multiple_returns();
printf("k: {}\ns: {}\n\n", k, s);
//
;; Strings
("\\\".*\\\"" . font-lock-string-face)
+ ("\\\'.*\\\'" . font-lock-string-face)
+
;; Numbers
(,(onyx-wrap-word-rx onyx-number-rx) . font-lock-constant-face)
- match: '"'
scope: punctuation.definition.string.begin.onyx
push: double_quoted_string
+ - match: "'"
+ scope: punctuation.definition.string.begin.onyx
+ push: single_quoted_string
# Comments begin with a '//' and finish at the end of the line
- match: '//'
# 1: variable
# 2: variable
+ single_quoted_string:
+ - meta_scope: string.quoted.single.onyx
+ - match: '\\.'
+ scope: constant.character.escape.onyx
+ - match: "'"
+ scope: punctuation.definition.string.end.onyx
+ pop: true
+
double_quoted_string:
- meta_scope: string.quoted.double.onyx
- match: '\\.'
syn match onyxTag "@[a-zA-Z0-9_]\+"
syn region onyxString start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ extend contains=@Spell
+syn region onyxString start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ extend contains=@Spell
syn region onyxMultiString start=+"""+ end=+"""+ extend contains=@Spell
hi def link onyxKeyword Statement
gos.height = 0;
while !string.empty(file) {
- line, file' := string.bisect(file, #char "\n");
+ line, file~ := string.bisect(file, #char "\n");
for ch: line do switch ch {
case #char "." do array.push(&gos.seats, SeatState.Floor);
case #char "L" do array.push(&gos.seats, SeatState.Empty);
string.advance(&file, 3);
i := 35;
- m, file' := string.bisect(file, #char "\n");
+ m, file~ := string.bisect(file, #char "\n");
for ch: m {
switch ch {
case #char "0" do mask[i] = 0;
z := 0;
while !string.empty(file) {
- line, file' := string.bisect(file, #char "\n");
+ line, file~ := string.bisect(file, #char "\n");
x := 0;
for ch: line {
valid_count := 0;
string.advance_line(&file);
while !string.empty(file) {
- line, file' := string.bisect(file, #char "\n");
+ line, file~ := string.bisect(file, #char "\n");
if cyk_algorithm(&grammar, line) do valid_count += 1;
}
td := cast(&bool) raw_alloc(tile_allocator, sizeof TileData);
for y: 0 .. 10 {
- line, file' := string.bisect(file, #char "\n");
+ line, file~ := string.bisect(file, #char "\n");
for x: 0 .. 10 {
td[x + y * TILE_DATA_WIDTH] = (line[x] == #char "#");
--- /dev/null
+az
+r is the 17 of the alphabet.
+
+Something else
--- /dev/null
+use core
+
+
+main :: () {
+ s: dyn_str;
+ defer string.free(&s);
+
+ string.append(&s, .['a', 'z']);
+
+ println(s);
+
+
+
+ x := 'r' - 'a';
+ printf("{} is the {} of the alphabet.\n", 'r', x);
+
+ a_newline := '\n';
+ printf("{}", a_newline);
+ println("Something else");
+}
\ No newline at end of file