@@ -9291,12 +9291,13 @@ parser_lex_callback(pm_parser_t *parser) {
92919291 * Return a new comment node of the specified type.
92929292 */
92939293static inline pm_comment_t *
9294- parser_comment(pm_parser_t *parser, pm_comment_type_t type) {
9294+ parser_comment(pm_parser_t *parser, pm_comment_type_t type, bool trailing ) {
92959295 pm_comment_t *comment = (pm_comment_t *) xcalloc(1, sizeof(pm_comment_t));
92969296 if (comment == NULL) return NULL;
92979297
92989298 *comment = (pm_comment_t) {
92999299 .type = type,
9300+ .trailing = trailing,
93009301 .location = { parser->current.start, parser->current.end }
93019302 };
93029303
@@ -9324,7 +9325,7 @@ lex_embdoc(pm_parser_t *parser) {
93249325 parser_lex_callback(parser);
93259326
93269327 // Now, create a comment that is going to be attached to the parser.
9327- pm_comment_t *comment = parser_comment(parser, PM_COMMENT_EMBDOC);
9328+ pm_comment_t *comment = parser_comment(parser, PM_COMMENT_EMBDOC, false );
93289329 if (comment == NULL) return PM_TOKEN_EOF;
93299330
93309331 // Now, loop until we find the end of the embedded documentation or the end
@@ -9831,7 +9832,11 @@ parser_lex(pm_parser_t *parser) {
98319832 // If we found a comment while lexing, then we're going to
98329833 // add it to the list of comments in the file and keep
98339834 // lexing.
9834- pm_comment_t *comment = parser_comment(parser, PM_COMMENT_INLINE);
9835+ bool trailing = true;
9836+ if (parser->previous.type == PM_TOKEN_EOF || parser->previous.type == PM_TOKEN_NEWLINE) {
9837+ trailing = false;
9838+ }
9839+ pm_comment_t *comment = parser_comment(parser, PM_COMMENT_INLINE, trailing);
98359840 pm_list_append(&parser->comment_list, (pm_list_node_t *) comment);
98369841
98379842 if (ending) parser->current.end++;
0 commit comments