feat(aiken-lang): add doc, module, and regular comment support
This commit is contained in:
parent
f7313ee61a
commit
132af027dc
|
@ -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>>,
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -96,27 +96,29 @@ 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,
|
||||
|
@ -125,7 +127,8 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
|||
));
|
||||
t
|
||||
}))
|
||||
.map_with_span(move |token, span| (token, span))
|
||||
.map_with_span(|token, span| (token, span)),
|
||||
))
|
||||
.padded()
|
||||
.recover_with(skip_then_retry_until([]))
|
||||
.repeated()
|
||||
|
|
Loading…
Reference in New Issue