Skip to content

escape comment in lex#12

Merged
Paladz merged 2 commits intomainfrom
escape_comment
Jul 29, 2021
Merged

escape comment in lex#12
Paladz merged 2 commits intomainfrom
escape_comment

Conversation

@shenao78
Copy link
Copy Markdown
Contributor

No description provided.

#include "y.tab.h"
%}

%x COMMENT
Copy link
Copy Markdown
Contributor Author

@shenao78 shenao78 Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加入一个 COMMENT 开始条件,BEGIN(COMMENT)会启动这个条件,当该条件启动时,不带有的规则都将无效
具体参考 https://gist.github.com/DmitrySoshnikov/f5e2583b37e8f758c789cea9dcdf238a

%%

"//" BEGIN(COMMENT);
<COMMENT>\n { BEGIN(0); return '\n'; }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把换行符返回的原因是,golang的每条语句之间必须包含换行符。当注释是那种尾注释时,换行符会被吃掉。

%%

"//" BEGIN(COMMENT);
<COMMENT>\n { BEGIN(0); return '\n'; }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BEGIN(0)表示恢复到原始的状态

@Paladz Paladz merged commit 580b136 into main Jul 29, 2021
@Paladz Paladz deleted the escape_comment branch July 29, 2021 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants