View Full Version : Brackets <Yada> vs Quotes "Yada" in txt vs. cpp
GreenMoose
29-Jan-2008, 05:50 AM
File1.txt:
"Yada" yada
File2.txt
<Yada> yada
Diff shows:
<Yada> Yada
If I instead have File1.cpp and file2.cpp with same content, the diff shows:
<Yada> Yada
Is this intentional? Shouldn't the cpp rules also indicate that the words inside are same?
Granted, the <> inclusion may search another location initially than the "" version... But IMHO it would, in that case, be more helpful to see if the filename inside brackets/quotes is identical.
(I found this by comparing #include "Yada" vs #include <Yada> lines).
Michael Kujawa
29-Jan-2008, 10:44 AM
I believe that's because that section is going from a String, to a '<' followed by an Identifier followed by a '>'. If I teach the grammar about the preprocessor or about #includes, then it behaves as you expect.
I haven't found a grammar entry I'm happy with, though. After playing with this, it seemed like having a preprocessor rule would be good, so I tried to make one for my general use. I can't get it to stop short of consuming comments. I'm using:
^\s*#.+
I figured that I could get the comments by placing that rule either before or after the comment rules, but it seems to grab the whole line regardless. Any suggestions?
Craig
29-Jan-2008, 10:59 AM
Michael is correct. Cirrus compares the character type (string/comment/identifier) in addition to the character value, so identical characters can appear as differences if they're different types.
It looks like MSVC's syntax highlighting works by flagging <xxx> as a string if it's part of a #include directive, which would be best, but our parser can't support that. A decent alternative would be to create explicit #include "Compiler Directive" grammar items with these regular expressions:
^\s*#include\s+".*"
^\s*#include\s+<.*>
For some reason the "List" grammar category's "Regular Expression" option isn't working right, so you'll need to add those as two "Basic" regular expressions.
GreenMoose
29-Jan-2008, 11:59 PM
Great thanks! (I didn't even know the grammar was customizable so that was a nice surprise).
I ended up using these 2 new Grammar (Compiler Directive) regexes:
^\s*#include\s+"[^"]*"
^\s*#include\s+\<[^\>]*\>
(The [^\>]* handles comments like e.g. #include <Yada> //Yada>yada properly).
vBulletin® v3.7.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.