Slide 15
Slide 15 text
パーサを作っていく
● BNFを見ながらパーサコンビネータに落としていく
○ 型定義を厳密にしたかったので構文木の型定義も
function_declaration ::=
function [ lifetime ] function_body_declaration
#[tracable_parser]
#[packrat_parser]
pub(crate) fn function_declaration(s: Span) -> IResult {
let (s, a) = keyword("function")(s)?;
let (s, b) = opt(lifetime)(s)?;
let (s, c) = function_body_declaration(s)?;
Ok((s, FunctionDeclaration { nodes: (a, b, c) }))
}
#[derive(Clone, Debug, PartialEq, Node)]
pub struct FunctionDeclaration {
pub nodes: (Keyword, Option, FunctionBodyDeclaration),
}