Fix formatting of mps-interpreter README

This commit is contained in:
NGnius (Graham) 2022-01-18 09:20:26 -05:00
parent b9def2f15c
commit 9afda71f6a
3 changed files with 100 additions and 74 deletions

View file

@ -46,70 +46,83 @@ Operations to reduce the items in an iterable: `iterable.(filter);`.
Filters are statements of the format `something.(predicate)`, where "something" is a variable name or another valid statement, and "predicate" is a valid filter predicate (see below).
E.g. `files(folder="~/Music/", recursive=true).(title == "Romantic Traffic");` is valid filter syntax to filter all songs in the Music folder for songs named "Romantic Traffic" (probably just one song).
field == something
field != something
field >= something
field > something
field <= something
field < something -- e.g. `iterable.(title == "Romantic Traffic");`
#### field == something
Compare all items, keeping only those that match the condition. Valid field names are those of the MpsMusicItem (title, artist, album, genre, track, etc.), though this will change when proper object support is added. Optionally, a ? or ! can be added to the end of the field name to skip items whose field is missing/incomparable, or keep all items whose field is missing/incomparable (respectively).
#### field != something
start..end -- e.g. `iterable.(0..42);`
#### field >= something
Keep only the items that are at the start index up to the end index. Start and/or end may be omitted to start/stop at the iterable's existing start/end (respectively). This stops once the end condition is met, leaving the rest of the iterator unconsumed.
#### field > something
start..=end -- e.g. `iterable.(0..=42);`
#### field <= something
Keep only the items that are at the start index up to and including the end index. Start may be omitted to start at the iterable's existing start. This stops once the end condition is met, leaving the rest of the iterator unconsumed.
#### field < something -- e.g. `iterable.(title == "Romantic Traffic");`
index -- e.g. `iterable.(4);`
Compare all items, keeping only those that match the condition. Valid field names are those of the MpsMusicItem (title, artist, album, genre, track, etc.), though this will change when proper object support is added. Optionally, a ? or ! can be added to the end of the field name to skip items whose field is missing/incomparable, or keep all items whose field is missing/incomparable (respectively).
Keep only the item at the given index. This stops once the index is reached, leaving the rest of the iterator unconsumed.
#### start..end -- e.g. `iterable.(0..42);`
predicate1 || predicate2 -- e.g. `iterable.(4 || 5);`
Keep only the items that are at the start index up to the end index. Start and/or end may be omitted to start/stop at the iterable's existing start/end (respectively). This stops once the end condition is met, leaving the rest of the iterator unconsumed.
Keep only the items that meet the criteria of predicate1 or predicate2. This will always consume the full iterator.
#### start..=end -- e.g. `iterable.(0..=42);`
[empty] -- e.g. `iterable.();`
Keep only the items that are at the start index up to and including the end index. Start may be omitted to start at the iterable's existing start. This stops once the end condition is met, leaving the rest of the iterator unconsumed.
Matches all items
#### index -- e.g. `iterable.(4);`
if filter: operation1 else operation2 -- e.g. `iterable.(if title == "Romantic Traffic": repeat(item, 2) else item.());`
Keep only the item at the given index. This stops once the index is reached, leaving the rest of the iterator unconsumed.
Replace items matching the filter with operation1 and replace items not matching the filter with operation2. The `else operation2` part may be omitted to preserve items not matching the filter. To perform operations with the current item, use the special variable `item`.
#### predicate1 || predicate2 -- e.g. `iterable.(4 || 5);`
Keep only the items that meet the criteria of predicate1 or predicate2. This will always consume the full iterator.
#### [empty] -- e.g. `iterable.();`
Matches all items
#### if filter: operation1 else operation2 -- e.g. `iterable.(if title == "Romantic Traffic": repeat(item, 2) else item.());`
Replace items matching the filter with operation1 and replace items not matching the filter with operation2. The `else operation2` part may be omitted to preserve items not matching the filter. To perform operations with the current item, use the special variable `item`. The replacement filter may not contain || -- instead, use multiple filters chained together.
### Functions
Similar to most other languages: `function_name(param1, param2, etc.);`.
These always return an iterable which can me manipulated.
These always return an iterable which can be manipulated.
Functions are statements of the format `function_name(params)`, where "function_name" is one of the function names (below) and params is a valid parameter input for the function.
Each function is responsible for parsing it's own parameters when the statement is parsed, so this is very flexible.
E.g. `files(folder="~/Music/", recursive=true);` is valid function syntax to execute the files function with parameters `folder="~/Music/", recursive=true`.
sql_init(generate = true|false, folder = "path/to/music");
Initialize the SQLite database connection using the provided parameters. This must be performed before any other database operation (otherwise the database will already be connected with default settings).
#### sql_init(generate = true|false, folder = "path/to/music");
sql("SQL query here");
Perform a raw SQLite query on the database which MPS auto-generates. An iterator of the results is returned.
Initialize the SQLite database connection using the provided parameters. This must be performed before any other database operation (otherwise the database will already be connected with default settings).
song("something");
Retrieve all songs in the database with a title like something.
#### sql("SQL query here");
album("something");
Retrieve all songs in the database with an album title like something.
Perform a raw SQLite query on the database which MPS auto-generates. An iterator of the results is returned.
artist("something");
Retrieve all songs in the database with an artist name like something.
#### song("something");
genre("something");
Retrieve all songs in the database with a genre title like something.
Retrieve all songs in the database with a title like something.
repeat(iterable, count);
Repeat the iterable count times, or infinite times if count is omitted.
#### album("something");
files(folder = "path/to/music", recursive = true|false, regex = "pattern");
Retrieve all files from a folder, matching a regex pattern.
Retrieve all songs in the database with an album title like something.
#### artist("something");
Retrieve all songs in the database with an artist name like something.
#### genre("something");
Retrieve all songs in the database with a genre title like something.
#### repeat(iterable, count);
Repeat the iterable count times, or infinite times if count is omitted.
#### files(folder = "path/to/music", recursive = true|false, regex = "pattern");
Retrieve all files from a folder, matching a regex pattern.
License: LGPL-2.1-only OR GPL-2.0-or-later

View file

@ -44,70 +44,83 @@
//! Filters are statements of the format `something.(predicate)`, where "something" is a variable name or another valid statement, and "predicate" is a valid filter predicate (see below).
//! E.g. `files(folder="~/Music/", recursive=true).(title == "Romantic Traffic");` is valid filter syntax to filter all songs in the Music folder for songs named "Romantic Traffic" (probably just one song).
//!
//! field == something
//! field != something
//! field >= something
//! field > something
//! field <= something
//! field < something -- e.g. `iterable.(title == "Romantic Traffic");`
//! ### field == something
//!
//! Compare all items, keeping only those that match the condition. Valid field names are those of the MpsMusicItem (title, artist, album, genre, track, etc.), though this will change when proper object support is added. Optionally, a ? or ! can be added to the end of the field name to skip items whose field is missing/incomparable, or keep all items whose field is missing/incomparable (respectively).
//! ### field != something
//!
//! start..end -- e.g. `iterable.(0..42);`
//! ### field >= something
//!
//! Keep only the items that are at the start index up to the end index. Start and/or end may be omitted to start/stop at the iterable's existing start/end (respectively). This stops once the end condition is met, leaving the rest of the iterator unconsumed.
//! ### field > something
//!
//! start..=end -- e.g. `iterable.(0..=42);`
//! ### field <= something
//!
//! Keep only the items that are at the start index up to and including the end index. Start may be omitted to start at the iterable's existing start. This stops once the end condition is met, leaving the rest of the iterator unconsumed.
//! ### field < something -- e.g. `iterable.(title == "Romantic Traffic");`
//!
//! index -- e.g. `iterable.(4);`
//! Compare all items, keeping only those that match the condition. Valid field names are those of the MpsMusicItem (title, artist, album, genre, track, etc.), though this will change when proper object support is added. Optionally, a ? or ! can be added to the end of the field name to skip items whose field is missing/incomparable, or keep all items whose field is missing/incomparable (respectively).
//!
//! Keep only the item at the given index. This stops once the index is reached, leaving the rest of the iterator unconsumed.
//! ### start..end -- e.g. `iterable.(0..42);`
//!
//! predicate1 || predicate2 -- e.g. `iterable.(4 || 5);`
//! Keep only the items that are at the start index up to the end index. Start and/or end may be omitted to start/stop at the iterable's existing start/end (respectively). This stops once the end condition is met, leaving the rest of the iterator unconsumed.
//!
//! Keep only the items that meet the criteria of predicate1 or predicate2. This will always consume the full iterator.
//! ### start..=end -- e.g. `iterable.(0..=42);`
//!
//! [empty] -- e.g. `iterable.();`
//! Keep only the items that are at the start index up to and including the end index. Start may be omitted to start at the iterable's existing start. This stops once the end condition is met, leaving the rest of the iterator unconsumed.
//!
//! Matches all items
//! ### index -- e.g. `iterable.(4);`
//!
//! if filter: operation1 else operation2 -- e.g. `iterable.(if title == "Romantic Traffic": repeat(item, 2) else item.());`
//! Keep only the item at the given index. This stops once the index is reached, leaving the rest of the iterator unconsumed.
//!
//! Replace items matching the filter with operation1 and replace items not matching the filter with operation2. The `else operation2` part may be omitted to preserve items not matching the filter. To perform operations with the current item, use the special variable `item`.
//! ### predicate1 || predicate2 -- e.g. `iterable.(4 || 5);`
//!
//! Keep only the items that meet the criteria of predicate1 or predicate2. This will always consume the full iterator.
//!
//! ### [empty] -- e.g. `iterable.();`
//!
//! Matches all items
//!
//! ### if filter: operation1 else operation2 -- e.g. `iterable.(if title == "Romantic Traffic": repeat(item, 2) else item.());`
//!
//! Replace items matching the filter with operation1 and replace items not matching the filter with operation2. The `else operation2` part may be omitted to preserve items not matching the filter. To perform operations with the current item, use the special variable `item`. The replacement filter may not contain || -- instead, use multiple filters chained together.
//!
//! ## Functions
//! Similar to most other languages: `function_name(param1, param2, etc.);`.
//! These always return an iterable which can me manipulated.
//! These always return an iterable which can be manipulated.
//! Functions are statements of the format `function_name(params)`, where "function_name" is one of the function names (below) and params is a valid parameter input for the function.
//! Each function is responsible for parsing it's own parameters when the statement is parsed, so this is very flexible.
//! E.g. `files(folder="~/Music/", recursive=true);` is valid function syntax to execute the files function with parameters `folder="~/Music/", recursive=true`.
//!
//!
//! sql_init(generate = true|false, folder = "path/to/music");
//! Initialize the SQLite database connection using the provided parameters. This must be performed before any other database operation (otherwise the database will already be connected with default settings).
//! ### sql_init(generate = true|false, folder = "path/to/music");
//!
//! sql("SQL query here");
//! Perform a raw SQLite query on the database which MPS auto-generates. An iterator of the results is returned.
//! Initialize the SQLite database connection using the provided parameters. This must be performed before any other database operation (otherwise the database will already be connected with default settings).
//!
//! song("something");
//! Retrieve all songs in the database with a title like something.
//! ### sql("SQL query here");
//!
//! album("something");
//! Retrieve all songs in the database with an album title like something.
//! Perform a raw SQLite query on the database which MPS auto-generates. An iterator of the results is returned.
//!
//! artist("something");
//! Retrieve all songs in the database with an artist name like something.
//! ### song("something");
//!
//! genre("something");
//! Retrieve all songs in the database with a genre title like something.
//! Retrieve all songs in the database with a title like something.
//!
//! repeat(iterable, count);
//! Repeat the iterable count times, or infinite times if count is omitted.
//! ### album("something");
//!
//! files(folder = "path/to/music", recursive = true|false, regex = "pattern");
//! Retrieve all files from a folder, matching a regex pattern.
//! Retrieve all songs in the database with an album title like something.
//!
//! ### artist("something");
//!
//! Retrieve all songs in the database with an artist name like something.
//!
//! ### genre("something");
//!
//! Retrieve all songs in the database with a genre title like something.
//!
//! ### repeat(iterable, count);
//!
//! Repeat the iterable count times, or infinite times if count is omitted.
//!
//! ### files(folder = "path/to/music", recursive = true|false, regex = "pattern");
//!
//! Retrieve all files from a folder, matching a regex pattern.
//!
mod context;

View file

@ -7,7 +7,7 @@ To view the currently-supported operations, try ?functions and ?filters";
pub const FUNCTIONS: &str =
"FUNCTIONS (?functions)
Similar to most other languages: function_name(param1, param2, etc.)
These always return an iterable which can me manipulated.
These always return an iterable which can be manipulated.
sql_init(generate = true|false, folder = `path/to/music`)
Initialize the SQLite database connection using the provided parameters. This must be performed before any other database operation (otherwise the database will already be connected with default settings).
@ -61,4 +61,4 @@ Operations to reduce the items in an iterable: iterable.(filter)
Matches all items
if filter: operation1 else operation2 -- e.g. iterable.(if title == `Romantic Traffic`: repeat(item, 2) else item.())
Replace items matching the filter with operation1 and replace items not matching the filter with operation2. The `else operation2` part may be omitted to preserve items not matching the filter. To perform operations with the current item, use the special variable `item`.";
Replace items matching the filter with operation1 and replace items not matching the filter with operation2. The `else operation2` part may be omitted to preserve items not matching the filter. To perform operations with the current item, use the special variable `item`. The replacement filter may not contain || -- instead, use multiple filters chained together.";