[][src]Trait rune::Parse

pub trait Parse where
    Self: Sized
{ fn parse(parser: &mut Parser<'_>) -> Result<Self, ParseError>; }

The parse trait, implemented by items that can be parsed.

Required methods

fn parse(parser: &mut Parser<'_>) -> Result<Self, ParseError>

Parse the current item from the parser.

Loading content...

Implementations on Foreign Types

impl<A, B> Parse for (A, B) where
    A: Parse + Peek,
    B: Parse
[src]

impl<T> Parse for Option<T> where
    T: Parse + Peek, 
[src]

Parse implementation for something that can be optionally parsed.

impl<T> Parse for Box<T> where
    T: Parse
[src]

Parse implementation for something that is boxed.

impl<T> Parse for Vec<T> where
    T: Parse + Peek, 
[src]

Parser implementation for a vector.

Loading content...

Implementors

impl Parse for Condition[src]

Parse a condition.

Examples

use rune::{parse_all, ast};

parse_all::<ast::Condition>("true")?;
parse_all::<ast::Condition>("let [a, ..] = v")?;

impl Parse for Decl[src]

impl Parse for DeclStructBody[src]

Parse implementation for a struct body.

Examples

use rune::{parse_all, ast};

parse_all::<ast::DeclStructBody>("").unwrap();
parse_all::<ast::DeclStructBody>("( a, b, c )").unwrap();
parse_all::<ast::DeclStructBody>("{ a, b, c }").unwrap();

impl Parse for DeclUseComponent[src]

impl Parse for Expr[src]

Parsing a block expression.

Examples

use rune::{parse_all, ast};

parse_all::<ast::Expr>("foo[\"foo\"]").unwrap();
parse_all::<ast::Expr>("foo.bar()").unwrap();
parse_all::<ast::Expr>("var()").unwrap();
parse_all::<ast::Expr>("var").unwrap();
parse_all::<ast::Expr>("42").unwrap();
parse_all::<ast::Expr>("1 + 2 / 3 - 4 * 1").unwrap();
parse_all::<ast::Expr>("foo[\"bar\"]").unwrap();
parse_all::<ast::Expr>("let var = 42").unwrap();
parse_all::<ast::Expr>("let var = \"foo bar\"").unwrap();
parse_all::<ast::Expr>("var[\"foo\"] = \"bar\"").unwrap();
parse_all::<ast::Expr>("let var = objects[\"foo\"] + 1").unwrap();
parse_all::<ast::Expr>("var = 42").unwrap();

let expr = parse_all::<ast::Expr>(r#"
    if 1 { } else { if 2 { } else { } }
"#).unwrap();

if let ast::Expr::ExprIf(..) = expr.item {
} else {
    panic!("not an if statement");
}

// Chained function calls.
parse_all::<ast::Expr>("foo.bar.baz()").unwrap();
parse_all::<ast::Expr>("foo[0][1][2]").unwrap();
parse_all::<ast::Expr>("foo.bar()[0].baz()[1]").unwrap();

parse_all::<ast::Expr>("42 is int::int").unwrap();

impl Parse for ExprBreakValue[src]

impl Parse for FnArg[src]

impl Parse for LitObjectIdent[src]

impl Parse for LitObjectKey[src]

Parse an object literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitObjectKey>("foo")?;
parse_all::<ast::LitObjectKey>("\"foo \\n bar\"")?;

impl Parse for Pat[src]

Parsing a block expression.

Examples

use rune::{parse_all, ast};

parse_all::<ast::Pat>("()").unwrap();
parse_all::<ast::Pat>("1").unwrap();
parse_all::<ast::Pat>("'a'").unwrap();
parse_all::<ast::Pat>("\"hello world\"").unwrap();
parse_all::<ast::Pat>("var").unwrap();
parse_all::<ast::Pat>("_").unwrap();
parse_all::<ast::Pat>("Foo(n)").unwrap();

impl Parse for And[src]

impl Parse for Async[src]

impl Parse for Await[src]

impl Parse for Break[src]

impl Parse for CloseBrace[src]

impl Parse for CloseBracket[src]

impl Parse for CloseParen[src]

impl Parse for Colon[src]

impl Parse for Comma[src]

impl Parse for DeclEnum[src]

Parse implementation for an enum.

Examples

use rune::{parse_all, ast};

parse_all::<ast::DeclEnum>("enum Foo { Bar(a), Baz(b), Empty() }").unwrap();

impl Parse for DeclFile[src]

Parse a file.

Examples

use rune::{parse_all, ast};

parse_all::<ast::DeclFile>(r#"
use foo;

fn foo() {
    42
}

use bar;

fn bar(a, b) {
    a
}
"#).unwrap();

Realistic Example

use rune::{parse_all, ast};

parse_all::<ast::DeclFile>(r#"
use http;

fn main() {
    let client = http::client();
    let response = client.get("https://google.com");
    let text = response.text();
}
"#).unwrap();

impl Parse for DeclFn[src]

Parse implementation for a function.

Examples

use rune::{ParseAll, parse_all, ast, Resolve as _};

parse_all::<ast::DeclFn>("async fn hello() {}").unwrap();
assert!(parse_all::<ast::DeclFn>("fn async hello() {}").is_err());

let ParseAll { item, .. } = parse_all::<ast::DeclFn>("fn hello() {}").unwrap();
assert_eq!(item.args.items.len(), 0);

let ParseAll  { source, item } = parse_all::<ast::DeclFn>("fn hello(foo, bar) {}").unwrap();
assert_eq!(item.args.items.len(), 2);
assert_eq!(item.name.resolve(source).unwrap(), "hello");

impl Parse for DeclImpl[src]

Parse implementation for an impl.

Examples

use rune::{parse_all, ast};

parse_all::<ast::DeclImpl>("impl Foo {}").unwrap();
parse_all::<ast::DeclImpl>("impl Foo { fn test(self) { } }").unwrap();

impl Parse for DeclStruct[src]

Parse implementation for a struct.

Examples

use rune::{parse_all, ast};

parse_all::<ast::DeclStruct>("struct Foo").unwrap();
parse_all::<ast::DeclStruct>("struct Foo ( a, b, c )").unwrap();
parse_all::<ast::DeclStruct>("struct Foo { a, b, c }").unwrap();

impl Parse for DeclUse[src]

Parsing an use declaration.

Examples

use rune::{parse_all, ast};

parse_all::<ast::DeclUse>("use foo;")?;
parse_all::<ast::DeclUse>("use foo::bar;")?;
parse_all::<ast::DeclUse>("use foo::bar::baz;")?;

impl Parse for Default[src]

impl Parse for Dot[src]

impl Parse for DotDot[src]

impl Parse for Else[src]

impl Parse for EmptyBody[src]

Parse implementation for an empty struct body.

Examples

use rune::{parse_all, ast};

parse_all::<ast::EmptyBody>("Foo").unwrap();

impl Parse for Enum[src]

impl Parse for Eq[src]

impl Parse for ExprAwait[src]

impl Parse for ExprBlock[src]

Parse implementation for a block.

Examples

use rune::{parse_all, ast};

let block = parse_all::<ast::ExprBlock>("{}")?.item;
assert_eq!(block.exprs.len(), 0);
assert!(block.trailing_expr.is_none());

let block = parse_all::<ast::ExprBlock>("{ foo }")?.item;
assert_eq!(block.exprs.len(), 0);
assert!(block.trailing_expr.is_some());

let block = parse_all::<ast::ExprBlock>("{ foo; }")?.item;
assert_eq!(block.exprs.len(), 1);
assert!(block.trailing_expr.is_none());

let block = parse_all::<ast::ExprBlock>(r#"
    {
        let foo = 42;
        let bar = "string";
        baz
    }
"#)?.item;
assert_eq!(block.exprs.len(), 2);
assert!(block.trailing_expr.is_some());

impl Parse for ExprBreak[src]

impl Parse for ExprClosure[src]

Parse implementation for a function.

Examples

use rune::{parse_all, ast};

parse_all::<ast::ExprClosure>("async || 42").unwrap();
parse_all::<ast::ExprClosure>("|| 42").unwrap();
parse_all::<ast::ExprClosure>("|| { 42 }").unwrap();

impl Parse for ExprElse[src]

impl Parse for ExprElseIf[src]

impl Parse for ExprFor[src]

impl Parse for ExprGroup[src]

impl Parse for ExprIf[src]

Parse an if statement.

Examples

use rune::{parse_all, ast};

parse_all::<ast::ExprIf>("if 0 {  }")?;
parse_all::<ast::ExprIf>("if 0 {  } else {  }")?;
parse_all::<ast::ExprIf>("if 0 {  } else if 0 {  } else {  }")?;
parse_all::<ast::ExprIf>("if let v = v {  }")?;

impl Parse for ExprIs[src]

impl Parse for ExprIsNot[src]

impl Parse for ExprLet[src]

impl Parse for ExprLoop[src]

impl Parse for ExprMatch[src]

Parse a match statement.

Examples

use rune::{ParseAll, parse_all, ast};

parse_all::<ast::ExprMatch>("match 0 { _ => 1, }")?;

impl Parse for ExprMatchBranch[src]

Parse a match statement.

Examples

use rune::{ParseAll, parse_all, ast};

parse_all::<ast::ExprMatchBranch>("1 => { foo }")?;

impl Parse for ExprReturn[src]

impl Parse for ExprSelect[src]

impl Parse for ExprUnary[src]

Parse a unary statement.

Examples

use rune::{parse_all, ast};

parse_all::<ast::ExprUnary>("!0").unwrap();
parse_all::<ast::ExprUnary>("*foo").unwrap();
parse_all::<ast::ExprUnary>("&foo").unwrap();

impl Parse for ExprWhile[src]

impl Parse for ExprYield[src]

impl Parse for Fn[src]

impl Parse for For[src]

impl Parse for Hash[src]

impl Parse for Ident[src]

impl Parse for If[src]

impl Parse for Impl[src]

impl Parse for In[src]

impl Parse for Is[src]

impl Parse for Label[src]

impl Parse for Let[src]

impl Parse for LitBool[src]

Parsing a unit literal

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitBool>("true").unwrap();
parse_all::<ast::LitBool>("false").unwrap();

impl Parse for LitByte[src]

Parse a byte literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitByte>("b'a'").unwrap();
parse_all::<ast::LitByte>("b'\\0'").unwrap();
parse_all::<ast::LitByte>("b'\\n'").unwrap();
parse_all::<ast::LitByte>("b'\\r'").unwrap();
parse_all::<ast::LitByte>("b'\\\\''").unwrap();

impl Parse for LitByteStr[src]

Parse a string literal.

Examples

use rune::{parse_all, ast};

let s = parse_all::<ast::LitByteStr>("b\"hello world\"")?;
assert_eq!(&s.resolve()?[..], &b"hello world"[..]);

let s = parse_all::<ast::LitByteStr>("b\"hello\\nworld\"")?;
assert_eq!(&s.resolve()?[..], &b"hello\nworld"[..]);

impl Parse for LitChar[src]

Parse a character literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitChar>("'a'")?;
parse_all::<ast::LitChar>("'\\0'")?;
parse_all::<ast::LitChar>("'\\n'")?;
parse_all::<ast::LitChar>("'\\r'")?;
parse_all::<ast::LitChar>("'\\''")?;

impl Parse for LitNumber[src]

Parse a number literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitNumber>("42")?;
parse_all::<ast::LitNumber>("42.42")?;
parse_all::<ast::LitNumber>("0.42")?;
parse_all::<ast::LitNumber>("0.42e10")?;

impl Parse for LitObject[src]

Parse an object literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitObject>("Foo {\"foo\": 42}").unwrap();
parse_all::<ast::LitObject>("#{\"foo\": 42}").unwrap();
parse_all::<ast::LitObject>("#{\"foo\": 42,}").unwrap();

impl Parse for LitObjectFieldAssign[src]

Parse an object literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitObjectFieldAssign>("\"foo\": 42").unwrap();
parse_all::<ast::LitObjectFieldAssign>("\"foo\": 42").unwrap();
parse_all::<ast::LitObjectFieldAssign>("\"foo\": 42").unwrap();

impl Parse for LitStr[src]

Parse a string literal.

Examples

use rune::{ParseAll, parse_all, ast};

let item = parse_all::<ast::LitStr>("\"hello world\"")?;
assert_eq!(item.resolve()?, "hello world");

let item = parse_all::<ast::LitStr>("\"hello\\nworld\"")?;
assert_eq!(item.resolve()?, "hello\nworld");

impl Parse for LitTemplate[src]

Parse a string literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitTemplate>("`hello world`")?;
parse_all::<ast::LitTemplate>("`hello\\n world`")?;

impl Parse for LitTuple[src]

Parse a tuple literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitTuple>("(1, \"two\")").unwrap();
parse_all::<ast::LitTuple>("(1, 2,)").unwrap();
parse_all::<ast::LitTuple>("(1, 2, foo())").unwrap();

impl Parse for LitUnit[src]

Parsing a unit literal

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitUnit>("()").unwrap();

impl Parse for LitVec[src]

Parse an array literal.

Examples

use rune::{parse_all, ast};

parse_all::<ast::LitVec>("[1, \"two\"]").unwrap();
parse_all::<ast::LitVec>("[1, 2,]").unwrap();
parse_all::<ast::LitVec>("[1, 2, foo()]").unwrap();

impl Parse for Loop[src]

impl Parse for Match[src]

impl Parse for Mul[src]

impl Parse for Not[src]

impl Parse for OpenBrace[src]

impl Parse for OpenBracket[src]

impl Parse for OpenParen[src]

impl Parse for Or[src]

impl Parse for PatObject[src]

impl Parse for PatObjectItem[src]

impl Parse for PatTuple[src]

impl Parse for PatVec[src]

impl Parse for Path[src]

impl Parse for Pipe[src]

impl Parse for Return[src]

impl Parse for Rocket[src]

impl Parse for Scope[src]

impl Parse for Select[src]

impl Parse for Self_[src]

impl Parse for SemiColon[src]

impl Parse for Star[src]

impl Parse for Struct[src]

impl Parse for StructBody[src]

Parse implementation for a struct body.

Examples

use rune::{parse_all, ast};

parse_all::<ast::StructBody>("{ a, b, c }").unwrap();

impl Parse for Try[src]

impl Parse for TupleBody[src]

Parse implementation for a struct body.

Examples

use rune::{parse_all, ast};

parse_all::<ast::TupleBody>("( a, b, c )").unwrap();

impl Parse for Underscore[src]

impl Parse for Use[src]

impl Parse for While[src]

impl Parse for Yield[src]

impl<T, S> Parse for Parenthesized<T, S> where
    T: Parse,
    S: Peek + Parse
[src]

Parse function arguments.

Examples

use rune::{parse_all, ast};

parse_all::<ast::Parenthesized<ast::Expr, ast::Comma>>("(1, \"two\")")?;
parse_all::<ast::Parenthesized<ast::Expr, ast::Comma>>("(1, 2,)")?;
parse_all::<ast::Parenthesized<ast::Expr, ast::Comma>>("(1, 2, foo())")?;
Loading content...