[][src]Struct saltwater::PreProcessor

pub struct PreProcessor<'a> { /* fields omitted */ }

A preprocessor does textual substitution and deletion on a C source file.

The C preprocessor, or cpp, is tightly tied to C tokenization. Rules for tokenizing identifiers, operators, and literals are all the same, so you can't use it to preprocess e.g. Haskell, where a' is a valid identifier.

The preprocessor is further tied to the lexer because it is whitespace dependent: #define a() b is not the same as #define a () b. The first is a function-like macro; the second is an object-like macro.

The preprocessor has no concept of scope: everything is either defined or not defined. Variables can only be defined as strings, or more accurately, token sequences.

It is possible to tell the difference between an undefined variable and a variable defined to be empty using #ifdef var and #if var.

Examples:

use saltwater::PreProcessor;

let cpp = PreProcessor::new("int main(void) { char *hello = \"hi\"; }\n", "example.c", false, vec![], Default::default());
for token in cpp {
    assert!(token.is_ok());
}

Implementations

impl<'a> PreProcessor<'a>[src]

pub fn new<'search: 'a, I: IntoIterator<Item = Cow<'search, Path>>, S: Into<Rc<str>>>(
    chars: S,
    filename: impl Into<OsString>,
    debug: bool,
    user_search_path: I,
    user_definitions: HashMap<InternedStr, Definition>
) -> Self
[src]

Create a new preprocessor for the file identified by file.

Note that the preprocessor may add arbitrarily many #included files to files, but will never delete a file.

The debug parameter specifies whether to print out tokens before replacement.

pub fn warnings(&mut self) -> VecDeque<CompileWarning>[src]

Return all warnings found so far.

These warnings are consumed and will not be returned if you call warnings() again.

pub fn eof(&self) -> Location[src]

pub fn into_files(self) -> Files[src]

pub fn cpp_expr<L>(
    definitions: &Definitions,
    lex_tokens: L,
    location: Location
) -> CompileResult<Expr> where
    L: Iterator<Item = Locatable<Token>>, 
[src]

A C expression on a single line. Used for #if directives.

Note that identifiers are replaced with a constant 0, as per 6.10.1.

pub fn next_non_whitespace(
    &mut self
) -> Option<Result<Locatable<Token>, CompileError>>
[src]

Returns next token in stream which is not whitespace

Trait Implementations

impl<'_> Iterator for PreProcessor<'_>[src]

type Item = Result<Locatable<Token>, CompileError>

The preprocessor hides all internal complexity and returns only tokens.

Auto Trait Implementations

impl<'a> !RefUnwindSafe for PreProcessor<'a>

impl<'a> !Send for PreProcessor<'a>

impl<'a> !Sync for PreProcessor<'a>

impl<'a> Unpin for PreProcessor<'a>

impl<'a> !UnwindSafe for PreProcessor<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<I> IteratorRandom for I where
    I: Iterator
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,