mirror of
https://github.com/emersion/kanshi
synced 2024-09-18 09:51:36 +02:00
parser: support single quotation marks
See https://github.com/emersion/kanshi/pull/96 Includes a simplification suggested by: Co-authored-by: Érico Nogueira Rolim <34201958+ericonr@users.noreply.github.com>
This commit is contained in:
parent
a3061857d6
commit
fd565f4415
8
parser.c
8
parser.c
@ -70,7 +70,7 @@ static bool parser_append_tok_ch(struct kanshi_parser *parser, char ch) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parser_read_quoted(struct kanshi_parser *parser) {
|
static bool parser_read_quoted(struct kanshi_parser *parser, char quote_char) {
|
||||||
while (1) {
|
while (1) {
|
||||||
int ch = parser_read_char(parser);
|
int ch = parser_read_char(parser);
|
||||||
if (ch < 0) {
|
if (ch < 0) {
|
||||||
@ -80,7 +80,7 @@ static bool parser_read_quoted(struct kanshi_parser *parser) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch == '"') {
|
if (ch == quote_char) {
|
||||||
parser->tok_str[parser->tok_str_len] = '\0';
|
parser->tok_str[parser->tok_str_len] = '\0';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -158,10 +158,10 @@ static bool parser_next_token(struct kanshi_parser *parser) {
|
|||||||
return true;
|
return true;
|
||||||
} else if (isspace(ch)) {
|
} else if (isspace(ch)) {
|
||||||
continue;
|
continue;
|
||||||
} else if (ch == '"') {
|
} else if (ch == '"' || ch == '\'') {
|
||||||
parser->tok_type = KANSHI_TOKEN_STR;
|
parser->tok_type = KANSHI_TOKEN_STR;
|
||||||
parser->tok_str_len = 0;
|
parser->tok_str_len = 0;
|
||||||
return parser_read_quoted(parser);
|
return parser_read_quoted(parser, ch);
|
||||||
} else if (ch == '#') {
|
} else if (ch == '#') {
|
||||||
parser_ignore_line(parser);
|
parser_ignore_line(parser);
|
||||||
parser->tok_type = KANSHI_TOKEN_NEWLINE;
|
parser->tok_type = KANSHI_TOKEN_NEWLINE;
|
||||||
|
Loading…
Reference in New Issue
Block a user