struct InputStream<R: Read> {
    reader: R,
    location: SourceLocation,
    saved_ch: char,
    saved_location: SourceLocation,
    saved_token: Option<Token>,
    spaces: u32,
}
Expand description

A high-level wrapper around a stream, used to parse scene files (yaml formatted).

This class implements a wrapper around a stream,
with the following additional capabilities:

  • It tracks the line number and column number;
  • It permits to “unread” characters and tokens;
  • It tracks the number of spaces that build up a indent block.

Fields§

§reader: R

A stream that implement Read trait.

§location: SourceLocation

A location pointer.

§saved_ch: char

Last saved char.

§saved_location: SourceLocation

Last saved location.

§saved_token: Option<Token>

Last saved token.

§spaces: u32

Spaces that build up an indent block.

Implementations§

source§

impl<R: Read> InputStream<R>

source

pub fn new(reader: R) -> Self

Create a new InputStream from a stream that implement Read trait.

source

fn update_pos(&mut self, ch: char)

Update location after having read char from the stream.

source

fn read_char(&mut self) -> char

Read a new character from the stream.

source

fn unread_char(&mut self, ch: char)

Push a character back to the stream.

source

fn skip_comment(&mut self)

If a comment character (for yaml is #) is found,
skip all the next ones until an end-of-line (\n) or end-of-file (\x00).

source

fn skip_whitespaces_and_comments(&mut self)

Keep reading characters until a non-whitespace/non-comment character is found.

source

fn count_spaces(&mut self) -> Result<(), SceneErr>

Count spaces that build up a particular indent block.
See parse_colors for example of usage.

source

fn parse_string( &mut self, token_location: SourceLocation, delimiter: char ) -> Result<Token, SceneErr>

Parse string token Token::String.

source

fn parse_float( &mut self, first_char: char, token_location: SourceLocation ) -> Result<Token, SceneErr>

Parse literal number (always as f32) token Token::LiteralNumber.

source

fn parse_keyword_or_identifier( &mut self, first_char: char, token_location: SourceLocation ) -> Token

Parse a keyword token Token::Keyword or an identifier token Token::Identifier.

source

fn read_token(&mut self) -> Result<Token, SceneErr>

Read a Token from the stream.

If successful return a particular variant of Token enum wrapped inside Result.
Otherwise return an error of type SceneErr::InvalidCharacter.

source

fn unread_token(&mut self, token: Token)

Make as if token were never read from stream.

source

fn match_symbol(&mut self, symbol: char) -> Result<(), SceneErr>

Read a token from stream and check that it matches Token::Symbol.
Otherwise return a SceneErr::NotMatch error.

source

fn match_eol_or_inline_comment(&mut self) -> Result<(), SceneErr>

Match an eof-of-inline or an inline comment, othewise return SceneErr::NotMatch error.

source

fn match_whitespaces_and_comments(&mut self) -> Result<(), SceneErr>

Match whitespaces or an comments, othewise return SceneErr::NotMatch error.
Unread the token, and skip nothing only if Token::Keyword was parsed.

source

fn match_spaces(&mut self, level: u32, nested: u32) -> Result<(), SceneErr>

Match the correct number of spaces for the current indent block.
Otherwise return a SceneErr::NotMatch error.

source

fn match_keyword(&mut self, keyword: Keywords) -> Result<(), SceneErr>

Read a token from stream and check that it matches Token::Keyword and
a particular keywords Keywords. Otherwise return a SceneErr::NotMatch error.

source

fn match_keywords( &mut self, keywords: &Vec<Keywords> ) -> Result<Keywords, SceneErr>

Read a token from stream and check that it matches Token::Keyword and
a particular range of keywords Keywords. Return, wrapped inside a Result, the keyword.
Otherwise return a SceneErr::NotMatch error.

source

fn match_identifier(&mut self) -> Result<(SourceLocation, String), SceneErr>

Read a token from stream and check that it matches Token::Identifier.
Return, wrapped inside a Result, the identifier location and value.
Otherwise return a SceneErr::NotMatch error.

source

fn match_string(&mut self) -> Result<(SourceLocation, String), SceneErr>

Read a token from stream and check that it matches Token::String.
Return, wrapped inside a Result, the string value and its location.
Otherwise return a SceneErr::NotMatch error.

source

fn match_number(&mut self) -> Result<f32, SceneErr>

Read a token from stream and check that it matches Token::LiteralNumber.
Return, wrapped inside a Result, the number value.
Otherwise return a SceneErr::NotMatch error.

source

fn match_number_cli(&mut self, cli: Cli) -> Result<f32, SceneErr>

Read a token from stream and check that it matches Token::LiteralNumber or a Token::Identifier
with a particular string instance, that if match means that f32 number must be read from cli.
Return, wrapped inside a Result, the number value.
Otherwise return a SceneErr::NotMatch error.

source

fn parse_color(&mut self, var: &Var) -> Result<Color, SceneErr>

Parse a rgb color Color from stream combining previous match methods.
A color could be also read from a Token::Identifier if its string match a particular key of var.colors map.
Otherwise return a variant of SceneErr error.

source

fn parse_vector(&mut self, var: &Var) -> Result<Vector, SceneErr>

Parse an xyz vector Vector from stream combining previous match methods.
Otherwise return a SceneErr::NotMatch error.

source

fn parse_color_name( &mut self, colors: &mut BTreeMap<String, Color>, var: &Var ) -> Result<(), SceneErr>

Parse a color from colors block combining parse_color and put it inside var.colors map.
Otherwise return a variant of SceneErr error.

source

fn parse_colors( &mut self, var: &Var ) -> Result<BTreeMap<String, Color>, SceneErr>

Parse colors inside colors block iterating parse_color_name until the block end.
Otherwise return a variant of SceneErr error.

source

fn parse_pigment(&mut self, nested: u32, var: &Var) -> Result<Pigment, SceneErr>

Parse a pigment Pigment from stream combining previous match and parse methods.
Otherwise return a variant of SceneErr error.

source

fn parse_brdf(&mut self, var: &Var) -> Result<BRDF, SceneErr>

Parse a brdf BRDF from stream combining previous match methods.
Otherwise return a variant of SceneErr error.

source

fn parse_material( &mut self, materials: &mut BTreeMap<String, Material>, var: &Var ) -> Result<(), SceneErr>

Parse a material Material inside materials block combining parse_pigment and parse_brdf.
And put it inside var.materials map.
Otherwise return a variant of SceneErr error.

source

fn parse_materials( &mut self, var: &Var ) -> Result<BTreeMap<String, Material>, SceneErr>

Parse materials inside materials block iterating parse_material until the block end.
Otherwise return a variant of SceneErr error.

source

fn parse_transformation( &mut self, transformations: &BTreeMap<String, Transformation>, var: &Var ) -> Result<Transformation, SceneErr>

Parse a transformation Transformation from stream combining previous match methods.
Otherwise return a SceneErr::NotMatch error.

source

fn parse_composed_transformation( &mut self, transformations: &mut BTreeMap<String, Transformation>, var: &Var ) -> Result<(), SceneErr>

Compose multiple transformation Transformation into one iterating over parse_transformation.
And put it inside var.transformations map.
Otherwise return a variant of SceneErr error.

source

fn parse_transformations( &mut self, var: &Var ) -> Result<BTreeMap<String, Transformation>, SceneErr>

Parse transformations inside transformations block iterating parse_composed_transformation until the block end.
Otherwise return a variant of SceneErr error.

source

fn parse_shape( &mut self, var: &Var ) -> Result<Box<dyn RayIntersection>, SceneErr>

Parse shape inside shapes block using var.materials and var.transformations.
Otherwise return a variant of SceneErr error.

source

fn parse_shapes(&mut self, var: &Var) -> Result<World, SceneErr>

Parse shapes inside shapes block iterating parse_shape until the block end.
Otherwise return a variant of SceneErr error.

source

fn parse_camera(&mut self, var: &Var, cli: Cli) -> Result<Camera, SceneErr>

Parse camera inside camera block using var.materials and var.transformations,
and optionally for particular identifiers read standard values from cli.
Otherwise return a variant of SceneErr error.

source

fn parse_scene(&mut self, cli: Cli) -> Result<Scene, SceneErr>

Parse a scene in all its entirety.

Blocks that must exist:

  • camera;
  • materials;
  • shapes.

Optionals:

  • colors;
  • transformations.

Blocks can be separated by multiple break line.

When a camera and world (list of shapes) are parsed stop scene parsing.

Trait Implementations§

source§

impl<R: Clone + Read> Clone for InputStream<R>

source§

fn clone(&self) -> InputStream<R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for InputStream<R>
where R: RefUnwindSafe,

§

impl<R> Send for InputStream<R>
where R: Send,

§

impl<R> Sync for InputStream<R>
where R: Sync,

§

impl<R> Unpin for InputStream<R>
where R: Unpin,

§

impl<R> UnwindSafe for InputStream<R>
where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.