Skip to content

Commit 87066c8

Browse files
committed
Merge branch 'master' into refactor/seperate_code_gen
2 parents 8ec3597 + 082929e commit 87066c8

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

src/ast/node/ret.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl Node for RetNode {
3434
return Err(err);
3535
}
3636
let (ret, tp, _) = ret.emit(ctx, builder)?;
37+
ctx.emit_comment_highlight(&self.comments[0]);
3738
let (ret, v) = ctx.try_load2var(self.range, ret.unwrap(), tp.unwrap(), builder)?;
3839
if v != rettp.unwrap() {
3940
let err = ctx.add_err(self.range, ErrorCode::RETURN_TYPE_MISMATCH);
@@ -44,7 +45,7 @@ impl Node for RetNode {
4445
builder.build_unconditional_branch(ctx.return_block.unwrap().0);
4546
} else {
4647
if rettp.is_some() && &*rettp.clone().unwrap().borrow() != &PLType::VOID {
47-
let _s = format!("return type is {:?}", &*rettp.unwrap().borrow());
48+
ctx.emit_comment_highlight(&self.comments[0]);
4849
let err = ctx.add_err(self.range, ErrorCode::NO_RETURN_VALUE_IN_NON_VOID_FUNCTION);
4950
return Err(err);
5051
}

src/nomparser/comment.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use nom::{
22
branch::alt,
33
bytes::complete::{tag, take_until},
4-
combinator::map_res,
5-
sequence::delimited,
4+
combinator::{map_res, rest},
5+
sequence::{pair, terminated},
66
IResult, InputTake,
77
};
88
use nom_locate::LocatedSpan;
@@ -12,32 +12,20 @@ use crate::{ast::node::comment::CommentNode, ast::range::Range};
1212
use super::*;
1313

1414
pub fn comment(input: Span) -> IResult<Span, Box<NodeEnum>> {
15-
alt((
16-
map_res(
17-
delimited(tag("///"), take_until("\n"), tag("\n")),
18-
|c: LocatedSpan<&str>| {
19-
res_enum(
20-
CommentNode {
21-
comment: c.to_string(),
22-
range: Range::new(input, c.take_split(c.len()).0),
23-
is_doc: true,
24-
}
25-
.into(),
26-
)
27-
},
15+
map_res(
16+
pair(
17+
alt((tag("///"), tag("//"))),
18+
alt((terminated(take_until("\n"), tag("\n")), rest)),
2819
),
29-
map_res(
30-
delimited(tag("//"), take_until("\n"), tag("\n")),
31-
|c: LocatedSpan<&str>| {
32-
res_enum(
33-
CommentNode {
34-
comment: c.to_string(),
35-
range: Range::new(input, c.take_split(c.len()).0),
36-
is_doc: false,
37-
}
38-
.into(),
39-
)
40-
},
41-
),
42-
))(input)
20+
|(a, c): (LocatedSpan<&str>, LocatedSpan<&str>)| {
21+
res_enum(
22+
CommentNode {
23+
comment: c.to_string(),
24+
range: Range::new(input, c.take_split(c.len()).0),
25+
is_doc: a.contains("///"),
26+
}
27+
.into(),
28+
)
29+
},
30+
)(input)
4331
}

test/main.pi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,5 @@ fn test_primitives() void {
425425
utest = utest + 2;
426426
return;
427427
}
428-
428+
//123
429+
//

0 commit comments

Comments
 (0)