From c6f3cfb7d7c711f0a59fb364af4f74d9996c57e2 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Mon, 21 Aug 2023 16:23:41 +0500 Subject: [PATCH] Support single quotes for strings as in CSS --- doc/rofi-theme.5 | 15 ++++++++------- doc/rofi-theme.5.markdown | 15 ++++++++------- lexer/theme-lexer.l | 16 +++++++++------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index 6c4139ad..eb4c3fa0 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -565,13 +565,13 @@ Some of these types are a combination of other types. .SS String .RS .IP \(bu 2 -Format: \fB\fC"[:print:]+"\fR +Format: \fB\fC(["'])[:print:]+\\1\fR .RE .PP -A string is always surrounded by double quotes (\fB\fC"\fR). Between the quotes there -can be any printable character. +Strings are always surrounded by double (\fB\fC"\fR) or single (\fB\fC\&'\fR, apostrophe) quotes. Between +the quotes there can be any printable character. .PP For example: @@ -592,15 +592,16 @@ The string must be valid UTF-8, special characters can be escaped: .RS .nf -text { - content: "Line one\\n\\tIndented line two"; -} +text { content: "Line one\\n\\tIndented line two 'Quoted text'"; } +text { content: 'Line one\\n\\tIndented line two "Quoted text"'; } +text { content: "Line one\\n\\tIndented line two \\"Quoted text\\""; } .fi .RE .PP -The following special characters can be escaped: \fB\fC\\b\fR, \fB\fC\\f\fR, \fB\fC\\n\fR, \fB\fC\\r\fR, \fB\fC\\t\fR, \fB\fC\\v\fR, \fB\fC\\\fR and \fB\fC"\fR\&. +The following special characters can be escaped: \fB\fC\\b\fR, \fB\fC\\f\fR, \fB\fC\\n\fR, \fB\fC\\r\fR, \fB\fC\\t\fR, \fB\fC\\v\fR, \fB\fC\\\fR, +\fB\fC"\fR and \fB\fC\&'\fR (double quotes inside single-quotes or in reverse don't need escape). .SS Integer .RS diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 188e4394..ea60a4c5 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -379,10 +379,10 @@ Some of these types are a combination of other types. ### String -- Format: `"[:print:]+"` +- Format: `(["'])[:print:]+\1` -A string is always surrounded by double quotes (`"`). Between the quotes there -can be any printable character. +Strings are always surrounded by double (`"`) or single (`'`, apostrophe) quotes. Between +the quotes there can be any printable character. For example: @@ -393,12 +393,13 @@ font: "Awasome 12"; The string must be valid UTF-8, special characters can be escaped: ```css -text { - content: "Line one\n\tIndented line two"; -} +text { content: "Line one\n\tIndented line two 'Quoted text'"; } +text { content: 'Line one\n\tIndented line two "Quoted text"'; } +text { content: "Line one\n\tIndented line two \"Quoted text\""; } ``` -The following special characters can be escaped: `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\` and `"`. +The following special characters can be escaped: `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\`, +`"` and `'` (double quotes inside single-quotes or in reverse don't need escape). ### Integer diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 0074b861..8edd776e 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -163,17 +163,19 @@ static double rofi_theme_parse_convert_hex ( char high, char low) ASC [\x00-\x7f] ASCN [\x00-\t\v-\x7f] -ASCNP [\x00-\t\v-\x21\x23-\x7f] +ASCNP1 [\x00-\t\v-\x21\x23-\x7f] +ASCNP2 [\x00-\t\v-\x26\x28-\x7f] U [\x80-\xbf] U2 [\xc2-\xdf] U3 [\xe0-\xef] U4 [\xf0-\xf4] - // UANY {ASC}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} -UANYN {ASCN}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} - // UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} +UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} + // UANY {ASC}|{UONLY} +UANYN {ASCN}|{UONLY} -UANYNP {ASCNP}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} +UANYNP1 {ASCNP1}|{UONLY} +UANYNP2 {ASCNP2}|{UONLY} WHITESPACE [[:blank:]] WSO [[:blank:]]* @@ -181,8 +183,8 @@ WORD [[:alnum:]-]+ WORD_ELEMENT [[:alpha:]][[:alnum:]-]* WORD_ENV [[:alpha:]_][[:alnum:]_]* COLOR_NAME [[:alpha:]]+ -STRING \"{UANYN}*\" -STRING_LIST \"{UANYNP}*\" +STRING \"{UANYN}*\"|\'{UANYN}*\' +STRING_LIST \"{UANYNP1}*\"|\'{UANYNP2}*\' CHAR \'({ASCN}|\\\\|\\\'|\\0)\' HEX [[:xdigit:]] NUMBER [[:digit:]]+