Skip to main content

Module parse

Module parse 

Source
Expand description

This module provides parse_fragment, which parses FLM source text into a Fragment, along with its options (ParseOptions) and the errors that it returns (FragmentError).

parse_fragment parses one source with a built language: the language that crate::lang::build creates from the definitions declared in the registry. You usually obtain the built language with FlmRegistry::lang. The returned Fragment contains the parsed tree, the source, and the diagnostics reported during the parse. To parse a document made of several files, use crate::model::assemble.

A parse starts from a parsing state: the scope stack of packages that resolves the commands, the rules of the tokenizer, and the parsing mode. parse_fragment starts from the initial state of the built language (BuiltLang::initial_state); parse_fragment_with_state starts from a state that the caller derives from it with BuiltLang::derive_state, for instance with a scoped package added or with a scope stack of its own built from BuiltLang::base_scope. Every parse runs techy’s standard root parser, whatever its state. A parse also has a standard state, which an argument or a body restores when its declaration carries the event StandardScope or StandardState: the initial state of the built language, unless ParseOptions::standard_state sets another one.

A parse is tolerant: the parser reports each problem in the source as a diagnostic, stores the diagnostic in the fragment, and continues. The tree covers the whole input. A parse returns no tree only in the cases listed in FragmentError, and an error in the syntax of the document causes none of these cases.

The caller passes the source as an Arc<FlmSource>, not as a string. The source contains its origin, and the canonical path of the origin identifies the source. For instance, the parser of \input uses the canonical path to detect a file that includes itself, and an embedding program can use it as the key of its own tables of sources.

A parse runs on a worker thread: a thread that declared its stack size, from which the recursion guard takes its budget. If the calling thread is not a worker thread, the parse functions run the parse on a new worker thread, so the caller does not need to create one. See on_worker_thread.

Structs§

AbortCondition
The error that is reported when a parse was aborted because of an error in the program (id flm.lang.parse-aborted).
ParseOptions
The settings of one parse that can differ from the settings of the built language.
WorkerThreadUnavailable
The error that is reported when the operating system fails to create a worker thread for a parse (id flm.lang.worker-thread-unavailable).

Enums§

FragmentError
The error that a parse returns when it cannot produce a tree.

Functions§

parse_fragment
Parses source with the built language lang, and returns the resulting fragment.
parse_fragment_with_state
Parses source with the built language lang, starting from the parsing state state, and returns the resulting fragment.