use luau_lexer::prelude::Token;
use luau_parser_derive::{Print, Range};
use crate::types::{Block, BracketedList, GenericDeclaration, Pointer, TableAccessKey, TypeValue};
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Range, Print)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct LocalFunction {
pub attributes: Vec<Attribute>,
pub local_keyword: Token,
pub function_keyword: Token,
pub function_name: Token,
pub generics: Option<Pointer<GenericDeclaration>>,
pub parameters: BracketedList<Parameter>,
pub colon: Option<Pointer<Token>>,
pub return_type: Option<Pointer<TypeValue>>,
pub body: Block,
pub end_keyword: Token,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Range, Print)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Parameter {
pub name: Token,
pub colon: Option<Token>,
#[range_or = "name"]
pub r#type: Option<Pointer<TypeValue>>,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Range, Print)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Attribute {
pub at: Token,
pub attribute: Token,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Print)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum GlobalFunctionName {
SimpleName(Token),
Table {
table: Token,
keys: Vec<TableAccessKey>,
method: Option<Pointer<(Token, Token)>>,
},
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Range, Print)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct GlobalFunction {
pub attributes: Vec<Attribute>,
pub function_keyword: Token,
pub function_name: GlobalFunctionName,
pub generics: Option<Pointer<GenericDeclaration>>,
pub parameters: BracketedList<Parameter>,
pub colon: Option<Pointer<Token>>,
pub return_type: Option<Pointer<TypeValue>>,
pub body: Block,
pub end_keyword: Token,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Range, Print)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct TypeFunction {
#[range_or = "type_keyword"]
pub export_keyword: Option<Token>,
pub type_keyword: Token,
pub function_keyword: Token,
pub function_name: Token,
pub generics: Option<Pointer<GenericDeclaration>>,
pub parameters: BracketedList<Parameter>,
pub colon: Option<Pointer<Token>>,
pub return_type: Option<Pointer<TypeValue>>,
pub body: Block,
pub end_keyword: Token,
}