mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
None literal 🕳
This commit is contained in:
parent
32af3095f8
commit
77c06ebc24
@ -176,6 +176,7 @@ impl Eval for Spanned<&Lit> {
|
|||||||
Value::Error
|
Value::Error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Lit::None => Value::None,
|
||||||
Lit::Bool(v) => Value::Bool(v),
|
Lit::Bool(v) => Value::Bool(v),
|
||||||
Lit::Int(v) => Value::Int(v),
|
Lit::Int(v) => Value::Int(v),
|
||||||
Lit::Float(v) => Value::Float(v),
|
Lit::Float(v) => Value::Float(v),
|
||||||
|
@ -326,6 +326,7 @@ fn value(p: &mut Parser) -> Option<Expr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Basic values.
|
// Basic values.
|
||||||
|
Some(Token::None) => Expr::Lit(Lit::None),
|
||||||
Some(Token::Bool(b)) => Expr::Lit(Lit::Bool(b)),
|
Some(Token::Bool(b)) => Expr::Lit(Lit::Bool(b)),
|
||||||
Some(Token::Int(i)) => Expr::Lit(Lit::Int(i)),
|
Some(Token::Int(i)) => Expr::Lit(Lit::Int(i)),
|
||||||
Some(Token::Float(f)) => Expr::Lit(Lit::Float(f)),
|
Some(Token::Float(f)) => Expr::Lit(Lit::Float(f)),
|
||||||
|
@ -614,6 +614,7 @@ fn test_parse_values() {
|
|||||||
t!("{name}" Block(Id("name")));
|
t!("{name}" Block(Id("name")));
|
||||||
t!("{ke-bab}" Block(Id("ke-bab")));
|
t!("{ke-bab}" Block(Id("ke-bab")));
|
||||||
t!("{α}" Block(Id("α")));
|
t!("{α}" Block(Id("α")));
|
||||||
|
t!("{none}" Block(Expr::Lit(Lit::None)));
|
||||||
t!("{true}" Block(Bool(true)));
|
t!("{true}" Block(Bool(true)));
|
||||||
t!("{false}" Block(Bool(false)));
|
t!("{false}" Block(Bool(false)));
|
||||||
t!("{1.0e-4}" Block(Float(1e-4)));
|
t!("{1.0e-4}" Block(Float(1e-4)));
|
||||||
|
@ -294,6 +294,7 @@ impl<'s> Tokens<'s> {
|
|||||||
self.s.eat_while(is_id_continue);
|
self.s.eat_while(is_id_continue);
|
||||||
let string = self.s.eaten_from(start);
|
let string = self.s.eaten_from(start);
|
||||||
match string {
|
match string {
|
||||||
|
"none" => Token::None,
|
||||||
"true" => Token::Bool(true),
|
"true" => Token::Bool(true),
|
||||||
"false" => Token::Bool(false),
|
"false" => Token::Bool(false),
|
||||||
_ => Token::Ident(string),
|
_ => Token::Ident(string),
|
||||||
@ -377,6 +378,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::parse::tests::check;
|
use crate::parse::tests::check;
|
||||||
|
|
||||||
|
use Option::None;
|
||||||
use Token::{
|
use Token::{
|
||||||
BlockComment as BC, Ident as Id, LeftBrace as LB, LeftBracket as L,
|
BlockComment as BC, Ident as Id, LeftBrace as LB, LeftBracket as L,
|
||||||
LeftParen as LP, LineComment as LC, RightBrace as RB, RightBracket as R,
|
LeftParen as LP, LineComment as LC, RightBrace as RB, RightBracket as R,
|
||||||
@ -679,7 +681,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tokenize_bools() {
|
fn test_tokenize_keywords() {
|
||||||
|
// Test none.
|
||||||
|
t!(Header[" /"]: "none" => Token::None);
|
||||||
|
t!(Header[" /"]: "None" => Id("None"));
|
||||||
|
|
||||||
// Test valid bools.
|
// Test valid bools.
|
||||||
t!(Header[" /"]: "false" => Bool(false));
|
t!(Header[" /"]: "false" => Bool(false));
|
||||||
t!(Header[" /"]: "true" => Bool(true));
|
t!(Header[" /"]: "true" => Bool(true));
|
||||||
|
@ -108,6 +108,8 @@ pub type ExprContent = Tree;
|
|||||||
pub enum Lit {
|
pub enum Lit {
|
||||||
/// A identifier literal: `left`.
|
/// A identifier literal: `left`.
|
||||||
Ident(Ident),
|
Ident(Ident),
|
||||||
|
/// The none literal: `none`.
|
||||||
|
None,
|
||||||
/// A boolean literal: `true`, `false`.
|
/// A boolean literal: `true`, `false`.
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
/// An integer literal: `120`.
|
/// An integer literal: `120`.
|
||||||
|
@ -63,6 +63,8 @@ pub enum Token<'s> {
|
|||||||
|
|
||||||
/// An identifier: `center`.
|
/// An identifier: `center`.
|
||||||
Ident(&'s str),
|
Ident(&'s str),
|
||||||
|
/// A none: `none`.
|
||||||
|
None,
|
||||||
/// A boolean: `true`, `false`.
|
/// A boolean: `true`, `false`.
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
/// An integer: `120`.
|
/// An integer: `120`.
|
||||||
@ -152,6 +154,7 @@ impl<'s> Token<'s> {
|
|||||||
Self::Slash => "slash",
|
Self::Slash => "slash",
|
||||||
|
|
||||||
Self::Ident(_) => "identifier",
|
Self::Ident(_) => "identifier",
|
||||||
|
Self::None => "none",
|
||||||
Self::Bool(_) => "bool",
|
Self::Bool(_) => "bool",
|
||||||
Self::Int(_) => "integer",
|
Self::Int(_) => "integer",
|
||||||
Self::Float(_) => "float",
|
Self::Float(_) => "float",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user