Skip to content

Commit

Permalink
Merge pull request #8 from chrhansk/feature-char-literals
Browse files Browse the repository at this point in the history
Add support for char literals
  • Loading branch information
b0o authored Nov 24, 2024
2 parents 9a65e15 + f58c024 commit 5f7a61d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum {
Format = 1 << 4,
Triple = 1 << 5,
Bytes = 1 << 6,
Char = 1 << 7,
} Flags;

typedef struct {
Expand All @@ -45,6 +46,10 @@ static inline bool is_raw(Delimiter *delimiter) {
return delimiter->flags & Raw;
}

static inline bool is_char(Delimiter *delimiter) {
return delimiter->flags & Char;
}

static inline bool is_triple(Delimiter *delimiter) {
return delimiter->flags & Triple;
}
Expand Down Expand Up @@ -72,6 +77,8 @@ static inline void set_format(Delimiter *delimiter) {

static inline void set_raw(Delimiter *delimiter) { delimiter->flags |= Raw; }

static inline void set_char(Delimiter *delimiter) { delimiter->flags |= Char; }

static inline void set_triple(Delimiter *delimiter) {
delimiter->flags |= Triple;
}
Expand Down Expand Up @@ -336,6 +343,8 @@ bool tree_sitter_cython_external_scanner_scan(void *payload, TSLexer *lexer,
set_format(&delimiter);
} else if (lexer->lookahead == 'r' || lexer->lookahead == 'R') {
set_raw(&delimiter);
} else if (lexer->lookahead == 'c'){
set_char(&delimiter);
} else if (lexer->lookahead == 'b' || lexer->lookahead == 'B') {
set_bytes(&delimiter);
} else if (lexer->lookahead != 'u' && lexer->lookahead != 'U') {
Expand Down
17 changes: 17 additions & 0 deletions test/corpus/cython.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1170,3 +1170,20 @@ def func(x: "cython.int"):
(string_end))))
(block
(pass_statement))))
=====================================
Char literals
=====================================
c"literal"
c'literal'
---
(module
(expression_statement
(string
(string_start)
(string_content)
(string_end)))
(expression_statement
(string
(string_start)
(string_content)
(string_end))))

0 comments on commit 5f7a61d

Please sign in to comment.