mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-19 15:41:36 +03:00
add scalar type to parser
This commit is contained in:
parent
521c04b4d6
commit
9fe4a7281b
@ -294,6 +294,7 @@ impl ParserContext<'_> {
|
||||
assert_no_whitespace("group")?;
|
||||
Expression::Value(ValueExpression::Group(Box::new(GroupValue::Single(value, full_span))))
|
||||
}
|
||||
// todo @collinc97 parse scalar type here.
|
||||
// Literal followed by other type suffix, e.g., `42u8`.
|
||||
Some(suffix) => {
|
||||
assert_no_whitespace(&suffix.to_string())?;
|
||||
|
@ -18,6 +18,10 @@ use super::*;
|
||||
use leo_errors::Result;
|
||||
|
||||
pub(crate) const TYPE_TOKENS: &[Token] = &[
|
||||
Token::Address,
|
||||
Token::Bool,
|
||||
Token::Field,
|
||||
Token::Group,
|
||||
Token::I8,
|
||||
Token::I16,
|
||||
Token::I32,
|
||||
@ -28,11 +32,8 @@ pub(crate) const TYPE_TOKENS: &[Token] = &[
|
||||
Token::U32,
|
||||
Token::U64,
|
||||
Token::U128,
|
||||
Token::Field,
|
||||
Token::Group,
|
||||
Token::Address,
|
||||
Token::Bool,
|
||||
Token::Char,
|
||||
Token::Scalar,
|
||||
];
|
||||
|
||||
impl ParserContext<'_> {
|
||||
@ -59,11 +60,12 @@ impl ParserContext<'_> {
|
||||
let span = self.expect_any(TYPE_TOKENS)?;
|
||||
Ok((
|
||||
match &self.prev_token.token {
|
||||
Token::Field => Type::Field,
|
||||
Token::Group => Type::Group,
|
||||
Token::Address => Type::Address,
|
||||
Token::Bool => Type::Boolean,
|
||||
Token::Field => Type::Field,
|
||||
Token::Group => Type::Group,
|
||||
Token::Char => Type::Char,
|
||||
// todo @collin parse scalar type here.
|
||||
x => Type::IntegerType(Self::token_to_int_type(x).expect("invalid int type")),
|
||||
},
|
||||
span,
|
||||
|
@ -426,6 +426,7 @@ impl Token {
|
||||
"mut" => Token::Mut,
|
||||
"public" => Token::Public,
|
||||
"return" => Token::Return,
|
||||
"scalar" => Token::Scalar,
|
||||
"true" => Token::True,
|
||||
"type" => Token::Type,
|
||||
"u8" => Token::U8,
|
||||
|
@ -154,6 +154,7 @@ mod tests {
|
||||
let
|
||||
mut
|
||||
return
|
||||
scalar
|
||||
string
|
||||
test
|
||||
true
|
||||
@ -204,7 +205,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
output,
|
||||
r#"'a' '😭' "test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address bool const else false field for function group i128 i64 i32 i16 i8 if in input let mut return string test true u128 u64 u32 u16 u8 console ! != && ( ) * ** + , - -> _ . .. / : ; < <= = == > >= [ ] { { } } || ? // test
|
||||
r#"'a' '😭' "test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address bool const else false field for function group i128 i64 i32 i16 i8 if in input let mut return scalar string test true u128 u64 u32 u16 u8 console ! != && ( ) * ** + , - -> _ . .. / : ; < <= = == > >= [ ] { { } } || ? // test
|
||||
/* test */ // "#
|
||||
);
|
||||
});
|
||||
|
@ -91,25 +91,26 @@ pub enum Token {
|
||||
Arrow,
|
||||
Underscore,
|
||||
|
||||
// Syntactic Grammr
|
||||
// Syntactic Grammar
|
||||
// Types
|
||||
U8,
|
||||
U16,
|
||||
U32,
|
||||
U64,
|
||||
U128,
|
||||
I8,
|
||||
I16,
|
||||
I32,
|
||||
I64,
|
||||
I128,
|
||||
Address,
|
||||
Bool,
|
||||
Field,
|
||||
Group,
|
||||
Bool,
|
||||
Address,
|
||||
U8,
|
||||
U16,
|
||||
U32,
|
||||
U64,
|
||||
U128,
|
||||
Char,
|
||||
Scalar,
|
||||
|
||||
// primary expresion
|
||||
// primary expression
|
||||
Input,
|
||||
|
||||
// Regular Keywords
|
||||
@ -159,6 +160,7 @@ pub const KEYWORD_TOKENS: &[Token] = &[
|
||||
Token::Mut,
|
||||
Token::Public,
|
||||
Token::Return,
|
||||
Token::Scalar,
|
||||
Token::True,
|
||||
Token::Type,
|
||||
Token::U8,
|
||||
@ -201,6 +203,7 @@ impl Token {
|
||||
Token::Mut => sym::Mut,
|
||||
Token::Public => sym::Public,
|
||||
Token::Return => sym::Return,
|
||||
Token::Scalar => sym::scalar,
|
||||
Token::True => sym::True,
|
||||
Token::Type => sym::Type,
|
||||
Token::U8 => sym::u8,
|
||||
@ -264,21 +267,22 @@ impl fmt::Display for Token {
|
||||
Arrow => write!(f, "->"),
|
||||
Underscore => write!(f, "_"),
|
||||
|
||||
U8 => write!(f, "u8"),
|
||||
U16 => write!(f, "u16"),
|
||||
U32 => write!(f, "u32"),
|
||||
U64 => write!(f, "u64"),
|
||||
U128 => write!(f, "u128"),
|
||||
I8 => write!(f, "i8"),
|
||||
I16 => write!(f, "i16"),
|
||||
I32 => write!(f, "i32"),
|
||||
I64 => write!(f, "i64"),
|
||||
I128 => write!(f, "i128"),
|
||||
Address => write!(f, "address"),
|
||||
Bool => write!(f, "bool"),
|
||||
Field => write!(f, "field"),
|
||||
Group => write!(f, "group"),
|
||||
Bool => write!(f, "bool"),
|
||||
Address => write!(f, "address"),
|
||||
U8 => write!(f, "u8"),
|
||||
U16 => write!(f, "u16"),
|
||||
U32 => write!(f, "u32"),
|
||||
U64 => write!(f, "u64"),
|
||||
U128 => write!(f, "u128"),
|
||||
Char => write!(f, "char"),
|
||||
Scalar => write!(f, "scalar"),
|
||||
|
||||
Input => write!(f, "input"),
|
||||
|
||||
|
@ -134,6 +134,7 @@ symbols! {
|
||||
prelude,
|
||||
Public,
|
||||
Return: "return",
|
||||
scalar,
|
||||
Star: "*",
|
||||
std,
|
||||
Struct: "struct",
|
||||
|
Loading…
Reference in New Issue
Block a user