feat(aiken-lang): add doc, module, and regular comment support

This commit is contained in:
rvcas 2022-11-16 14:22:57 -05:00 committed by Lucas
parent f7313ee61a
commit 132af027dc
3 changed files with 27 additions and 23 deletions

View File

@ -44,6 +44,7 @@ pub fn pretty(writer: &mut String, module: UntypedModule, extra: ModuleExtra, sr
.pretty_print(80, writer);
}
#[derive(Debug)]
struct Intermediate<'a> {
comments: Vec<Comment<'a>>,
doc_comments: Vec<Comment<'a>>,

View File

@ -1,6 +1,6 @@
use crate::ast::Span;
#[derive(Debug, PartialEq, Eq, Default)]
#[derive(Debug, PartialEq, Eq, Default, Clone)]
pub struct ModuleExtra {
pub module_comments: Vec<Span>,
pub doc_comments: Vec<Span>,

View File

@ -96,36 +96,39 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
}
});
let module_comments =
just("////").ignore_then(take_until(text::newline()).to(Token::ModuleComment));
let module_comments = just("////").ignore_then(
take_until(text::newline().rewind())
.to(Token::ModuleComment)
.map_with_span(|token, span| (token, span)),
);
let doc_comments = just("///")
.ignore_then(take_until(text::newline()))
.to(Token::DocComment);
let doc_comments = just("///").ignore_then(
take_until(text::newline().rewind())
.to(Token::DocComment)
.map_with_span(|token, span| (token, span)),
);
let comments = just("//")
.ignore_then(take_until(text::newline()))
.to(Token::Comment);
let comments = just("//").ignore_then(
take_until(text::newline().rewind())
.to(Token::Comment)
.map_with_span(|token, span| (token, span)),
);
choice((
module_comments,
doc_comments,
comments,
keyword,
int,
op,
grouping,
string,
choice((keyword, int, op, grouping, string))
.or(any().map(Token::Error).validate(|t, span, emit| {
emit(ParseError::expected_input_found(
span,
None,
Some(t.clone()),
));
t
}))
.map_with_span(|token, span| (token, span)),
))
.or(any().map(Token::Error).validate(|t, span, emit| {
emit(ParseError::expected_input_found(
span,
None,
Some(t.clone()),
));
t
}))
.map_with_span(move |token, span| (token, span))
.padded()
.recover_with(skip_then_retry_until([]))
.repeated()