[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/16] Allow the string "xxx.yyy" to parse as a symbol list
From: |
David Kastrup |
Subject: |
[PATCH 09/16] Allow the string "xxx.yyy" to parse as a symbol list |
Date: |
Tue, 9 Oct 2012 20:59:54 +0200 |
This changes the parser to let xxx.yyy be a valid way of specifying a
function argument required to be #'(xxx yyy).
---
lily/parser.yy | 48 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/lily/parser.yy b/lily/parser.yy
index 6a087d8..121b059 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -231,7 +231,7 @@ SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM
modification_list);
SCM make_chord_step (SCM step, Rational alter);
SCM make_simple_markup (SCM a);
bool is_duration (int t);
-bool is_regular_identifier (SCM id);
+bool is_regular_identifier (SCM id, bool multiple=false);
SCM try_string_variants (SCM pred, SCM str);
int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
@@ -1309,15 +1309,15 @@ symbol_list_part:
symbol_list_element
{
SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
- if (scm_is_true (scm_call_1 (sym_l_p, $1)))
- $$ = scm_reverse ($1);
- else {
+ if (scm_is_false (scm_call_1 (sym_l_p, $1)))
+ {
$$ = try_string_variants (sym_l_p, $1);
if (SCM_UNBNDP ($$)) {
parser->parser_error (@1, _("not a symbol"));
$$ = SCM_EOL;
}
}
+ $$ = scm_reverse ($$);
}
;
@@ -3413,27 +3413,47 @@ SCM loc_on_music (Input loc, SCM arg)
SCM
try_string_variants (SCM pred, SCM str)
{
+ // a matching predicate is always ok
if (scm_is_true (scm_call_1 (pred, str)))
return str;
- if (scm_is_string (str))
- {
- if (!is_regular_identifier (str))
- return SCM_UNDEFINED;
-
- str = scm_string_to_symbol (str);
+ // a symbol may be interpreted as a list of symbols if it helps
+ if (scm_is_symbol (str)) {
+ str = scm_list_1 (str);
if (scm_is_true (scm_call_1 (pred, str)))
return str;
- } else if (!scm_is_symbol (str))
return SCM_UNDEFINED;
+ }
+
+ // If this cannot be a string representation of a symbol list,
+ // we are through.
+
+ if (!is_regular_identifier (str, true))
+ return SCM_UNDEFINED;
+
+ str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
+ for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
+ scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
+
+ // Let's attempt the symbol list interpretation first.
- str = scm_list_1 (str);
if (scm_is_true (scm_call_1 (pred, str)))
return str;
+
+ // If there is just one symbol in the list, we might interpret
+ // it as a single symbol
+
+ if (scm_is_null (scm_cdr (str)))
+ {
+ str = scm_car (str);
+ if (scm_is_true (scm_call_1 (pred, str)))
+ return str;
+ }
+
return SCM_UNDEFINED;
}
bool
-is_regular_identifier (SCM id)
+is_regular_identifier (SCM id, bool multiple)
{
if (!scm_is_string (id))
return false;
@@ -3449,7 +3469,7 @@ is_regular_identifier (SCM id)
|| (c >= 'A' && c <= 'Z')
|| c > 0x7f)
middle = true;
- else if (middle && (c == '-' || c == '_'))
+ else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
middle = false;
else
return false;
--
1.7.9.5
- [PATCH 05/16] Let \accidentalStyle detect its optional context argument by looking at its letter case, (continued)
- [PATCH 05/16] Let \accidentalStyle detect its optional context argument by looking at its letter case, David Kastrup, 2012/10/09
- [PATCH 11/16] Replace the rather fuzzy list-or-symbol? with symbol-list-or-symbol?, David Kastrup, 2012/10/09
- [PATCH 13/16] Change \accidentalStyle to get a symbol list as argument, David Kastrup, 2012/10/09
- [PATCH 03/16] parser.yy: make is_regular_identifier match the lexer definition, David Kastrup, 2012/10/09
- [PATCH 14/16] convert-ly rule for \alterbroken, \accidentalStyle, \overrideProperty, David Kastrup, 2012/10/09
- [PATCH 01/16] Assignments can't contain literal lyric music (wrong lexer mode), David Kastrup, 2012/10/09
- [PATCH 04/16] Factor SCM_IDENTIFIER out from embedded_scm_arg*, David Kastrup, 2012/10/09
- [PATCH 02/16] parser.yy: FRACTION does not require a closed expression before it, David Kastrup, 2012/10/09
- [PATCH 16/16] Let \overrideProperty accept nested properties, David Kastrup, 2012/10/09
- [PATCH 12/16] Make \alterBroken, \hide, \omit, \overrideProperty, \shape take unquoted Context.Grob specs, David Kastrup, 2012/10/09
- [PATCH 09/16] Allow the string "xxx.yyy" to parse as a symbol list,
David Kastrup <=
- [PATCH 06/16] Allow LilyPond strings to stand in for symbols when parsing, David Kastrup, 2012/10/09
- [PATCH 15/16] Run scripts/auxiliar/update-with-convert-ly.sh, David Kastrup, 2012/10/09
- [PATCH 10/16] Add symbol-list-or-music? predicate, David Kastrup, 2012/10/09
- Re: Context.Grob considered as symbol list, Colin Campbell, 2012/10/09
- Re: Context.Grob considered as symbol list, David Kastrup, 2012/10/10
- Re: Context.Grob considered as symbol list, David Kastrup, 2012/10/10
- Re: Context.Grob considered as symbol list, Werner LEMBERG, 2012/10/10
- Re: Context.Grob considered as symbol list, David Kastrup, 2012/10/10
- Re: Context.Grob considered as symbol list, Werner LEMBERG, 2012/10/10
- Re: Context.Grob considered as symbol list, David Kastrup, 2012/10/10