Trait oursh::program::Program

source ·
pub trait Program: Sized + Debug + Run {
    type Command: Command;

    // Required methods
    fn parse<R: BufRead>(reader: R) -> Result<Self>;
    fn commands(&self) -> &[Self::Command];
}
Expand description

A program is as large as a file or as small as a line.

Each program is to be treated as a complete single language entity, with the explicit exception of {#} blocks, which act as bridges between programs.

Working Thoughts

  • Is simply iterating a collection of commands really the correct semantics for all the types of programs we want?
  • What language information do we still need to store?

Required Associated Types§

source

type Command: Command

The type of each of this program’s commands.

Required Methods§

source

fn parse<R: BufRead>(reader: R) -> Result<Self>

Parse a whole program from the given reader.

source

fn commands(&self) -> &[Self::Command]

Return a list of all the commands in this program.

Implementors§

source§

impl Program for oursh::program::basic::Program

source§

impl Program for oursh::program::posix::ast::Program

The syntax and semantics of a single POSIX command.

use std::io::Read;
use oursh::program::Program as ProgramTrait;
use oursh::program::posix::ast::Program;

assert!(Program::parse(b"ls" as &[u8]).is_ok());