Skip to content

Commit daa9321

Browse files
committed
(node) ref: doc & fix
1 parent 1d6640a commit daa9321

File tree

11 files changed

+312
-176
lines changed

11 files changed

+312
-176
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install nightly
2323
run: rustup default nightly
2424
- name: Build
25-
run: cargo build --verbose
25+
run: cargo build --release --verbose
2626

2727
test:
2828
needs: build

src/errors/display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ pub fn display_errors(errors: Vec<CompileError>, files: &[(String, &str)], err_t
1414
let code_lines = files_status
1515
.get(&filename)
1616
.expect("Never happens: File of error doesn't exist");
17-
let code_line = code_lines
18-
.get(line_nb - 1)
19-
.unwrap_or_else(|| panic!("Never happens: given line of file that doesn't exist: {filename}:{line_nb}:{column_nb}"));
17+
let code_line = code_lines.get(line_nb - 1).unwrap_or_else(|| {
18+
panic!("Never happens: given line of file that doesn't exist: {filename}:{line_nb}:{column_nb}")
19+
});
2020
eprintln!("\n{filename}:{line_nb}:{column_nb}: {err_type} {err_lvl}: {message}");
2121
eprintln!("{line_nb:5} | {code_line}");
2222
eprintln!("{}^{}", " ".repeat(8 + column_nb - 1), "~".repeat(length));

src/lexer/end_state.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ pub fn end_current(status: &mut LexingStatus, lex_data: &mut LexingData, locatio
1212
LexingStatus::Symbols(symbol_status) => end_symbols(symbol_status, lex_data, location),
1313
LexingStatus::Identifier(ident) => end_ident(ident, lex_data, location),
1414
LexingStatus::Char(None) => {
15-
lex_data.push_err(location.to_error(
16-
"Found an empty char, but chars must contain one character. Did you mean '\\''?".to_owned()
17-
));
15+
lex_data.push_err(
16+
location.to_error(
17+
"Found an empty char, but chars must contain one character. Did you mean '\\''?".to_owned(),
18+
),
19+
);
1820
}
1921
LexingStatus::Char(Some(ch)) => lex_data.push_token(Token::from_char(*ch, location)),
2022
LexingStatus::Str(val) => {

src/lexer/numbers/base/binary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub fn to_bin_value(
1919
.chars()
2020
.find(|ch| matches!(ch, '0' | '1'))
2121
.expect("Exists according to line above");
22-
OverParseRes::from(location.to_error(format!("{ERR_PREFIX}a binary constant must only contain '0's and '1's. Found invalid character '{first}'.")))
22+
OverParseRes::from(location.to_error(format!(
23+
"{ERR_PREFIX}a binary constant must only contain '0's and '1's. Found invalid character '{first}'."
24+
)))
2325
}
2426
}

src/lexer/numbers/base/hexadecimal.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,40 @@ fn get_hex_float_state(literal: &str, location: &Location) -> Result<HexFloatPar
115115
let mut float_parse = HexFloatParse::default();
116116
for ch in literal.chars() {
117117
match ch {
118-
'+' | '-' if float_parse.state != HexFloatParseState::Exponent => panic!("never happens: + or - always are after a p character in hex literal"),
119-
'+' | '-' if float_parse.exponent_neg.is_some() => return Err(location.to_error(format!("{ERR_PREFIX}maximum one sign is allowed in a number literal."))),
118+
'+' | '-' if float_parse.state != HexFloatParseState::Exponent => {
119+
panic!("never happens: + or - always are after a p character in hex literal")
120+
}
121+
'+' | '-' if float_parse.exponent_neg.is_some() => {
122+
return Err(location.to_error(format!("{ERR_PREFIX}maximum one sign is allowed in a number literal.")))
123+
}
120124
'-' => float_parse.exponent_neg = Some(true),
121125
'+' => float_parse.exponent_neg = Some(false),
122126
_ if float_parse.state == HexFloatParseState::Exponent && ch.is_ascii_digit() => float_parse.push(ch),
123-
_ if float_parse.state == HexFloatParseState::Exponent => return Err(location.to_error(format!("{ERR_PREFIX}invalid character for exponent. Expected an ascii digit, but found '{ch}'"))),
127+
_ if float_parse.state == HexFloatParseState::Exponent => {
128+
return Err(location.to_error(format!(
129+
"{ERR_PREFIX}invalid character for exponent. Expected an ascii digit, but found '{ch}'"
130+
)))
131+
}
124132
_ if ch.is_ascii_hexdigit() => float_parse.push(ch),
125133
'.' if float_parse.state == HexFloatParseState::Int => float_parse.state = HexFloatParseState::Decimal,
126-
'.' if float_parse.state == HexFloatParseState::Decimal => return Err(location.to_error(format!("{ERR_PREFIX}maximum one '.' in number constant, but 2 were found."))),
127-
'.' if float_parse.state == HexFloatParseState::Exponent => return Err(location.to_error(format!("{ERR_PREFIX}exponent must be an integer, but found a period."))),
128-
'p' | 'P' if float_parse.state == HexFloatParseState::Exponent => return Err(location.to_error(format!("{ERR_PREFIX}maximum one 'p' in number constant, but 2 were found."))),
129-
'p' | 'P' => float_parse.state = HexFloatParseState::Exponent,
130-
_ => return Err(location.to_error(format!("{ERR_PREFIX}invalid character '{ch}' found in number constant"))),
131-
};
134+
'.' if float_parse.state == HexFloatParseState::Decimal => {
135+
return Err(location.to_error(format!(
136+
"{ERR_PREFIX}maximum one '.' in number constant, but 2 were found."
137+
)))
138+
}
139+
'.' if float_parse.state == HexFloatParseState::Exponent => {
140+
return Err(location.to_error(format!("{ERR_PREFIX}exponent must be an integer, but found a period.")))
141+
}
142+
'p' | 'P' if float_parse.state == HexFloatParseState::Exponent => {
143+
return Err(location.to_error(format!(
144+
"{ERR_PREFIX}maximum one 'p' in number constant, but 2 were found."
145+
)))
146+
}
147+
'p' | 'P' => float_parse.state = HexFloatParseState::Exponent,
148+
_ => {
149+
return Err(location.to_error(format!("{ERR_PREFIX}invalid character '{ch}' found in number constant")))
150+
}
151+
};
132152
}
133153
Ok(float_parse)
134154
}

src/lexer/numbers/from_literal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ fn literal_to_number_err(literal: &str, location: &Location, signed: bool) -> Pa
152152
let mut nb_type = get_number_type(literal, location)?;
153153
let base = get_base(literal, &nb_type, location)?;
154154
let value = literal
155-
.get(base.prefix_size()..literal.len() - nb_type.suffix_size())
156-
.expect("never happens as suffix size + prefix size <= len, as 'x' and 'b' can't be used as suffix");
155+
.get(base.prefix_size()..literal.len() - nb_type.suffix_size())
156+
.expect("never happens as suffix size + prefix size <= len, as 'x' and 'b' can't be used as suffix");
157157

158158
if value.is_empty() {
159159
return ParseRes::Err(location.to_error(format!(

src/lexer/types/lexing_state.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Ident {
3636
self.is_number()
3737
&& match self.0.chars().last() {
3838
Some('p' | 'P') => self.0.starts_with("0x"),
39-
Some('e' | 'E') => !self.0.starts_with("0x"), /* if the number expression starts with 0 and contains an exponent, the number is considered decimal, not octal. */
39+
Some('e' | 'E') => !self.0.starts_with("0x"), /* if the number expression starts
40+
* with 0 and contains */
41+
// an exponent, the number is considered decimal, not
42+
// octal.
4043
Some(_) | None => false,
4144
}
4245
}

src/parser/parse_content.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::errors::api::{CompileError, Location, Res};
1010
use crate::lexer::api::{Token, TokenValue};
1111

1212
fn clean_nodes(nodes: Vec<Node>) -> Node {
13-
let mut cleaned = nodes
13+
let mut cleaned: Vec<Node> = nodes
1414
.into_iter()
1515
.filter(|node| *node != Node::Empty)
1616
.collect::<Vec<_>>();
@@ -19,7 +19,7 @@ fn clean_nodes(nodes: Vec<Node>) -> Node {
1919
} else {
2020
Node::Block(Block {
2121
elts: cleaned,
22-
full: true,
22+
full: false,
2323
})
2424
}
2525
}

src/parser/tree/conversions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ where
2626
Self: Sized,
2727
{
2828
fn try_convert_and_erase_node(self, node: &mut Node) -> Result<(), String> {
29+
//TODO: check that this is called only on unary operators
2930
*node = self.try_to_node()?;
3031
Ok(())
3132
}

0 commit comments

Comments
 (0)