@@ -49,7 +49,7 @@ NEWLINE= \n | \r | \r\n
49
49
50
50
// handle for end which is \n```
51
51
String text = yytext(). toString(). trim();
52
- if (text. equals(" \n ```" ) || text. equals(" ```" )) {
52
+ if (( text. equals(" \n ```" ) || text. equals(" ```" )) && isCodeStart == true ) {
53
53
isCodeStart = false ;
54
54
return CODE_BLOCK_END ;
55
55
}
@@ -59,6 +59,10 @@ NEWLINE= \n | \r | \r\n
59
59
return NEWLINE ;
60
60
}
61
61
62
+ if (isCodeStart == false ) {
63
+ return TEXT_SEGMENT ;
64
+ }
65
+
62
66
return CODE_CONTENT ;
63
67
}
64
68
%}
@@ -68,7 +72,7 @@ NEWLINE= \n | \r | \r\n
68
72
"@" { yybegin(AGENT_BLOCK ); return AGENT_START ; }
69
73
"/" { yybegin(COMMAND_BLOCK ); return COMMAND_START ; }
70
74
"$" { yybegin(VARIABLE_BLOCK ); return VARIABLE_START ; }
71
- "```" {IDENTIFIER} { yybegin(LANG_ID ); isCodeStart = true ; yypushback(yylength()); }
75
+ "```" {IDENTIFIER} ? { yybegin(LANG_ID ); if ( isCodeStart == true ) { isCodeStart = false ; return CODE_BLOCK_END ; } else { isCodeStart = true ; } ; yypushback(yylength()); }
72
76
73
77
{TEXT_SEGMENT} { if (isCodeStart) { return codeContent(); } else { return TEXT_SEGMENT ; } }
74
78
{NEWLINE} { return NEWLINE ; }
@@ -91,10 +95,10 @@ NEWLINE= \n | \r | \r\n
91
95
}
92
96
93
97
<CODE_BLOCK> {
94
- {CODE_CONTENT} { return codeContent(); }
98
+ {CODE_CONTENT} { if (isCodeStart) { return codeContent(); } else { yybegin( YYINITIAL ); yypushback(yylength()); } }
95
99
{NEWLINE} { return NEWLINE ; }
96
- <<EOF>> { isCodeStart = false ; return codeContent( ); }
97
- [^] { }
100
+ <<EOF>> { isCodeStart = false ; yybegin( YYINITIAL ); yypushback(yylength() ); }
101
+ [^] { isCodeStart = false ; yybegin( YYINITIAL ); yypushback(yylength()); }
98
102
}
99
103
100
104
<LANG_ID> {
0 commit comments