What would the Regex equivalent be of the following Flex structure? I'm trying to recreate Rusts grammar for a project but right now I'm stuck on this piece? This is the grammar for an inner/outer documentation comment (Rust has six types of comments). It should match comments like /** */
and /*! */
but for example I don't understand why [^*]
is needed on the first line and what the order of matching is in this case.
\/\*(\*|\!)[^*] { yy_push_state(INITIAL); yy_push_state(doc_block); yymore(); }
<doc_block>\/\* { yy_push_state(doc_block); yymore(); }
<doc_block>\*\/ {
yy_pop_state();
if (yy_top_state() == doc_block) {
yymore();
} else {
return ((yytext[2] == '!') ? INNER_DOC_COMMENT : OUTER_DOC_COMMENT);
}
}
<doc_block>(.|\n) { yymore(); }
As far as I understand: line 1, matches the start /**
or /*!
; line 2, matches a block comment (for some reason?); line 3, matches the end */
; line 11, matches any character or a newline (why?).
Two lines further it also matches for the normal block comment. Why is it also matching for it inside the doc comment?
\/\* { yy_push_state(blockcomment); }
<blockcomment>\/\* { yy_push_state(blockcomment); }
<blockcomment>\*\/ { yy_pop_state(); }
<blockcomment>(.|\n) { }