SciLex
A header-only C++20 lexer built on REAL
Loading...
Searching...
No Matches
Classes | Functions
scilex::detail Namespace Reference

Classes

struct  grammar_fields
 The fields of one rule line, split on tabs, with the byte column each starts at. More...
 
struct  indent_measure
 A line's indentation under tab_policy::python (tab stops of 8, and tabs as 1). More...
 
struct  transition_site
 Where a rule's push= or set= option is written. More...
 

Functions

std::string quoting (std::string_view before, std::string_view word, std::string_view after)
 before, then word in quotes, then after: a cause naming the offending word.
 
grammar_fields split_grammar_line (std::string_view line, std::size_t first)
 Splits line on tabs, from first (0-based), keeping each field's column.
 
std::string_view checked_mode (std::string_view name, std::string_view word, const std::string &origin, std::size_t line, std::size_t column)
 name, refused when it is empty or holds a comma (which separates the modes of in=).
 
void set_transition (rule &out, mode_action::op operation, std::string_view target, const std::string &origin, std::size_t line, std::size_t column)
 Gives out its transition, refusing a second one.
 
std::size_t apply_grammar_options (std::string_view options, std::size_t column, const std::string &origin, std::size_t line, rule &out)
 Applies the space-separated options of one rule to out.
 
void check_transition_targets (const grammar &parsed, const std::vector< transition_site > &sites, const std::string &origin)
 Refuses a push= or set= whose mode no rule is active in, at the option.
 
indent_measure measure_indent (std::string_view source, std::size_t offset)
 Measures the bytes of source between the start of the line holding offset and it.
 
std::vector< token > layout_pass (std::span< const token > tokens, const std::vector< bool > &mode_significant, const std::string_view *source, tab_policy tabs)
 

Function Documentation

◆ apply_grammar_options()

std::size_t scilex::detail::apply_grammar_options ( std::string_view  options,
std::size_t  column,
const std::string &  origin,
std::size_t  line,
rule &  out 
)
inline

Applies the space-separated options of one rule to out.

Parameters
[in]optionsThe options field.
[in]columnThe 1-based column the field starts at.
[in]originFor errors: where the grammar came from.
[in]lineFor errors: the 1-based line.
[in,out]outThe rule being built.
Returns
The 1-based column of its push= or set= option, or 0 when it has none.
Exceptions
grammar_errorOn an unknown option, an empty mode name, or a second transition.

◆ check_transition_targets()

void scilex::detail::check_transition_targets ( const grammar &  parsed,
const std::vector< transition_site > &  sites,
const std::string &  origin 
)
inline

Refuses a push= or set= whose mode no rule is active in, at the option.

Parameters
[in]parsedThe grammar.
[in]sitesWhere each push= and set= is written.
[in]originFor errors: where the grammar came from.
Exceptions
grammar_errorFor the first such transition.

◆ checked_mode()

std::string_view scilex::detail::checked_mode ( std::string_view  name,
std::string_view  word,
const std::string &  origin,
std::size_t  line,
std::size_t  column 
)
inline

name, refused when it is empty or holds a comma (which separates the modes of in=).

Parameters
[in]nameA mode name from an option.
[in]wordFor errors: the whole option.
[in]originFor errors: where the grammar came from.
[in]lineFor errors: the 1-based line.
[in]columnFor errors: the 1-based column of the option.
Returns
name.
Exceptions
grammar_errorWhen name is empty or holds a comma.

◆ layout_pass()

std::vector< token > scilex::detail::layout_pass ( std::span< const token >  tokens,
const std::vector< bool > &  mode_significant,
const std::string_view *  source,
tab_policy  tabs 
)
inline

◆ measure_indent()

indent_measure scilex::detail::measure_indent ( std::string_view  source,
std::size_t  offset 
)
inline

Measures the bytes of source between the start of the line holding offset and it.

◆ quoting()

std::string scilex::detail::quoting ( std::string_view  before,
std::string_view  word,
std::string_view  after 
)
inline

before, then word in quotes, then after: a cause naming the offending word.

Parameters
[in]beforeThe text before the word.
[in]wordThe offending word.
[in]afterThe text after it.
Returns
The cause.

◆ set_transition()

void scilex::detail::set_transition ( rule &  out,
mode_action::op  operation,
std::string_view  target,
const std::string &  origin,
std::size_t  line,
std::size_t  column 
)
inline

Gives out its transition, refusing a second one.

Parameters
[in,out]outThe rule being built.
[in]operationThe transition.
[in]targetThe mode it enters (empty for pop).
[in]originFor errors: where the grammar came from.
[in]lineFor errors: the 1-based line.
[in]columnFor errors: the 1-based column of the option.
Exceptions
grammar_errorWhen out already has a transition.

◆ split_grammar_line()

grammar_fields scilex::detail::split_grammar_line ( std::string_view  line,
std::size_t  first 
)
inline

Splits line on tabs, from first (0-based), keeping each field's column.

Parameters
[in]lineThe line, trailing blanks already removed.
[in]firstWhere the first field starts.
Returns
The fields.