|
FE 0.13.1
Header-only C++ frontend library
|
The blueprint for a lexer with a buffer of K tokens to peek into the future (Lexer::ahead).
More...
#include <fe/lexer.h>
Classes | |
| struct | Ahead |
| A decoded code point together with the byte range it occupies. More... | |
Public Member Functions | |
| Lexer (std::string_view buf) | |
| Lexer (const Src &src) | |
Protected Member Functions | |
| Lexer (std::string_view buf, const Src *src) | |
| Delegate here to funnel both of the above into a single ctor of your own. | |
| char32_t | ahead (size_t i=0) const |
| Loc | peek () const |
| Location of the next character to be consumed (Lexer::ahead()); empty once the buffer is exhausted. | |
| void | start () |
| Invoke before assembling the next token. | |
| char32_t | next () |
| Get next char32_t in Lexer::buf_ and extend Lexer::loc_ to cover it. | |
Recover | |
Lexer::next input that cannot be part of a token, report it, and keep the current lexer going. Invoke after Lexer::start, so Lexer::loc_ spans exactly what was discarded. | |
| bool | recover_utf8 () |
| void | recover_char () |
| One character, reported as S::char_err. | |
Diagnostics | |
The defaults | |
| void | utf8_err () |
| void | char_err (char32_t c) |
Lexer::recover_char discarded c at Lexer::loc_. | |
Protected Attributes | |
| std::string_view | buf_ |
| const Src * | src_ |
| size_t | cursor_ = 0 |
| Byte offset of the first not yet decoded character. | |
| Ring< Ahead, K > | ahead_ |
| Loc | loc_ |
| Location of the token we are currently constructing within Lexer::str_,. | |
| std::string | str_ |
Accept | |
Accept next character in Lexer::buf_, depending on some condition. | |
| enum class | Append { Off , On , Lower , Upper } |
| template<Append append = Append::On, class Pred> | |
| bool | accept (Pred pred) |
| template<Append append = Append::On> | |
| bool | accept (char32_t c) |
| template<Append append = Append::On> | |
| bool | accept (char c) |
| template<Append append = Append::On> | |
| bool | accept (char8_t c) |
The blueprint for a lexer with a buffer of K tokens to peek into the future (Lexer::ahead).
You can "override" Lexer::next via CRTP (S is the child). The whole source has to sit in buf: a Pos is an index into it, so there is nothing left to keep track of - Lexer::next just hands out the byte range the code point it consumed occupied. S must provide somewhere to report to:
Lexer::utf8_err and Lexer::char_err come with a default; declare either in S to word it differently.
| struct fe::Lexer::Ahead |
|
strongprotected |
What should happen to the accepted char? Normalize identifiers via Append::Lower or Append::Upper for case-insensitive languages like FORTRAN or SQL.
| Enumerator | |
|---|---|
| Off | Do not append accepted char to Lexer::str_. |
| On | Append accepted char as is to Lexer::str_. |
| Lower | Append accepted char via fe::utf8::tolower` to Lexer::str_. |
| Upper | Append accepted char via fe::utf8::toupper` to Lexer::str_. |
|
inline |
|
inlineprotected |
pred holds. In this case invoke Lexer::next() and append to Lexer::str_, if append. Definition at line 91 of file lexer.h.
References ahead(), Lower, Off, str_, fe::utf8::tolower(), fe::utf8::toupper(), and Upper.
Referenced by accept(), accept(), accept(), and recover_utf8().
|
inlineprotected |
Definition at line 58 of file lexer.h.
References ahead_.
Referenced by accept(), and recover_char().
|
inlineprotected |
Lexer::recover_char discarded c at Lexer::loc_.
Definition at line 146 of file lexer.h.
References loc_.
|
inlineprotected |
Get next char32_t in Lexer::buf_ and extend Lexer::loc_ to cover it.
Definition at line 71 of file lexer.h.
References ahead_, fe::Loc::end, and loc_.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
Lexer::recover_utf8 discarded the malformed bytes at Lexer::loc_.
Definition at line 138 of file lexer.h.
References loc_.
|
protected |
|
protected |
Location of the token we are currently constructing within Lexer::str_,.
Definition at line 158 of file lexer.h.
Referenced by char_err(), next(), start(), and utf8_err().
|
protected |