Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
Haio::Cli::Lexer Namespace Reference

Namespaces

namespace  Detail

Classes

struct  Rule
struct  Note
struct  Option
struct  Word

Enumerations

enum class  Opt {
  Size , Crop , CropRect , Resize ,
  Radius , Format , PixFmt , Filter ,
  Limit , Palette , Fx
}

Functions

constexpr std::optional< Word > optionOf (std::string_view token)

Variables

const auto paren = x3::string("\\‍(") | x3::string("\\‍)") | x3::string("(") | x3::string(")")
const auto singleQuoted = x3::lexeme['\'' >> *(x3::char_ - '\'') >> '\'']
const auto doubleQuoted = x3::lexeme['"' >> *(('\\' >> x3::char_) | (x3::char_ - '"')) >> '"']
const auto word = x3::lexeme[+(x3::char_ - x3::space - '"' - '\'' - '(' - ')')]
const auto arg = x3::raw[singleQuoted | doubleQuoted | paren | word]
const auto cmdline = x3::skip(x3::space)[*arg]
constexpr std::array ebnfRules
constexpr Option options []
constexpr std::string_view generatorKinds [] = {"xc", "canvas", "gradient", "radial-gradient"}
constexpr auto commandRules
constexpr std::array notes

Class Documentation

◆ Haio::Cli::Lexer::Rule

struct Haio::Cli::Lexer::Rule

Definition at line 23 of file haio_cli_grammar.hpp.

Class Members
string_view expression
string_view name

◆ Haio::Cli::Lexer::Note

struct Haio::Cli::Lexer::Note

Definition at line 28 of file haio_cli_grammar.hpp.

Class Members
string_view text

◆ Haio::Cli::Lexer::Option

struct Haio::Cli::Lexer::Option

every option the convert line takes, and how many words follow each.

it is a table because the same facts were written down three times: as an if in the parser, as a rule in the grammar this file documents, and as a line in the usage text. three copies of one list is three chances to disagree, and they did – "--size" was in the grammar and in the usage and in neither branch of the parser, and "--palette=cga" went looking for its value in the next word along, because the equals sign was only ever matched against the spelling the error message used.

the count is the part that matters. reading an option is the same work whatever it means: take the words the table says it takes, from after an equals sign or from one along, and hand them to whoever knows what they are for. that last step is the only thing particular to the option, and it is all the parser's switch is left doing.

Definition at line 75 of file haio_cli_grammar.hpp.

Class Members
int args = 1

how many words follow it

bool filter = true

whether it is one of the filters, which is what the grammar calls the options that may repeat between the source and the output. -size is not one: it belongs to the generator that has to follow it.

string_view help
Opt kind
bool optional = false

... and whether it can do without them, which only -crop can

string_view rule

the name this option's rule has in the grammar

array< string_view, 4 > spellings

every spelling it answers to; the first is the one the usage text shows

string_view takes

and the rule the words after it have to match

◆ Haio::Cli::Lexer::Word

struct Haio::Cli::Lexer::Word

an option, the spelling it arrived as, and whatever an equals sign carried with it

Definition at line 150 of file haio_cli_grammar.hpp.

Collaboration diagram for Haio::Cli::Lexer::Word:
Class Members
bool hasValue = false
const Option * option = nullptr
string_view spelling
string_view value

Enumeration Type Documentation

◆ Opt

enum class Haio::Cli::Lexer::Opt
strong

which option a word turned out to name, so that a spelling is recognised once, by the table below, rather than by whichever branch of the parser gets to it first.

Enumerator
Size 
Crop 
CropRect 
Resize 
Radius 
Format 
PixFmt 
Filter 
Limit 
Palette 
Fx 

Definition at line 45 of file haio_cli_grammar.hpp.

Function Documentation

◆ optionOf()

std::optional< Word > Haio::Cli::Lexer::optionOf ( std::string_view token)
constexpr

the option a word names, or nothing when it names none.

"-resize=8x8" and "-resize 8x8" are one thing said two ways, so the equals sign is split off here rather than inside each option's own branch: whoever matched a spelling by hand had to remember this too, and one of them did not.

Definition at line 164 of file haio_cli_grammar.hpp.

Here is the call graph for this function:

Variable Documentation

◆ arg

const auto Haio::Cli::Lexer::arg = x3::raw[singleQuoted | doubleQuoted | paren | word]
inline

Definition at line 20 of file haio_cli_grammar.hpp.

◆ cmdline

const auto Haio::Cli::Lexer::cmdline = x3::skip(x3::space)[*arg]
inline

Definition at line 21 of file haio_cli_grammar.hpp.

◆ commandRules

auto Haio::Cli::Lexer::commandRules
inlineconstexpr
Initial value:
=
consteval auto joined(const std::array< Rule, A > &a, const std::array< Rule, B > &b, const std::array< Rule, C > &c)
constexpr std::array leafRules
constexpr std::array structureRules

Definition at line 314 of file haio_cli_grammar.hpp.

◆ doubleQuoted

const auto Haio::Cli::Lexer::doubleQuoted = x3::lexeme['"' >> *(('\\' >> x3::char_) | (x3::char_ - '"')) >> '"']
inline

Definition at line 18 of file haio_cli_grammar.hpp.

◆ ebnfRules

std::array Haio::Cli::Lexer::ebnfRules
inlineconstexpr
Initial value:
= {
Rule{"paren", R"ebnf("\‍(" | "\)" | "(" | ")")ebnf"},
Rule{"single-quoted", R"("'" , { any-character - "'" } , "'")"},
Rule{"double-quoted", R"ebnf(""" , { "\" , any-character | any-character - """ } , """)ebnf"},
Rule{"word", R"(non-empty-token-without-space-quote-or-paren)"},
Rule{"arg", "single-quoted | double-quoted | paren | word"},
Rule{"cmdline", "{ arg }"},
}

Definition at line 32 of file haio_cli_grammar.hpp.

◆ generatorKinds

std::string_view Haio::Cli::Lexer::generatorKinds[] = {"xc", "canvas", "gradient", "radial-gradient"}
inlineconstexpr

the generators, which are a prefix on the source rather than an option of their own

Definition at line 181 of file haio_cli_grammar.hpp.

◆ notes

std::array Haio::Cli::Lexer::notes
inlineconstexpr
Initial value:
= {
Note{"`png:-` and `ppm:-` use stdin/stdout with an explicit format."},
Note{"an unknown prefix such as `foo:bar.png` is parsed as a normal path."},
Note{"every option takes its words after a space or after an `=`; the two are the same thing."},
Note{"`-size` is valid only when followed by a generator source, so an option written between the two is an error."},
Note{"generator sources are parsed but currently rejected during pipeline construction."},
Note{"`-fx` expressions are parsed but currently rejected during pipeline construction."},
Note{"`-crop` is the one option whose argument is optional; without geometry it creates a default crop token, which the current c++ pipeline rejects until a default crop operation is defined."},
Note{"`-filter` and `-limit` are settings: they wait for the operation that uses them, and a line that ends with one still waiting is an error."},
Note{"`-pix_fmt` names the colour stored inside the output, the way ffmpeg's option does; the container still comes from the output path or `-format`."},
Note{"naming a colour a container cannot store is an error rather than a silent conversion."},
Note{"`raw:out.bin` with a `-pix_fmt` writes the pixels themselves, which is the only way to ask for a colour with no container around it."},
Note{"the format and colour names above are generated from the enums, so they are whatever this build can actually do."},
}

Definition at line 317 of file haio_cli_grammar.hpp.

◆ options

Option Haio::Cli::Lexer::options[]
inlineconstexpr

Definition at line 103 of file haio_cli_grammar.hpp.

◆ paren

const auto Haio::Cli::Lexer::paren = x3::string("\\‍(") | x3::string("\\‍)") | x3::string("(") | x3::string(")")
inline

Definition at line 16 of file haio_cli_grammar.hpp.

◆ singleQuoted

const auto Haio::Cli::Lexer::singleQuoted = x3::lexeme['\'' >> *(x3::char_ - '\'') >> '\'']
inline

Definition at line 17 of file haio_cli_grammar.hpp.

◆ word

const auto Haio::Cli::Lexer::word = x3::lexeme[+(x3::char_ - x3::space - '"' - '\'' - '(' - ')')]
inline

Definition at line 19 of file haio_cli_grammar.hpp.