2 * Copyright (C) 2017 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
8 * Since we do not supply yywrap(), we use noyywrap to instruct the scanner to
9 * behave as though yywrap() returned 1.
14 * We don't want symbols to clash with those of other flex users, particularly
17 %option prefix="mp_yy"
20 * Generate a scanner that maintains the number of the current line read from
21 * its input in the yylineno variable.
25 /* Generate a bison-compatible scanner. */
26 %option bison-bridge bison-locations
29 * Warn (in particular) if the default rule can be matched but no default rule
35 * Generate a scanner which is portable and safe to use in one or more threads
41 * Generate a scanner which always looks one extra character ahead. This is a
42 * bit faster than an interactive scanner for which look ahead happens only
45 %option never-interactive
54 #define YYSTYPE MP_YYSTYPE
55 #define YYLTYPE MP_YYLTYPE
56 #define YY_DECL int mp_yylex(MP_YYSTYPE *yylval_param, MP_YYLTYPE *yylloc_param, \
57 struct mp_context *ctx, struct mp_ast_node **ast, mp_yyscan_t yyscanner)
59 #define MP_YY_USER_ACTION do {mp_yylloc->first_line = mp_yylineno;} while (0);
61 DECIMAL_CONSTANT (0|([[:digit:]]{-}[0])[[:digit:]]*)
62 STRING_LITERAL \"([^\"\\\n]|(\\[\"\\abfnrtv]))*\"
63 REGEX_PATTERN \/([^\/\\\n]|(\\[\/\\abfnrtv]))*\/([in])*
64 WILDCARD_PATTERN \|([^\|\\\n]|(\\[\|\\abfnrtv]))*\|([npPlie])*
67 is_set {return IS_SET;}
68 num_attributes_set {return NUM_ATTRIBUTES_SET;}
70 artist {return ARTIST;}
73 comment {return COMMENT;}
75 num_played {return NUM_PLAYED;}
76 image_id {return IMAGE_ID;}
77 lyrics_id {return LYRICS_ID;}
78 bitrate {return BITRATE;}
79 frequency {return FREQUENCY;}
80 channels {return CHANNELS;}
84 [[:space:]]+|#.*\n /* skip comments and whitespace */
86 "("|")"|","|"+"|"-"|"*"|"/"|"<"|">" {return yytext[0];}
92 "!=" {return NOT_EQUAL;}
93 "<=" {return LESS_OR_EQUAL;}
94 ">=" {return GREATER_OR_EQUAL;}
95 "=~" {return REGEX_MATCH;}
96 "=|" {return FILENAME_MATCH;}
100 yylval->node = mp_new_ast_leaf_node(NUM);
101 ret = para_atoi64(yytext, &yylval->node->sv.intval);
104 mp_parse_error(yylloc->first_line, ctx, "%s: %s", yytext,
105 para_strerror(-ret));
106 return -E_MOOD_PARSE;
112 yylval->node = mp_new_ast_leaf_node(STRING_LITERAL);
113 parse_quoted_string(yytext, "\"\"", &yylval->node->sv.strval);
114 //PARA_CRIT_LOG("strval: %s\n", yylval->node->sv.strval);
115 //PARA_CRIT_LOG("node: %p\n", yylval->node);
116 return STRING_LITERAL;
121 yylval->node = mp_new_ast_leaf_node(REGEX_PATTERN);
122 ret = mp_parse_regex_pattern(yytext, &yylval->node->sv.re_pattern);
124 mp_parse_error(yylloc->first_line, ctx, "%s: %s", yytext,
125 para_strerror(-ret));
126 return -E_MOOD_PARSE;
128 return REGEX_PATTERN;
132 yylval->node = mp_new_ast_leaf_node(WILDCARD_PATTERN);
133 mp_parse_wildcard_pattern(yytext, &yylval->node->sv.wc_pattern);
134 return WILDCARD_PATTERN;
138 mp_parse_error(yylloc->first_line, ctx, "unrecognized text: %s",
140 return -E_MOOD_PARSE;