Crate scnr

Source
Expand description

§scnr

The ‘scnr’ crate is a library that provides lexical scanner for programming languages. It is designed to be used in a parser of a compiler or interpreter for a programming language or in similar tools that require lexical analysis, e.g. in a language server. It provides multiple scanner modes out of the box, which can be switched at runtime depending on the context of the input. A parser can use different modes for different parts of the input, e.g. to scan comments in one mode and code in another. The scanner is designed to be fast and efficient, and it is implemented with the help of finite state machines. To parse the given regular expressions, the crate uses the regex-syntax crate.

Structs§

  • An iterator over all non-overlapping matches.
  • A lookahead is used to restrict a match in the input. The lookahead is a regular expression whose condition must be met after the pattern itself for it to be considered a match. The lookahead can be positive or negative.
  • A match in the haystack.
  • A match with line and column information for start and end positions.
  • A pattern that is used to match the input. The pattern is represented by a regular expression and a token type number. The token type number is used to identify the pattern in the scanner. The pattern also has an optional lookahead.
  • A position in the haystack. The position is represented by a line and column number. The line and column numbers are 1-based.
  • A Scanner. It consists of multiple DFAs resp. NFAs that are used to search for matches.
  • A builder for creating a scanner.
  • A scanner mode that can be used to scan specific parts of the input. It has a name and a set of patterns that are valid token types in this mode. The scanner mode can also have transitions to other scanner modes triggered by a token type.
  • The error type for the scrn crate.
  • A span in an input string.
  • An iterator over all non-overlapping matches with positions.

Enums§

Traits§

Type Aliases§

  • The result type for the scrn crate.