1
0
mirror of https://github.com/emersion/kanshi synced 2024-09-15 00:20: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:
Mayeul Cantan 2021-01-22 12:45:27 +01:00 committed by Simon Ser
parent a3061857d6
commit fd565f4415

View File

@ -70,7 +70,7 @@ static bool parser_append_tok_ch(struct kanshi_parser *parser, char ch) {
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) {
int ch = parser_read_char(parser);
if (ch < 0) {
@ -80,7 +80,7 @@ static bool parser_read_quoted(struct kanshi_parser *parser) {
return false;
}
if (ch == '"') {
if (ch == quote_char) {
parser->tok_str[parser->tok_str_len] = '\0';
return true;
}
@ -158,10 +158,10 @@ static bool parser_next_token(struct kanshi_parser *parser) {
return true;
} else if (isspace(ch)) {
continue;
} else if (ch == '"') {
} else if (ch == '"' || ch == '\'') {
parser->tok_type = KANSHI_TOKEN_STR;
parser->tok_str_len = 0;
return parser_read_quoted(parser);
return parser_read_quoted(parser, ch);
} else if (ch == '#') {
parser_ignore_line(parser);
parser->tok_type = KANSHI_TOKEN_NEWLINE;