1 /* Copyright (C) 2017 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
4 * Since we do not supply yywrap(), we use noyywrap to instruct the scanner to
5 * behave as though yywrap() returned 1.
10 * We don't want symbols to clash with those of other flex users, particularly
13 %option prefix="mp_yy"
16 * Generate a scanner that maintains the number of the current line read from
17 * its input in the yylineno variable.
21 /* Generate a bison-compatible scanner. */
22 %option bison-bridge bison-locations
25 * Warn (in particular) if the default rule can be matched but no default rule
31 * Generate a scanner which is portable and safe to use in one or more threads
37 * Generate a scanner which always looks one extra character ahead. This is a
38 * bit faster than an interactive scanner for which look ahead happens only
41 %option never-interactive
50 #define YYSTYPE MP_YYSTYPE
51 #define YYLTYPE MP_YYLTYPE
52 #define YY_DECL int mp_yylex(MP_YYSTYPE *yylval_param, MP_YYLTYPE *yylloc_param, \
53 struct mp_context *ctx, struct mp_ast_node **ast, mp_yyscan_t yyscanner)
55 #define MP_YY_USER_ACTION do {mp_yylloc->first_line = mp_yylineno;} while (0);
57 DECIMAL_CONSTANT (0|([[:digit:]]{-}[0])[[:digit:]]*)
58 STRING_LITERAL \"([^\"\\\n]|(\\[\"\\abfnrtv]))*\"
59 REGEX_PATTERN \/([^\/\\\n]|(\\[\/\\abfnrtv]))*\/([in])*
60 WILDCARD_PATTERN \|([^\|\\\n]|(\\[\|\\abfnrtv]))*\|([npPlie])*
63 is_set {return IS_SET;}
64 num_attributes_set {return NUM_ATTRIBUTES_SET;}
66 artist {return ARTIST;}
69 comment {return COMMENT;}
71 num_played {return NUM_PLAYED;}
72 image_id {return IMAGE_ID;}
73 lyrics_id {return LYRICS_ID;}
74 bitrate {return BITRATE;}
75 frequency {return FREQUENCY;}
76 channels {return CHANNELS;}
77 duration {return DURATION;}
81 [[:space:]]+|#.*\n /* skip comments and whitespace */
83 "("|")"|","|"+"|"-"|"*"|"/"|"<"|">" {return yytext[0];}
89 "!=" {return NOT_EQUAL;}
90 "<=" {return LESS_OR_EQUAL;}
91 ">=" {return GREATER_OR_EQUAL;}
92 "=~" {return REGEX_MATCH;}
93 "=|" {return FILENAME_MATCH;}
97 yylval->node = mp_new_ast_leaf_node(NUM);
98 ret = para_atoi64(yytext, &yylval->node->sv.intval);
101 mp_parse_error(yylloc->first_line, ctx, "%s: %s", yytext,
102 para_strerror(-ret));
103 return -E_MOOD_PARSE;
109 yylval->node = mp_new_ast_leaf_node(STRING_LITERAL);
110 parse_quoted_string(yytext, "\"\"", &yylval->node->sv.strval);
111 //PARA_CRIT_LOG("strval: %s\n", yylval->node->sv.strval);
112 //PARA_CRIT_LOG("node: %p\n", yylval->node);
113 return STRING_LITERAL;
118 yylval->node = mp_new_ast_leaf_node(REGEX_PATTERN);
119 ret = mp_parse_regex_pattern(yytext, &yylval->node->sv.re_pattern);
121 mp_parse_error(yylloc->first_line, ctx, "%s: %s", yytext,
122 para_strerror(-ret));
123 return -E_MOOD_PARSE;
125 return REGEX_PATTERN;
129 yylval->node = mp_new_ast_leaf_node(WILDCARD_PATTERN);
130 mp_parse_wildcard_pattern(yytext, &yylval->node->sv.wc_pattern);
131 return WILDCARD_PATTERN;
135 mp_parse_error(yylloc->first_line, ctx, "unrecognized text: %s",
137 return -E_MOOD_PARSE;