// See also: file:///usr/share/doc/python/html/reference/grammar.html?highlight=grammar // See also: https://github.com/antlr/grammars-v4/blob/master/python3/Python3.g4 // See also: file:///usr/share/doc/python/html/reference/compound_stmts.html#function-definitions // See also: https://greentreesnakes.readthedocs.io/en/latest/nodes.html#keyword use std::iter::FromIterator; use crate::ast; use crate::fstring::parse_fstring; use crate::lexer; use num_bigint::BigInt; grammar; // This is a hack to reduce the amount of lalrpop tables generated: // For each public entry point, a full parse table is generated. // By having only a single pub function, we reduce this to one. pub Top: ast::Top = { StartProgram => ast::Top::Program(p), StartStatement => ast::Top::Statement(s), StartExpression => ast::Top::Expression(e), }; Program: ast::Program = { => ast::Program { statements: Vec::from_iter(lines.into_iter().flatten()) }, }; // A file line either has a declaration, or an empty newline: FileLine: Vec = { Statement, "\n" => vec![], }; Suite: Vec = { SimpleStatement, "\n" indent dedent => s.into_iter().flatten().collect(), }; Statement: Vec = { SimpleStatement, => vec![s], }; SimpleStatement: Vec = { ";"? "\n" => { let mut statements = vec![s1]; statements.extend(s2.into_iter().map(|e| e.1)); statements } }; SmallStatement: ast::LocatedStatement = { ExpressionStatement, PassStatement, DelStatement, FlowStatement, ImportStatement, GlobalStatement, NonlocalStatement, AssertStatement, }; PassStatement: ast::LocatedStatement = { "pass" => { ast::LocatedStatement { location: loc, node: ast::Statement::Pass, } }, }; DelStatement: ast::LocatedStatement = { "del" => { ast::LocatedStatement { location: loc, node: ast::Statement::Delete { targets: e }, } }, }; ExpressionStatement: ast::LocatedStatement = { => { // Just an expression, no assignment: if suffix.is_empty() { ast::LocatedStatement { location: loc.clone(), node: ast::Statement::Expression { expression: expr } } } else { let mut targets = vec![expr]; let mut values = suffix; while values.len() > 1 { targets.push(values.remove(0)); } let value = values.into_iter().next().unwrap(); ast::LocatedStatement { location: loc.clone(), node: ast::Statement::Assign { targets, value }, } } }, => { ast::LocatedStatement { location: loc, node: ast::Statement::AugAssign { target: Box::new(expr), op, value: Box::new(rhs) }, } }, }; AssignSuffix: ast::Expression = { "=" => e, "=" => e, }; TestOrStarExprList: ast::Expression = { > => { if elements.len() == 1 && comma.is_none() { elements.into_iter().next().unwrap() } else { ast::Expression::Tuple { elements } } } }; TestOrStarExpr: ast::Expression = { Test, StarExpr, }; AugAssign: ast::Operator = { "+=" => ast::Operator::Add, "-=" => ast::Operator::Sub, "*=" => ast::Operator::Mult, "@=" => ast::Operator::MatMult, "/=" => ast::Operator::Div, "%=" => ast::Operator::Mod, "&=" => ast::Operator::BitAnd, "|=" => ast::Operator::BitOr, "^=" => ast::Operator::BitXor, "<<=" => ast::Operator::LShift, ">>=" => ast::Operator::RShift, "**=" => ast::Operator::Pow, "//=" => ast::Operator::FloorDiv, }; FlowStatement: ast::LocatedStatement = { "break" => { ast::LocatedStatement { location: loc, node: ast::Statement::Break, } }, "continue" => { ast::LocatedStatement { location: loc, node: ast::Statement::Continue, } }, "return" => { ast::LocatedStatement { location: loc, node: ast::Statement::Return { value: t.map(Box::new) }, } }, => { ast::LocatedStatement { location: loc, node: ast::Statement::Expression { expression: y }, } }, RaiseStatement, }; RaiseStatement: ast::LocatedStatement = { "raise" => { ast::LocatedStatement { location: loc, node: ast::Statement::Raise { exception: None, cause: None }, } }, "raise" => { ast::LocatedStatement { location: loc, node: ast::Statement::Raise { exception: Some(t), cause: c.map(|x| x.1) }, } }, }; ImportStatement: ast::LocatedStatement = { "import" >>> => { ast::LocatedStatement { location: loc, node: ast::Statement::Import { import_parts: i .iter() .map(|(n, a)| ast::SingleImport { module: n.to_string(), symbols: vec![], alias: a.clone(), level: 0, }) .collect() }, } }, "from" "import" => { ast::LocatedStatement { location: loc, node: ast::Statement::Import { import_parts: vec![ ast::SingleImport { module: n.0.to_string(), symbols: i.iter() .map(|(i, a)| ast::ImportSymbol { symbol: i.to_string(), alias: a.clone(), }) .collect(), alias: None, level: n.1 }] }, } }, }; ImportFromLocation: (String, usize) = { => { (name, dots.len()) }, => { ("".to_string(), dots.len()) }, }; ImportAsNames: Vec<(String, Option)> = { >> => i, "(" >> ")" => i, "*" => { // Star import all vec![("*".to_string(), None)] }, }; #[inline] ImportPart: (String, Option) = { => (i, a.map(|a| a.1)), }; // A name like abc or abc.def.ghi DottedName: String = { => n, => { let mut r = n.to_string(); for x in n2 { r.push_str("."); r.push_str(&x.1); } r }, }; GlobalStatement: ast::LocatedStatement = { "global" > => { ast::LocatedStatement { location: loc, node: ast::Statement::Global { names } } }, }; NonlocalStatement: ast::LocatedStatement = { "nonlocal" > => { ast::LocatedStatement { location: loc, node: ast::Statement::Nonlocal { names } } }, }; AssertStatement: ast::LocatedStatement = { "assert" => { ast::LocatedStatement { location: loc, node: ast::Statement::Assert { test, msg: msg.map(|e| e.1) } } }, }; CompoundStatement: ast::LocatedStatement = { IfStatement, WhileStatement, ForStatement, TryStatement, WithStatement, FuncDef, ClassDef, }; IfStatement: ast::LocatedStatement = { "if" ":" => { // Determine last else: let mut last = s3.map(|s| s.2); // handle elif: for i in s2.into_iter().rev() { let x = ast::LocatedStatement { location: i.0, node: ast::Statement::If { test: i.2, body: i.4, orelse: last }, }; last = Some(vec![x]); } ast::LocatedStatement { location: loc, node: ast::Statement::If { test, body: s1, orelse: last } } }, }; WhileStatement: ast::LocatedStatement = { "while" ":" => { let or_else = s2.map(|s| s.2); ast::LocatedStatement { location: loc, node: ast::Statement::While { test, body, orelse: or_else }, } }, }; ForStatement: ast::LocatedStatement = { "for" "in" ":" => { let orelse = s2.map(|s| s.2); ast::LocatedStatement { location: loc, node: if is_async.is_some() { ast::Statement::AsyncFor { target, iter, body, orelse } } else { ast::Statement::For { target, iter, body, orelse } }, } }, }; TryStatement: ast::LocatedStatement = { "try" ":" => { let or_else = else_suite.map(|s| s.2); let finalbody = finally.map(|s| s.2); ast::LocatedStatement { location: loc, node: ast::Statement::Try { body: body, handlers: handlers, orelse: or_else, finalbody: finalbody, }, } }, }; ExceptClause: ast::ExceptHandler = { "except" ":" => { ast::ExceptHandler { typ: typ, name: None, body: body, } }, "except" ":" => { ast::ExceptHandler { typ: Some(x.0), name: Some(x.2), body: body, } }, }; WithStatement: ast::LocatedStatement = { "with" > ":" => { ast::LocatedStatement { location: loc, node: ast::Statement::With { items: items, body: s }, } }, }; WithItem: ast::WithItem = { => { let optional_vars = n.map(|val| val.1); ast::WithItem { context_expr: t, optional_vars } }, }; FuncDef: ast::LocatedStatement = { "def" " Test)?> ":" => { ast::LocatedStatement { location: loc, node: if is_async.is_some() { ast::Statement::AsyncFunctionDef { name: i, args: a, body: s, decorator_list: d, returns: r.map(|x| x.1), } } else { ast::Statement::FunctionDef { name: i, args: a, body: s, decorator_list: d, returns: r.map(|x| x.1), } } } }, }; Parameters: ast::Parameters = { "(" )?> ")" => a.unwrap_or_else(Default::default), }; // Note that this is a macro which is used once for function defs, and // once for lambda defs. ParameterList: ast::Parameters = { > )?> ","? => { let (names, default_elements) = param1; // Now gather rest of parameters: let (vararg, kwonlyargs, kw_defaults, kwarg) = args2.map_or((None, vec![], vec![], None), |x| x.1); ast::Parameters { args: names, kwonlyargs: kwonlyargs, vararg: vararg.into(), kwarg: kwarg.into(), defaults: default_elements, kw_defaults: kw_defaults, } }, > )> ","? => { let (names, default_elements) = param1; // Now gather rest of parameters: let vararg = None; let kwonlyargs = vec![]; let kw_defaults = vec![]; let kwarg = Some(kw.1); ast::Parameters { args: names, kwonlyargs: kwonlyargs, vararg: vararg.into(), kwarg: kwarg.into(), defaults: default_elements, kw_defaults: kw_defaults, } }, > ","? => { let (vararg, kwonlyargs, kw_defaults, kwarg) = params; ast::Parameters { args: vec![], kwonlyargs: kwonlyargs, vararg: vararg.into(), kwarg: kwarg.into(), defaults: vec![], kw_defaults: kw_defaults, } }, > ","? => { ast::Parameters { args: vec![], kwonlyargs: vec![], vararg: ast::Varargs::None, kwarg: Some(kw).into(), defaults: vec![], kw_defaults: vec![], } }, }; // Use inline here to make sure the "," is not creating an ambiguity. #[inline] ParameterDefs: (Vec, Vec) = { > )*> => { // Combine first parameters: let mut args = vec![param1]; args.extend(param2.into_iter().map(|x| x.1)); let mut names = vec![]; let mut default_elements = vec![]; for (name, default) in args.into_iter() { if let Some(default) = default { default_elements.push(default); } else { if default_elements.len() > 0 { // Once we have started with defaults, all remaining arguments must // have defaults panic!( "non-default argument follows default argument: {}", &name.arg ); } } names.push(name); } (names, default_elements) } }; ParameterDef: (ast::Parameter, Option) = { => (i, None), "=" => (i, Some(e)), }; UntypedParameter: ast::Parameter = { => ast::Parameter { arg: i, annotation: None }, }; TypedParameter: ast::Parameter = { => { let annotation = a.map(|x| Box::new(x.1)); ast::Parameter { arg, annotation } }, }; // Use inline here to make sure the "," is not creating an ambiguity. // TODO: figure out another grammar that makes this inline no longer required. #[inline] ParameterListStarArgs: (Option>, Vec, Vec>, Option>) = { "*" )*> )?> => { // Extract keyword arguments: let mut kwonlyargs = vec![]; let mut kw_defaults = vec![]; for (name, value) in kw.into_iter().map(|x| x.1) { kwonlyargs.push(name); kw_defaults.push(value); } let kwarg = kwarg.map(|n| n.1); (Some(va), kwonlyargs, kw_defaults, kwarg) } }; KwargParameter: Option = { "**" => { kwarg } }; ClassDef: ast::LocatedStatement = { "class" ":" => { let (bases, keywords) = match a { Some((_, args, _)) => args, None => (vec![], vec![]), }; ast::LocatedStatement { location: loc, node: ast::Statement::ClassDef { name: n, bases: bases, keywords: keywords, body: s, decorator_list: d, }, } }, }; Path: ast::Expression = { => ast::Expression::Identifier { name: n }, "." => { ast::Expression::Attribute { value: Box::new(p), name: n, } }, }; // Decorators: Decorator: ast::Expression = { "@" "\n" => { match a { Some((_, args, _)) => ast::Expression::Call { function: Box::new(p), args: args.0, keywords: args.1, }, None => p, } }, }; YieldExpr: ast::Expression = { "yield" => ast::Expression::Yield { value: value.map(Box::new) }, "yield" "from" => ast::Expression::YieldFrom { value: Box::new(e) }, }; Test: ast::Expression = { => { if let Some(c) = condition { ast::Expression::IfExpression { test: Box::new(c.1), body: Box::new(expr), orelse: Box::new(c.3), } } else { expr } }, LambdaDef, }; LambdaDef: ast::Expression = { "lambda" ?> ":" => ast::Expression::Lambda { args: p.unwrap_or(Default::default()), body: Box::new(body) } } OrTest: ast::Expression = { AndTest, "or" => ast::Expression::BoolOp { a: Box::new(e1), op: ast::BooleanOperator::Or, b: Box::new(e2) }, }; AndTest: ast::Expression = { NotTest, "and" => ast::Expression::BoolOp { a: Box::new(e1), op: ast::BooleanOperator::And, b: Box::new(e2) }, }; NotTest: ast::Expression = { "not" => ast::Expression::Unop { a: Box::new(e), op: ast::UnaryOperator::Not }, Comparison, }; Comparison: ast::Expression = { => { let mut vals = vec![e]; let mut ops = vec![]; for x in comparisons { ops.push(x.0); vals.push(x.1); } ast::Expression::Compare { vals, ops } }, Expression, }; CompOp: ast::Comparison = { "==" => ast::Comparison::Equal, "!=" => ast::Comparison::NotEqual, "<" => ast::Comparison::Less, "<=" => ast::Comparison::LessOrEqual, ">" => ast::Comparison::Greater, ">=" => ast::Comparison::GreaterOrEqual, "in" => ast::Comparison::In, "not" "in" => ast::Comparison::NotIn, "is" => ast::Comparison::Is, "is" "not" => ast::Comparison::IsNot, }; Expression: ast::Expression = { "|" => ast::Expression::Binop { a: Box::new(e1), op: ast::Operator::BitOr, b: Box::new(e2) }, XorExpression, }; XorExpression: ast::Expression = { "^" => ast::Expression::Binop { a: Box::new(e1), op: ast::Operator::BitXor, b: Box::new(e2) }, AndExpression, }; AndExpression: ast::Expression = { "&" => ast::Expression::Binop { a: Box::new(e1), op: ast::Operator::BitAnd, b: Box::new(e2) }, ShiftExpression, }; ShiftExpression: ast::Expression = { => ast::Expression::Binop { a: Box::new(e1), op: op, b: Box::new(e2) }, ArithmaticExpression, }; ShiftOp: ast::Operator = { "<<" => ast::Operator::LShift, ">>" => ast::Operator::RShift, }; ArithmaticExpression: ast::Expression = { => ast::Expression::Binop { a: Box::new(a), op: op, b: Box::new(b) }, Term, }; AddOp: ast::Operator = { "+" => ast::Operator::Add, "-" => ast::Operator::Sub, }; Term: ast::Expression = { => ast::Expression::Binop { a: Box::new(a), op: op, b: Box::new(b) }, Factor, }; MulOp: ast::Operator = { "*" => ast::Operator::Mult, "/" => ast::Operator::Div, "//" => ast::Operator::FloorDiv, "%" => ast::Operator::Mod, "@" => ast::Operator::MatMult, }; Factor: ast::Expression = { "+" => ast::Expression::Unop { a: Box::new(e), op: ast::UnaryOperator::Pos }, "-" => ast::Expression::Unop { a: Box::new(e), op: ast::UnaryOperator::Neg }, "~" => ast::Expression::Unop { a: Box::new(e), op: ast::UnaryOperator::Inv }, Power, }; Power: ast::Expression = { => { match e2 { None => e, Some(x) => ast::Expression::Binop { a: Box::new(e), op: ast::Operator::Pow, b: Box::new(x.1) }, } } }; AtomExpr: ast::Expression = { => { if is_await.is_some() { ast::Expression::Await { value: Box::new(atom) } } else { atom } } } AtomExpr2: ast::Expression = { Atom, "(" ")" => ast::Expression::Call { function: Box::new(f), args: a.0, keywords: a.1 }, "[" "]" => ast::Expression::Subscript { a: Box::new(e), b: Box::new(s) }, "." => ast::Expression::Attribute { value: Box::new(e), name: n }, }; SubscriptList: ast::Expression = { ","? => { if s2.is_empty() { s1 } else { let mut dims = vec![s1]; for x in s2 { dims.push(x.1) } ast::Expression::Tuple { elements: dims } } } }; Subscript: ast::Expression = { Test, ":" => { let s1 = e1.unwrap_or(ast::Expression::None); let s2 = e2.unwrap_or(ast::Expression::None); let s3 = e3.unwrap_or(ast::Expression::None); ast::Expression::Slice { elements: vec![s1, s2, s3] } } }; SliceOp: ast::Expression = { ":" => e.unwrap_or(ast::Expression::None) } Atom: ast::Expression = { => ast::Expression::String { value }, => ast::Expression::Bytes { value }, => ast::Expression::Number { value }, => ast::Expression::Identifier { name }, "[" "]" => { let elements = e.unwrap_or(Vec::new()); ast::Expression::List { elements } }, "[" "]" => e, "(" ")" => { elements.unwrap_or(ast::Expression::Tuple { elements: Vec::new() }) }, "(" ")" => { ast::Expression::Comprehension { kind: Box::new(ast::ComprehensionKind::GeneratorExpression { element: e }), generators: c, } }, "{" "}" => ast::Expression::Dict { elements: e.unwrap_or(Vec::new()) }, "{" "}" => e, "{" "}" => ast::Expression::Set { elements: e }, "{" "}" => e, "True" => ast::Expression::True, "False" => ast::Expression::False, "None" => ast::Expression::None, "..." => ast::Expression::Ellipsis, }; TestListComp: Vec = { > <_trailing_comma:","?> => e, }; TestListComp2: ast::Expression = { => { ast::Expression::Comprehension { kind: Box::new(ast::ComprehensionKind::List { element: e }), generators: c, } }, }; TestDict: Vec<(Option, ast::Expression)> = { > <_trailing_comma:","?> => elements, }; TestDictComp: ast::Expression = { => { ast::Expression::Comprehension { kind: Box::new(ast::ComprehensionKind::Dict { key: e1.0, value: e1.1 }), generators: c, } } }; DictEntry: (ast::Expression, ast::Expression) = { ":" => (e1, e2), }; DictElement: (Option, ast::Expression) = { => (Some(e.0), e.1), "**" => (None, e), }; TestSet: Vec = { > ","? => e1 }; TestSetComp: ast::Expression = { => { ast::Expression::Comprehension { kind: Box::new(ast::ComprehensionKind::Set { element: e1 }), generators: c, } } }; ExpressionOrStarExpression = { Expression, StarExpr }; ExpressionList: ast::Expression = { > => { if elements.len() == 1 && trailing_comma.is_none() { elements.into_iter().next().unwrap() } else { ast::Expression::Tuple { elements } } }, }; ExpressionList2: Vec = { > ","? => elements, }; // A test list is one of: // - a list of expressions // - a single expression // - a single expression followed by a trailing comma TestList: ast::Expression = { > => { if elements.len() == 1 && trailing_comma.is_none() { elements.into_iter().next().unwrap() } else { ast::Expression::Tuple { elements } } } }; // Test StarExpr: ast::Expression = { "*" => ast::Expression::Starred { value: Box::new(e) }, }; // Comprehensions: CompFor: Vec = => c; SingleForComprehension: ast::Comprehension = { "for" "in" => { ast::Comprehension { target, iter, ifs: c2 } } }; ExpressionNoCond: ast::Expression = OrTest; ComprehensionIf: ast::Expression = "if" => c; ArgumentList: (Vec, Vec) = { > => { let mut args = vec![]; let mut keywords = vec![]; for (name, value) in e { match name { Some(n) => { keywords.push(ast::Keyword { name: n, value: value }); }, None => { // Allow starred args after keyword arguments. let is_starred = if let ast::Expression::Starred { .. } = &value { true } else { false }; if keywords.len() > 0 && !is_starred { panic!("positional argument follows keyword argument {:?}", keywords); }; args.push(value); }, } } (args, keywords) } }; FunctionArgument: (Option>, ast::Expression) = { => { let expr = match c { Some(c) => ast::Expression::Comprehension { kind: Box::new(ast::ComprehensionKind::GeneratorExpression { element: e }), generators: c, }, None => e, }; (None, expr) }, "=" => (Some(Some(i.clone())), e), "*" => (None, ast::Expression::Starred { value: Box::new(e) }), "**" => (Some(None), e), }; Comma: Vec = { ",")*> => { let mut items = items; items.extend(last); items } }; #[inline] OneOrMore: Vec = { => { let mut items = vec![i1]; items.extend(i2.into_iter().map(|e| e.1)); items } }; Number: ast::Number = { => { ast::Number::Integer { value } }, => { ast::Number::Float { value } }, => { ast::Number::Complex { real: s.0, imag: s.1 } }, }; StringGroup: ast::StringGroup = { =>? { let mut values = vec![]; for (value, is_fstring) in s { values.push(if is_fstring { parse_fstring(&value)? } else { ast::StringGroup::Constant { value } }) } Ok(if values.len() > 1 { ast::StringGroup::Joined { values } } else { values.into_iter().next().unwrap() }) }, }; Bytes: Vec = { => { s.into_iter().flatten().collect::>() }, }; Identifier: String = => s; // Hook external lexer: extern { type Location = lexer::Location; type Error = lexer::LexicalError; enum lexer::Tok { indent => lexer::Tok::Indent, dedent => lexer::Tok::Dedent, StartProgram => lexer::Tok::StartProgram, StartStatement => lexer::Tok::StartStatement, StartExpression => lexer::Tok::StartExpression, "+" => lexer::Tok::Plus, "-" => lexer::Tok::Minus, "~" => lexer::Tok::Tilde, ":" => lexer::Tok::Colon, "." => lexer::Tok::Dot, "..." => lexer::Tok::Ellipsis, "," => lexer::Tok::Comma, "*" => lexer::Tok::Star, "**" => lexer::Tok::DoubleStar, "&" => lexer::Tok::Amper, "@" => lexer::Tok::At, "%" => lexer::Tok::Percent, "//" => lexer::Tok::DoubleSlash, "^" => lexer::Tok::CircumFlex, "|" => lexer::Tok::Vbar, "<<" => lexer::Tok::LeftShift, ">>" => lexer::Tok::RightShift, "/" => lexer::Tok::Slash, "(" => lexer::Tok::Lpar, ")" => lexer::Tok::Rpar, "[" => lexer::Tok::Lsqb, "]" => lexer::Tok::Rsqb, "{" => lexer::Tok::Lbrace, "}" => lexer::Tok::Rbrace, "=" => lexer::Tok::Equal, "+=" => lexer::Tok::PlusEqual, "-=" => lexer::Tok::MinusEqual, "*=" => lexer::Tok::StarEqual, "@=" => lexer::Tok::AtEqual, "/=" => lexer::Tok::SlashEqual, "%=" => lexer::Tok::PercentEqual, "&=" => lexer::Tok::AmperEqual, "|=" => lexer::Tok::VbarEqual, "^=" => lexer::Tok::CircumflexEqual, "<<=" => lexer::Tok::LeftShiftEqual, ">>=" => lexer::Tok::RightShiftEqual, "**=" => lexer::Tok::DoubleStarEqual, "//=" => lexer::Tok::DoubleSlashEqual, "==" => lexer::Tok::EqEqual, "!=" => lexer::Tok::NotEqual, "<" => lexer::Tok::Less, "<=" => lexer::Tok::LessEqual, ">" => lexer::Tok::Greater, ">=" => lexer::Tok::GreaterEqual, "->" => lexer::Tok::Rarrow, "and" => lexer::Tok::And, "as" => lexer::Tok::As, "assert" => lexer::Tok::Assert, "async" => lexer::Tok::Async, "await" => lexer::Tok::Await, "break" => lexer::Tok::Break, "class" => lexer::Tok::Class, "continue" => lexer::Tok::Continue, "def" => lexer::Tok::Def, "del" => lexer::Tok::Del, "elif" => lexer::Tok::Elif, "else" => lexer::Tok::Else, "except" => lexer::Tok::Except, "finally" => lexer::Tok::Finally, "for" => lexer::Tok::For, "from" => lexer::Tok::From, "global" => lexer::Tok::Global, "if" => lexer::Tok::If, "in" => lexer::Tok::In, "is" => lexer::Tok::Is, "import" => lexer::Tok::Import, "from" => lexer::Tok::From, "lambda" => lexer::Tok::Lambda, "nonlocal" => lexer::Tok::Nonlocal, "not" => lexer::Tok::Not, "or" => lexer::Tok::Or, "pass" => lexer::Tok::Pass, "raise" => lexer::Tok::Raise, "return" => lexer::Tok::Return, "try" => lexer::Tok::Try, "while" => lexer::Tok::While, "with" => lexer::Tok::With, "yield" => lexer::Tok::Yield, "True" => lexer::Tok::True, "False" => lexer::Tok::False, "None" => lexer::Tok::None, int => lexer::Tok::Int { value: }, float => lexer::Tok::Float { value: }, complex => lexer::Tok::Complex { real: , imag: }, string => lexer::Tok::String { value: , is_fstring: }, bytes => lexer::Tok::Bytes { value: > }, name => lexer::Tok::Name { name: }, "\n" => lexer::Tok::Newline, ";" => lexer::Tok::Semi, } }