Paraslash Audio Streaming | |
About News Download Documentation Development |
Internal mood parser API (backend). More...
Data Structures | |
struct | mp_re_pattern |
Parsed regex pattern. More... | |
struct | mp_wc_pattern |
Parsed wildcard pattern. More... | |
union | mp_semantic_value |
The possible values of a node in the abstract syntax tree (AST). More... | |
struct | mp_ast_node |
Describes one node of the abstract syntax tree. More... | |
Typedefs | |
typedef void * | mp_yyscan_t |
Since we use a reentrant lexer, all functions generated by flex(1) receive an additional argument of this type. More... | |
Functions | |
__printf_3_4 void | mp_parse_error (int line, struct mp_context *ctx, const char *fmt,...) |
Set the error bit in the parser context and log a message. More... | |
unsigned | parse_quoted_string (const char *src, const char quote_chars[2], char **result) |
Parse a (generalized) string literal. More... | |
int | mp_parse_regex_pattern (const char *src, struct mp_re_pattern *result) |
Parse and compile an extended regular expression pattern, including flags. More... | |
void | mp_parse_wildcard_pattern (const char *src, struct mp_wc_pattern *result) |
Parse a wildcard pattern, including flags. More... | |
struct mp_ast_node * | mp_new_ast_leaf_node (int id) |
Allocate a new leaf node for the abstract syntax tree. More... | |
bool | mp_eval_ast (struct mp_ast_node *root, struct mp_context *ctx) |
Evaluate an abstract syntax tree, starting at the root node. More... | |
void | mp_free_ast (struct mp_ast_node *root) |
Deallocate an abstract syntax tree. More... | |
bool | mp_is_set (const char *attr, struct mp_context *ctx) |
Check whether the given attribute is set for the current audio file. More... | |
char * | mp_path (struct mp_context *ctx) |
Return the full path to the audio file. More... | |
int64_t | mp_year (struct mp_context *ctx) |
Parse and return the value of the year tag. More... | |
int64_t | mp_num_attributes_set (struct mp_context *ctx) |
Count the number of attributes set. More... | |
int64_t | mp_duration (struct mp_context *ctx) |
Return the duration of the audio file from the afh info structure. More... | |
Internal mood parser API (backend).
This header is included from the lexer, the parser, and from mp.c, but not from mood.c, the only user of the mood parser front end. It contains structures and function prototypes which are considered implementation details.
There is one function for each keyword in the context-free grammar of the parser. These functions return the semantic value of the keyword.
The functions declared here are defined either in mp.c or in mp.y.
typedef void* mp_yyscan_t |
Since we use a reentrant lexer, all functions generated by flex(1) receive an additional argument of this type.
__printf_3_4 void mp_parse_error | ( | int | line, |
struct mp_context * | ctx, | ||
const char * | fmt, | ||
... | |||
) |
Set the error bit in the parser context and log a message.
line | The number of the input line which caused the error. |
ctx | Contains the error bit. |
fmt | Usual format string. |
This is called if the lexer or the parser detect an error in the mood definition. Only the first error is logged (with a severity of "warn").
References PARA_WARNING_LOG, xasprintf(), and xvasprintf().
unsigned parse_quoted_string | ( | const char * | src, |
const char | quote_chars[2], | ||
char ** | result | ||
) |
Parse a (generalized) string literal.
src | The string to parse. |
quote_chars | Opening and closing quote characters. |
result | The corresponding C string is returned here. |
This function turns a generalized C99 string literal like "xyz\n" into a C string (containing the three characters 'x', 'y' and 'z', followed by a newline character and the terminating zero byte). The function receives quote characters as an argument so that, for example, regular expression patterns enclosed in '/' can be parsed as well. To parse a proper string literal, one has to pass two double quotes as the second argument.
The function strips off the opening and leading quote characters, replaces double backslashes by single backslashes and handles the usual escapes like
and ".
The caller must make sure that the input is well-formed. The function simply aborts if the input is not a valid C99 string literal (modulo the quote characters).
References alloc().
Referenced by mp_parse_regex_pattern(), and mp_parse_wildcard_pattern().
int mp_parse_regex_pattern | ( | const char * | src, |
struct mp_re_pattern * | result | ||
) |
Parse and compile an extended regular expression pattern, including flags.
src | The pattern to parse. |
result | C-string and flags are returned here. |
A regex pattern is identical to a C99 string literal except (a) it is enclosed in '/' characters rather than double quotes, (b) double quote characters which are part of the pattern do not need to be quoted with backslashes, but slashes must be quoted in this way, and (c) the closing slash may be followed by one or more flag characters which modify the matching behaviour.
The only flags which are currently supported are 'i' to ignore case in match (REG_ICASE) and 'n' to change the handling of newline characters (REG_NEWLINE).
References mp_re_pattern::flags, para_regcomp(), parse_quoted_string(), and mp_re_pattern::preg.
void mp_parse_wildcard_pattern | ( | const char * | src, |
struct mp_wc_pattern * | result | ||
) |
Parse a wildcard pattern, including flags.
src | The pattern to parse. |
result | C-string and flags are returned here. |
This function parses a shell wildcard pattern. It is similar to mp_parse_regex_pattern(), so the remarks mentioned there apply to this function as well.
Wildcard patterns differ from regular expression patterns in that (a) they must be enclosed in '|' characters, (b) they support different flags for modifying matching behaviour, and (c) there is no cache for them.
The following flags, whose meaning is explained in fnmatch(3), are currently supported: 'n' (FNM_NOESCAPE), 'p' (FNM_PATHNAME), 'P' (FNM_PERIOD), 'l' (FNM_LEADING_DIR), 'i' (FNM_CASEFOLD), 'e' (FNM_EXTMATCH). The last flag is a GNU extension. It is silently ignored on non GNU systems.
References mp_wc_pattern::flags, parse_quoted_string(), and mp_wc_pattern::pat.
struct mp_ast_node* mp_new_ast_leaf_node | ( | int | id | ) |
Allocate a new leaf node for the abstract syntax tree.
id | Initial value for the ->id field of the new node |
bool mp_eval_ast | ( | struct mp_ast_node * | root, |
struct mp_context * | ctx | ||
) |
Evaluate an abstract syntax tree, starting at the root node.
root | As returned from mp_init() via the context pointer. |
ctx | Contains the aft row to evaluate. |
Referenced by mp_eval_row().
void mp_free_ast | ( | struct mp_ast_node * | root | ) |
Deallocate an abstract syntax tree.
This frees the memory occupied by the nodes of the AST, the child pointers of the internal nodes and the (constant) semantic values of the leaf nodes (string literals, unescaped wildcard patterns and pre-compiled regular expressions).
root | It's OK to pass NULL here. |
Referenced by mp_init(), and mp_shutdown().
bool mp_is_set | ( | const char * | attr, |
struct mp_context * | ctx | ||
) |
Check whether the given attribute is set for the current audio file.
attr | The string to look up in the attribute table. |
ctx | See mp_path(). |
First, determine the bit number which corresponds to the attribute, then check if this bit is set in the ->attributes field of the afs_info structure of the audio file.
References get_attribute_bitnum_by_name().
char* mp_path | ( | struct mp_context * | ctx | ) |
Return the full path to the audio file.
ctx | Contains a reference to the row of the audio file table which corresponds to the current audio file. The path of the audio file, the afs_info and the afh_info structures (which contain the tag information) can be retrieved through this reference. |
References get_audio_file_path_of_row().
int64_t mp_year | ( | struct mp_context * | ctx | ) |
Parse and return the value of the year tag.
ctx | See mp_path(). |
int64_t mp_num_attributes_set | ( | struct mp_context * | ctx | ) |
int64_t mp_duration | ( | struct mp_context * | ctx | ) |
Return the duration of the audio file from the afh info structure.
ctx | See mp_path(). |
The duration is computed by multiplying the number of chunks and the duration of one chunk.