-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js: Parse simple function declarations
- Loading branch information
1 parent
49e3b61
commit c95c806
Showing
8 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
crates/js/src/parser/functions_and_classes/function_definitions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! <https://262.ecma-international.org/14.0/#sec-function-definitions> | ||
use crate::{ | ||
bytecode::{self, CompileToBytecode}, | ||
parser::{ | ||
identifiers::parse_binding_identifier, script::Statement, tokenizer::Punctuator, | ||
SyntaxError, Tokenizer, | ||
}, | ||
}; | ||
|
||
/// <https://262.ecma-international.org/14.0/#prod-FunctionDeclaration> | ||
#[derive(Clone, Debug)] | ||
pub struct FunctionDeclaration { | ||
pub identifier: String, | ||
pub body: Vec<Statement>, | ||
} | ||
|
||
impl FunctionDeclaration { | ||
/// <https://262.ecma-international.org/14.0/#prod-FunctionDeclaration> | ||
pub fn parse<const YIELD: bool, const AWAIT: bool, const DEFAULT: bool>( | ||
tokenizer: &mut Tokenizer<'_>, | ||
) -> Result<Self, SyntaxError> { | ||
tokenizer.expect_keyword("function")?; | ||
|
||
let identifier = parse_binding_identifier::<YIELD, AWAIT>(tokenizer)?; | ||
tokenizer.expect_punctuator(Punctuator::ParenthesisOpen)?; | ||
tokenizer.expect_punctuator(Punctuator::ParenthesisClose)?; | ||
tokenizer.expect_punctuator(Punctuator::CurlyBraceOpen)?; | ||
tokenizer.expect_punctuator(Punctuator::CurlyBraceClose)?; | ||
|
||
let body = vec![]; | ||
|
||
let function_declaration = Self { identifier, body }; | ||
|
||
Ok(function_declaration) | ||
} | ||
} | ||
|
||
impl CompileToBytecode for FunctionDeclaration { | ||
fn compile(&self, builder: &mut bytecode::Builder) { | ||
_ = builder; | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//! <https://262.ecma-international.org/14.0/#sec-ecmascript-language-functions-and-classes> | ||
mod function_definitions; | ||
mod parameter_lists; | ||
|
||
pub(crate) use function_definitions::FunctionDeclaration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//! <https://262.ecma-international.org/14.0/#prod-FormalParameters> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters