Eclipse CDT 和 ESQL 语法错误
我正在使用 Eclipse CDT(Helios 版本)来编辑(旧的)C 应用程序的源代码,该应用程序也使用 ESQL。在此项目中,按照惯例,包含 ESQL 代码的文件具有 .sc 扩展名(而不是默认的 .c)
所有 ESQL 部分(例如以 EXEC SQL 关键字开头)都被标记为“语法错误”(垂直标尺、概述标尺和琥珀色波浪线)。实际编译是在另一台具有 ESQL 编译器的机器 (Unix) 上执行的。如何在开发机上检查SQL代码的语法?
注意:我可以隐藏“首选项”/“常规”/“编辑器”/“文本编辑器”/“注释”/“C/C++ 索引器标记”中的通知,但这可能会隐藏可能有用的警告。
I am using Eclipse CDT (Helios release) to edit the source code of an (old) C application, which also uses ESQL. In this project, by convention, files containing ESQL code have a .sc extension (instead of the default .c)
All ESQL sections e.g. starting with EXEC SQL keywords are flagged as “syntax error” (vertical ruler, overview ruler and amber squiggly line). The actual compilation is performed on a different machine (Unix), which has the ESQL compiler. What can I do to check the syntax of the SQL code on the development machine?
Note: I can hide the notification from Preferences / General / Editors / Text Editors / Annotations / C/C++ Indexer Markers but this may hide possible useful warnings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不管你怎么想,你拥有的并不是 C 代码。
额外的“语法”(例如 EXEC SQL 加上里面的任何内容)根本就不是 C 代码,任何处理传统 C 代码的工具都必然将其视为语法错误而拒绝。
“ESQL 处理器”(听起来像一个给定 EXEC SQL 短语的大型机)可能会预处理您所想到的 C 代码以提取 SQL 并用函数调用替换它;该结果可能会反馈给真正的 C 编译器。
我怀疑你可以使用 CDT 做任何有用的事情。
What you have isn't C code, in spite of what you might think.
Extra "syntax" (e.g, EXEC SQL plus whatever is inside) simply isn't C code, and any tool that processes conventional C code will by necessity reject it as a syntax error.
The "ESQL processor" (sounds like a mainframe given the EXEC SQL phrase) probably preprocesses what you are thinking of a C code to extract the SQL and replace it by function calls; that result is likely fed off to a real C compiler.
I doubt you can do anything useful with this using CDT.
如果您使用“窗口”->“首选项”->“C/C++”->“文件类型”,并使用 C 或 C++ 将新文件类型定义为 *.pc 或 *.sc 等,以适合您的扩展名,则语法荧光笔将尝试对关键字进行适当的着色并提供悬停提示。当然,EXEC SQL 类型语句将显示为错误,但这些错误相对容易被忽略,因为您知道您正在为文件中的元素寻找一些帮助,但不是全部(即不解析嵌入式 SQL)。
更新(对于 vi(m) 爱好者):我发现我需要在 ~/.vim/ftdetect/pc.vim 中创建一个文件,其中包含:
au BufRead,BufNewFile *.pc set filetype=pc
并且我还创建了一个链接我的 /usr/share/vim/vim73/esqlc.vim 到 pc.vim (虽然我们可以指定 *.pc set filetype=esqlc )
并且我安装了 vrapper,然后重新启动 eclipse 后,我的 EXEC SQL 或其他关键字没有下划线更长,尽管它们也没有着色。这可能会在未来的 vrapper 更新中发生变化。 (注意:我使用的是 Eclipse Kepler,因为它支持 vrapper)
额外:请确保将“查找和替换”首选项设置为 CTRL-4 而不是 CTRL-F,以便在 vim 工作中向前翻页。
If you use the Window->Preferences->C/C++->File Types and define a new file type with C or C++ as *.pc, or *.sc etc. as is appropriate to your extension, then the syntax highlighter will attempt to colour the keywords appropriately and provide hover tips. Of course the EXEC SQL type statements will show up as errors but those are relatively easy to ignore knowing that you're looking for some help for the elements in the file, but not all (i.e. doesn't parse embedded SQL).
Update (for vi(m) lovers): I found that I needed to create a file in ~/.vim/ftdetect/pc.vim containing:
au BufRead,BufNewFile *.pc set filetype=pc
and I also created a link from my /usr/share/vim/vim73/esqlc.vim to pc.vim (though we could have specified *.pc set filetype=esqlc)
and I installed vrapper, then after restarting eclipse, I my EXEC SQL or other keywords were no longer underlined, though they weren't colourized either. That may change in future vrapper updates. (Note: I'm using Eclipse Kepler as it supports vrapper)
Bonus: make sure to set your preferences for "Find and Replace" to CTRL-4 instead of CTRL-F to get page forward in vim working.