-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
421efc0
commit c436368
Showing
17 changed files
with
169 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use super::{ClassWalker, ClientWalker, ConfigurationWalker, EnumWalker, Walker}; | ||
use crate::{ | ||
ast::{self, WithName}, | ||
printer::{serialize_with_printer, WithSerializeableContent}, | ||
types::FunctionType, | ||
ParserDatabase, WithSerialize, | ||
}; | ||
use either::Either; | ||
use internal_baml_schema_ast::ast::{ArgumentId, Identifier, ValExpId, WithIdentifier, WithSpan}; | ||
|
||
pub type ArgWalker<'db> = super::Walker<'db, (ValExpId, bool, ArgumentId)>; | ||
|
||
impl<'db> ArgWalker<'db> { | ||
/// The ID of the function in the db | ||
pub fn function_id(self) -> ast::ValExpId { | ||
self.id.0 | ||
} | ||
|
||
/// The AST node. | ||
pub fn ast_function(self) -> &'db ast::ValueExprBlock { | ||
&self.db.ast[self.id.0] | ||
} | ||
|
||
/// The AST node. | ||
pub fn ast_arg(self) -> (Option<&'db Identifier>, &'db ast::BlockArg) { | ||
match self.id.1 { | ||
true => { | ||
let args = self.ast_function().input(); | ||
let res = &args.expect("Expected input args")[self.id.2]; | ||
(Some(&res.0), &res.1) | ||
} | ||
|
||
false => { | ||
let output = self.ast_function().output(); | ||
let res = output.expect("Error: Output is undefined for function ID"); | ||
(None, res) | ||
} | ||
} | ||
} | ||
|
||
/// The name of the type. | ||
pub fn field_type(self) -> &'db ast::FieldType { | ||
&self.ast_arg().1.field_type | ||
} | ||
|
||
/// The name of the function. | ||
pub fn is_optional(self) -> bool { | ||
self.field_type().is_nullable() | ||
} | ||
|
||
/// The name of the function. | ||
pub fn required_enums(self) -> impl Iterator<Item = EnumWalker<'db>> { | ||
let (input, output) = &self.db.types.function[&self.function_id()].dependencies; | ||
if self.id.1 { input } else { output } | ||
.iter() | ||
.filter_map(|f| match self.db.find_type_by_str(f) { | ||
Some(Either::Left(_cls)) => None, | ||
Some(Either::Right(walker)) => Some(walker), | ||
None => None, | ||
}) | ||
} | ||
|
||
/// The name of the function. | ||
pub fn required_classes(self) -> impl Iterator<Item = ClassWalker<'db>> { | ||
let (input, output) = &self.db.types.function[&self.function_id()].dependencies; | ||
if self.id.1 { input } else { output } | ||
.iter() | ||
.filter_map(|f| match self.db.find_type_by_str(f) { | ||
Some(Either::Left(walker)) => Some(walker), | ||
Some(Either::Right(_enm)) => None, | ||
None => None, | ||
}) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ function AudioInput(aud: audio) -> string{ | |
} | ||
|
||
|
||
|
||
test TestURLAudioInput{ | ||
functions [AudioInput] | ||
args { | ||
|
6 changes: 0 additions & 6 deletions
6
integ-tests/baml_src/test-files/functions/input/named-args/syntax.baml
This file was deleted.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.