Reviewers: lemzwerg, marc,
Message:
On 2012/10/28 07:46:36, marc wrote:
On 2012/10/26 13:58:41, lemzwerg wrote:
> LGTM.
+1
Nice to have this feature available!
It is more a pacifier than a feature since it does not actually add
any functionality. And I don't want to see anything in our code tree
(except possibly the documentation for it itself) making use of it,
just like I don't want to see durations written as 4 . . . anywhere.
I am not unconvinced this is a good idea. It just addresses a pet
peeve in some kind of manner.
Description:
Allow quoted identifiers like to be used like \"violin1", not just
defined.
Consists of the following four commits:
Add regtest for quoted identifiers
Allow quoted identifiers like to be used like \"violin1", not just
defined.
A frequent complaint is the absence of identifiers with numbers in
them, like violin1.
Defining such identifiers has always been possible with
"violin1" = { c''4 c c c }
This patch lets one actually use them by calling them with
\"violin1"
lexer.ll: duplicate a few quotes in character sets to help syntax
highlighting
This uses regular expressions like [^''] rather than [^'] in order to
keep
the confusion of editors like Emacs tolerable.
lexer.ll: lyric_quote was not necessary as separate state.
Please review this at http://codereview.appspot.com/6778055/
Affected files:
A input/regression/identifier-quoted.ly
M lily/lexer.ll
Index: input/regression/identifier-quoted.ly
diff --git a/input/regression/identifier-quoted.ly
b/input/regression/identifier-quoted.ly
new file mode 100644
index
0000000000000000000000000000000000000000..02611c1aaf7dffb53c744ac6a9ef91e244e9e760
--- /dev/null
+++ b/input/regression/identifier-quoted.ly
@@ -0,0 +1,26 @@
+\header
+{
+
+texidoc = "Music identifiers containing arbitrary characters may be
+initialized using
+@example
+\"violin1\" = @{ c''4 c'' c'' c'' @}
+@end example
+and used as:
+@example
+\\new Voice @{ \\\"violin1\" @}
+@end example
+"
+
+}
+
+\version "2.17.6"
+
+"violin1" = { c''4 c'' c'' c'' }
+"violin2" = { a'4 a' a' a' }
+
+\layout { ragged-right = ##t }
+
+{
+ << \"violin1" \\ \"violin2" >>
+}
Index: lily/lexer.ll
diff --git a/lily/lexer.ll b/lily/lexer.ll
index
60a41943a61ce2b2148e2717fa5d972370d7ea87..448333e1d00e2ac66d55d216c48a48e4b3bb980c
100644
--- a/lily/lexer.ll
+++ b/lily/lexer.ll
@@ -91,8 +91,14 @@ bool is_valid_version (string s);
yylval = SCM_EOL; \
} while (0)
-#define start_lyric_quote() do { \
- yy_push_state (lyric_quote); \
+/*
+ The inside of \"violin1" is marked by nesting two quote modes as we
+ don't have a dedicated command mode.
+*/
+
+#define start_command_quote() do { \
+ yy_push_state (quote); \
+ yy_push_state (quote); \
yylval = SCM_EOL; \
} while (0)
@@ -124,7 +130,6 @@ SCM (* scm_parse_error_handler) (void *);
%x figures
%x incl
%x lyrics
-%x lyric_quote
%x longcomment
%x markup
%x notes
@@ -165,7 +170,7 @@ WHITE [ \n\t\f\r]
HORIZONTALWHITE [ \t]
BLACK [^ \n\t\f\r]
RESTNAME [rs]
-ESCAPED [nt\\'"]
+ESCAPED [nt\\''""]
EXTENDER __
HYPHEN --
BOM_UTF8 \357\273\277
@@ -253,7 +258,7 @@ BOM_UTF8 \357\273\277
<INITIAL,chords,lyrics,notes,figures>\\sourcefileline{WHITE}* {
yy_push_state (sourcefileline);
}
-<version>\"[^"]*\" { /* got the version number */
+<version>\"[^""]*\" { /* got the version number */
string s (YYText_utf8 () + 1);
s = s.substr (0, s.rfind ('\"'));
@@ -490,7 +495,9 @@ BOM_UTF8 \357\273\277
{WORD} {
return scan_bare_word (YYText_utf8 ());
}
-
+ \\\" {
+ start_command_quote ();
+ }
{COMMAND}/[-_] | // backup rule
{COMMAND} {
return scan_escaped_word (YYText_utf8 () + 1);
@@ -510,7 +517,7 @@ BOM_UTF8 \357\273\277
}
}
-<quote,lyric_quote>{
+<quote>{
\\{ESCAPED} {
char c = escaped_char (YYText ()[1]);
yylval = scm_cons (scm_from_locale_stringn (&c, 1),
@@ -530,6 +537,11 @@ BOM_UTF8 \357\273\277
SCM_UNDEFINED,
SCM_UNDEFINED);
+ if (get_state () == quote) {
+ yy_pop_state ();
+ return scan_escaped_word (ly_scm2string (yylval));
+ }
+
return is_lyric_state () ? LYRICS_STRING : STRING;
}
\\ {
@@ -540,7 +552,7 @@ BOM_UTF8 \357\273\277
<lyrics>{
\" {
- start_lyric_quote ();
+ start_quote ();
}
{FRACTION} {
yylval = scan_fraction (YYText ());
@@ -551,6 +563,9 @@ BOM_UTF8 \357\273\277
yylval = scm_c_read_string (YYText ());
return UNSIGNED;
}
+ \\\" {
+ start_command_quote ();
+ }
{COMMAND}/[-_] | // backup rule
{COMMAND} {
return scan_escaped_word (YYText_utf8 () + 1);
@@ -584,6 +599,9 @@ BOM_UTF8 \357\273\277
{WORD} {
return scan_bare_word (YYText_utf8 ());
}
+ \\\" {
+ start_command_quote ();
+ }
{COMMAND}/[-_] | // backup rule
{COMMAND} {
return scan_escaped_word (YYText_utf8 () + 1);
@@ -629,6 +647,9 @@ BOM_UTF8 \357\273\277
yylval = SCM_UNSPECIFIED;
return SCORE;
}
+ \\\" {
+ start_command_quote ();
+ }
{COMMAND}/[-_] | // backup rule
{COMMAND} {
string str (YYText_utf8 () + 1);
@@ -723,6 +744,9 @@ BOM_UTF8 \357\273\277
{WORD} {
return scan_bare_word (YYText_utf8 ());
}
+ \\\" {
+ start_command_quote ();
+ }
{COMMAND}/[-_] | // backup rule
{COMMAND} {
return scan_escaped_word (YYText_utf8 () + 1);
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel