Skip to content

Commit 329ffbc

Browse files
committed
(parser) fix: indirections can be part of type declaration
1 parent 0448b47 commit 329ffbc

File tree

16 files changed

+334
-200
lines changed

16 files changed

+334
-200
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
clippy::nursery,
1111
clippy::cargo
1212
)]
13-
//
13+
// lints that are not meant to be used
1414
#![allow(clippy::single_call_fn)]
1515
#![allow(clippy::implicit_return)]
1616
#![allow(clippy::pattern_type_mismatch)]
1717
#![allow(clippy::blanket_clippy_restriction_lints)]
18+
#![allow(clippy::missing_trait_methods)]
1819
//
1920
#![allow(clippy::missing_docs_in_private_items)]
2021
#![allow(clippy::arithmetic_side_effects)]

src/parser/keyword/types/attributes.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use super::PushInNode;
77
use crate::lexer::api::Keyword;
88
use crate::parser::tree::binary::Binary;
99
use crate::parser::tree::blocks::Block;
10+
use crate::parser::tree::literal::{Literal, Variable};
1011
use crate::parser::tree::unary::Unary;
11-
use crate::parser::tree::{FunctionCall, ListInitialiser, Literal, Ternary, Variable};
12+
use crate::parser::tree::{FunctionCall, ListInitialiser, Ternary};
1213

1314
macro_rules! define_attribute_keywords {
1415
($($name:ident: $($variant:ident)*,)*) => {
@@ -68,7 +69,7 @@ impl PushInNode for AttributeKeyword {
6869
fn push_in_node(self, node: &mut Ast) -> Result<(), String> {
6970
match node {
7071
Ast::Empty => *node = self.into_node(),
71-
Ast::Leaf(Literal::Variable(var)) => var.push_attr(self),
72+
Ast::Leaf(Literal::Variable(var)) => var.push_keyword(self),
7273
Ast::ParensBlock(_) | Ast::Leaf(_) => return Err(format!("invalid attribute. Attribute keywords can only be applied to variables, but found {node}")),
7374
Ast::Unary(Unary{arg, ..}) | Ast::Binary(Binary {arg_r: arg, ..}) | Ast::Ternary(Ternary { failure: Some(arg), ..} | Ternary { success: arg, .. }) => return self.push_in_node(arg),
7475
Ast::ListInitialiser(ListInitialiser{ full: true, ..}) | Ast::FunctionCall(FunctionCall{full: true, .. }) => return Err("Attributes can only be placed before variables.".to_owned())

src/parser/keyword/types/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::fmt;
22

33
use super::super::Ast;
44
use super::PushInNode;
5-
use crate::parser::tree::{Literal, Variable};
5+
use crate::parser::tree::literal::{Literal, Variable};
66

77
#[derive(Debug, PartialEq, Eq)]
88
pub enum FunctionKeyword {

src/parser/keyword/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use functions::FunctionKeyword as Func;
1515

1616
use super::super::tree::node::Ast;
1717
use crate::lexer::api::Keyword;
18-
use crate::parser::tree::Literal;
18+
use crate::parser::tree::literal::Literal;
1919

2020
pub enum KeywordParsing {
2121
Attr(Attr),

src/parser/parse_content.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use super::keyword::handle_keyword;
55
use super::state::{BlockState, ParsingState};
66
use super::symbols::handle_symbol;
77
use super::tree::blocks::Block;
8+
use super::tree::literal::{Literal, Variable};
89
use super::tree::node::Ast;
9-
use super::tree::{Literal, Variable};
1010
use crate::errors::api::{CompileError, Location, Res};
1111
use crate::lexer::api::{Token, TokenValue};
1212

src/parser/symbols/blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn blocks_handler(
3535
match block_state {
3636
// semi-colon
3737
TodoBlock::SemiColon => {
38-
handle_colon(current);
38+
handle_semicolon(current);
3939
parse_block(tokens, p_state, current)
4040
}
4141
// parenthesis
@@ -135,7 +135,7 @@ fn handle_brace_block_open(
135135
parse_block(tokens, p_state, current)
136136
}
137137

138-
fn handle_colon(current: &mut Ast) {
138+
fn handle_semicolon(current: &mut Ast) {
139139
if let Ast::Block(Block { elts, full }) = current
140140
&& !*full
141141
{

src/parser/symbols/handlers.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ use super::super::tree::binary::BinaryOperator;
22
use super::super::tree::node::Ast;
33
use super::super::tree::unary::UnaryOperator;
44

5+
pub fn handle_binary_unary(
6+
current: &mut Ast,
7+
bin_op: BinaryOperator,
8+
un_op: UnaryOperator,
9+
) -> Result<(), String> {
10+
current
11+
.push_op(bin_op)
12+
.map_or_else(|_| current.push_op(un_op), |()| Ok(()))
13+
}
14+
515
pub fn handle_comma(current: &mut Ast) -> Result<(), String> {
616
if current
717
.apply_to_last_list_initialiser(&|vec, _| vec.push(Ast::Empty))
@@ -12,16 +22,6 @@ pub fn handle_comma(current: &mut Ast) -> Result<(), String> {
1222
Ok(())
1323
}
1424

15-
pub fn handle_double_binary(
16-
current: &mut Ast,
17-
bin_op: BinaryOperator,
18-
un_op: UnaryOperator,
19-
) -> Result<(), String> {
20-
current
21-
.push_op(bin_op)
22-
.map_or_else(|_| current.push_op(un_op), |()| Ok(()))
23-
}
24-
2525
pub fn handle_double_unary(
2626
current: &mut Ast,
2727
first: UnaryOperator,

src/parser/symbols/sort_symbols.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::super::tree::node::Ast;
55
use super::super::tree::unary::UnaryOperator;
66
use super::super::tree::TernaryOperator;
77
use super::blocks::TodoBlock;
8-
use super::handlers::{handle_comma, handle_double_binary, handle_double_unary};
8+
use super::handlers::{handle_binary_unary, handle_comma, handle_double_unary};
99
use crate::lexer::api::Symbol;
1010

1111
enum SymbolParsing {
@@ -86,7 +86,7 @@ pub fn handle_one_symbol(symbol: Symbol, current: &mut Ast) -> Result<TodoBlock,
8686
SymbolParsing::UniqueBinary(op) => current.push_op(op)?,
8787
// doubles
8888
SymbolParsing::DoubleUnary(first, second) => handle_double_unary(current, first, second)?,
89-
SymbolParsing::BinaryUnary(bin_op, un_op) => handle_double_binary(current, bin_op, un_op)?,
89+
SymbolParsing::BinaryUnary(bin_op, un_op) => handle_binary_unary(current, bin_op, un_op)?,
9090
// blocks
9191
SymbolParsing::Block(block) => return Ok(block),
9292
// special

src/parser/tree/binary.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use core::fmt;
44

5+
use super::unary::UnaryOperator;
56
use super::{Associativity, Ast, Operator};
67

78
macro_rules! define_binary_operator {
@@ -96,3 +97,9 @@ define_binary_operator!(
9697
XorAssign 14, "^="
9798
OrAssign 14, "|="
9899
);
100+
101+
impl PartialEq<UnaryOperator> for BinaryOperator {
102+
fn eq(&self, _: &UnaryOperator) -> bool {
103+
false
104+
}
105+
}

src/parser/tree/conversions.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ impl OperatorConversions for BinaryOperator {
1313
}
1414

1515
fn try_to_node_with_arg(self, arg: Ast) -> Result<Ast, String> {
16+
let lvalue = if self.precedence() == 14 {
17+
let mut old = arg;
18+
old.make_lhs()?;
19+
old
20+
} else {
21+
arg
22+
};
1623
Ok(Ast::Binary(Binary {
1724
op: self,
18-
arg_l: Box::new(arg),
25+
arg_l: Box::new(lvalue),
1926
arg_r: Box::new(Ast::Empty),
2027
}))
2128
}
2229
}
23-
2430
pub trait OperatorConversions: Operator
2531
where
2632
Self: Sized,

0 commit comments

Comments
 (0)