开发者

C# & PLSQL - Finding Comments and Strings by RegExp

开发者 https://www.devze.com 2023-03-28 15:45 出处:网络
Is it possible to distinguish between code, strings and comments by using regular expressions? I\'m trying to build a formatter for PLSQL-Code in C# and I can\'t manage to solve the problem, that stri

Is it possible to distinguish between code, strings and comments by using regular expressions? I'm trying to build a formatter for PLSQL-Code in C# and I can't manage to solve the problem, that strings, respectively quotes ( " or ' ) can also appear in comments, negating their special character and vice versa, comment indicators ( -- or /* ) appearing in strings, being nullified as a special开发者_如何学Go character sequence. Is there a solution, or are regular expressions simply the wrong way to handle this?

Best regards, Philipp


You might find an idea how to reliably identify comments by studying a source code of Perl module Regexp::Common::comment. The module supports matching also PL/SQL comments.

0

精彩评论

暂无评论...
验证码 换一张
取 消