I am having a problem with comments in creating custom file in NetBeans. I got two types of multiline comment types:
/*
and ending */
<!--
and ending -->
MORE :
{
"/*": XSCRIPT_COMMENT
|
"<!--": XML_COMMENT
}
<XSCRIPT_COMMENT>
TOKEN :
{
<X_SCRIPT_COMMENT_END: "*/" > : DEFAULT
}
<XML_COMMENT>
TOKEN :
{
<XML_COMMENT_END: "-->" > : DEFAULT
}
<XSCRIPT_COMMENT,XML_COMMENT>
MORE :
{
< ~[] >
}
the problem is, that both multiline comments throws TokenMgrError
when I write the initial part of comment (/*
or <!--
). The error occurs only when there is no ending part and lexer reaches end of file.
My goal is to create multiline comments which works similar to other comment types (When only initial part is written, the rest of document is comment type text).
Please excuse my english, not my native language.
One way to do it is to use a single regular expression to match comments. For example a /* .. */ multiline comment can be matched by
"/*" (("*")* ~["*"])* ("*" ("*")* "/"?)?
Here I made the final "*/" optional. (The best way to come up with this sort of regular expression, in my experience, is to convert an NDFA to an RE, if you know how to do that.)
Another way to do it is to allow an empty string to end a comment. Add these two rules.
<XML_COMMENT> TOKEN : { <XML_COMMENT_END: "" > : DEFAULT }
<XSCRIPT_COMMENT> TOKEN : { <X_SCRIPT_COMMENT_END: "" > : DEFAULT }