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); .pretty_print(80, writer);
} }
#[derive(Debug)]
struct Intermediate<'a> { struct Intermediate<'a> {
comments: Vec<Comment<'a>>, comments: Vec<Comment<'a>>,
doc_comments: Vec<Comment<'a>>, doc_comments: Vec<Comment<'a>>,

View File

@ -1,6 +1,6 @@
use crate::ast::Span; use crate::ast::Span;
#[derive(Debug, PartialEq, Eq, Default)] #[derive(Debug, PartialEq, Eq, Default, Clone)]
pub struct ModuleExtra { pub struct ModuleExtra {
pub module_comments: Vec<Span>, pub module_comments: Vec<Span>,
pub doc_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 = let module_comments = just("////").ignore_then(
just("////").ignore_then(take_until(text::newline()).to(Token::ModuleComment)); take_until(text::newline().rewind())
.to(Token::ModuleComment)
.map_with_span(|token, span| (token, span)),
);
let doc_comments = just("///") let doc_comments = just("///").ignore_then(
.ignore_then(take_until(text::newline())) take_until(text::newline().rewind())
.to(Token::DocComment); .to(Token::DocComment)
.map_with_span(|token, span| (token, span)),
);
let comments = just("//") let comments = just("//").ignore_then(
.ignore_then(take_until(text::newline())) take_until(text::newline().rewind())
.to(Token::Comment); .to(Token::Comment)
.map_with_span(|token, span| (token, span)),
);
choice(( choice((
module_comments, module_comments,
doc_comments, doc_comments,
comments, comments,
keyword, choice((keyword, int, op, grouping, string))
int, .or(any().map(Token::Error).validate(|t, span, emit| {
op, emit(ParseError::expected_input_found(
grouping, span,
string, 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() .padded()
.recover_with(skip_then_retry_until([])) .recover_with(skip_then_retry_until([]))
.repeated() .repeated()