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

Classes

struct  continue_site
 A continue= option, its name resolved once every line is read. More...
 
struct  directive_site
 Where a insignificant directive names a mode. More...
 
struct  fragment
 A fragment line: a named pattern for continue=. More...
 
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...
 
class  indent_meter
 Measures the bytes of a source between the start of the line holding an offset and it, over offsets that mostly increase: each byte is read once from the last offset measured, so a pass over a long line stays linear (measured from its line's start at every token, 40 000 entries on one line took 2.5 s). More...
 
struct  line_extras
 The options of a line that name another line, or make it a fragment, resolved once every line is read. More...
 
struct  predicate_site
 An after= or not_after= option, its names resolved once every rule is read. 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, std::size_t index, std::vector< predicate_site > &predicates, line_extras &extras)
 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.
 
void resolve_predicates (grammar &parsed, const std::vector< predicate_site > &sites, const std::string &origin)
 Gives each rule of sites the kinds its names stand for: every rule bearing the name, and scilex::end_of_input for ^.
 
void resolve_continuations (grammar &parsed, const std::vector< fragment > &fragments, const std::vector< continue_site > &sites, const std::string &origin)
 Gives each rule of sites the pattern its continue= names: the fragment of that name, else the first rule of that name.
 
void parse_directive (std::string_view line, std::size_t first, const std::string &origin, std::size_t number, std::vector< directive_site > &sites)
 Parses the directive line (its % at 0-based first): insignificant m1,m2.
 
void apply_directives (grammar &parsed, const std::vector< directive_site > &sites, const std::string &origin)
 Records the modes of sites in parsed, refusing one no rule is active in, at its column.
 
std::vector< token > layout_pass (std::span< const token > tokens, const std::vector< bool > &mode_significant, const layout_roles &roles, const std::string_view *source, tab_policy tabs)
 

Function Documentation

◆ apply_directives()

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

Records the modes of sites in parsed, refusing one no rule is active in, at its column.

Exceptions
grammar_errorFor the first such mode.

◆ 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,
std::size_t  index,
std::vector< predicate_site > &  predicates,
line_extras &  extras 
)
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.
[in]indexThe rule's index (for its after= / not_after= entry).
[in,out]predicatesEach after= / not_after= option, appended with its names unresolved.
[out]extrasIts fragment and continue= options.
Returns
The 1-based column of its push= or set= option, or 0 when it has none.
Exceptions
grammar_errorOn an unknown option or value, an empty mode name, a second transition, or an option the line gives twice.

◆ 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 layout_roles &  roles,
const std::string_view *  source,
tab_policy  tabs 
)
inline

◆ parse_directive()

void scilex::detail::parse_directive ( std::string_view  line,
std::size_t  first,
const std::string &  origin,
std::size_t  number,
std::vector< directive_site > &  sites 
)
inline

Parses the directive line (its % at 0-based first): insignificant m1,m2.

Parameters
[in]lineThe line, trailing blanks already removed.
[in]firstWhere the % is.
[in]originFor errors: where the grammar came from.
[in]numberFor errors: the 1-based line.
[in,out]sitesEach named mode is appended, with where it is written.
Exceptions
grammar_errorOn another directive, or an empty or malformed mode list.

◆ 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.

◆ resolve_continuations()

void scilex::detail::resolve_continuations ( grammar &  parsed,
const std::vector< fragment > &  fragments,
const std::vector< continue_site > &  sites,
const std::string &  origin 
)
inline

Gives each rule of sites the pattern its continue= names: the fragment of that name, else the first rule of that name.

Exceptions
grammar_errorAt the option, for a rule without extend=lines or a name nothing bears.

◆ resolve_predicates()

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

Gives each rule of sites the kinds its names stand for: every rule bearing the name, and scilex::end_of_input for ^.

Exceptions
grammar_errorAt the option, for a name no rule bears.

◆ 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.