I want to add support for syntax highlighting for lex and yacc-files in Visual Studio 2010.
How can I do this?
Following the given link to Syntax Coloring leads to another, more pertinent page Implementing Syntax Coloring, where it is noted
Visual Studio does not specify a parser interface, and parser implementation is completely up to you. However, a default parser implementation is provided in the Visual Studio Language Package project. For managed code, the managed package framework (MPF) provides complete support for colorizing text.
Depending on what you want:
trivial, coloring only the C code portions of the lex/yacc files
much harder, coloring the patterns so that one can make sense of them
you could in principle make a parser using just lex (yacc isn't necessary). For yacc files, that's not so hard, but for lex there's the complication of regular expressions. vi-like-emacs does that and while the interface differs in detail, conceptually it's similar. Reading the lexers might give you some ideas how to apply that approach:
lex syntax filter
yacc syntax filter
There is documentation from Microsoft on integrating yacc/bison & flex/lex with Visual Studio. Although a URL only link is discouraged on SO, its best to go to the source for this kind of detailed information:
https://msdn.microsoft.com/en-us/library/aa730877(VS.80).aspx#vccustombr_topic3
It lays out all the steps necessary for integrating with the build tools. Syntax highlighting is covered elsewhere as described in Add a new language to Visual Studio 2010 with syntax highlighting and intellisense. In particular the guidance for syntax colouring can be found here: https://msdn.microsoft.com/en-us/library/bb166778(v=vs.100).aspx.
However, I'm not aware of anyone who has published extra colouring rules for the grammar specific components of flex and yacc. However, most of the body of flex and yacc files are written in C or C++ for which there are syntax highlighting rules that can be applied, and suit most peoples needs.
Related
My project is written in C++/CX on VS2015 and I am seeking a way to generate API documentation.
After googling and stackoverflow, I have tried doxygen, VSDocman,NDoc, Atomineer Pro Documentation and SandCastle, I found these tools do not support C++/CX syntax, therefore, they cannot generate correct document.
I also tried to generate XML file which VS supports. But it's hard to read XML file.
How do I generate API documentation from C++/CX? Thanks for any suggestion
There are a lot of misconceptions about the C++/CX language extension. You tried too many products that have no hope of getting you anywhere. First and foremost is that it is a native C++ extension and does not generate a .NET compatible assembly. So knock out any that try to use Reflection to parse metadata. Out goes NDoc, VSDocman, Sandcastle. Atomineer is out, it is just an editor add-in.
So all you got left is doxygen.
Sure, it doesn't know about C++/CX out of the box. The FAQ points out that in order to make it compatible with a language, you need to modify src/scanner.l
Having a look at it, I see it already supports the C++/CLI extension. That's another C++ language extension that supports generating MSIL. C++/CX syntax is very close to C++/CLI. Just some minor differences, like the gcnew keyword is too misleading and replaced by ref new. But that's not the kind of syntax that doxygen cares about, it just wants to know about declarations. Those keywords are the same.
So the only obstacle I can guess at is that you just forgot to tell it about the language. It can't guess at it correctly from just the filename extension, .cpp and .h will get it to parse plain C++. Modify or add this line in the config file:
CPP_CLI_SUPPORT = YES
And tweak scanner.l if necessary.
I'm happily developing a language in ANTLR 4.4 / ANTLR4CS, and I'd like to start integrating my language into an IDE. The natural place for me feels like integrating it into Visual Studio. It occurs to me that someone might have figured out a general way to plug an ANTLR lexer into the Visual Studio syntax highlighting system, or ANTLR parsers into an MSBuild task such that errors appear in the Visual Studio error list.
Is there any kind of starting point, base package, plugin system, or similar which lets you integrate an ANTLR4CS language with Visual Studio's language support mechanisms?
Alternatively, has anyone had any success building, say, a Sublime Text build system / language def automatically from their grammar?
#Lucas Trzesniewski wrote:
I did this by reparsing the whole file every time, doing it on a line-by line basis was too much of a PITA for my needs (and our DSL files are small so it works fine).
I don't know if it'll be suitable for your needs, but you can implement a single file generator from a VS extension. The Generate method takes a IVsGeneratorProgress parameter which lets you report errors easily.
I use Visual Studio for development and I am quite used to Intellisense. But when writting CoffeeScript you don't really get any Syntax Checking or Intellisense.
Is there a plugin for VS that would allow this?
Thanks
You can't have more than syntax checking/coloring with coffeescript (on any IDE) AFAIK.
As an alternative, you can use TypeScript to get the full Visual Studio tooling support (and stay close to the javascript), or some transcompilers that transform code to javascript, for C# there is Saltarelle and for CIL (.NET bytecode, so compatible with any .NET language), I just found JSIL but I have no idea how well it works.
Note than the generated code "look" can be important for debugging and using external libraries get a bit of work to be included in Typed languages.
For js code readability I would recommand TypeScript (similar to coffeescript, even easier, but less powerfull as a language).
Saltarelle code looks readable (didn't tried a lot), for JSIL I have no idea.
A list of languages that compiles to JS: https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS
Webstorm and all of the JetBrains IDEs recently added some code completion and refactoring support. It knows what methods are in my own classes and will prompt to complete as I type. The red squiggly underline compile as you type is not quite there yet but it is coming. I bet Webstorm is the first to implement CS source map also. They have added so much in the last 11 months.
Check this out: http://visualstudiogallery.msdn.microsoft.com/2b96d16a-c986-4501-8f97-8008f9db141a
Here is another: http://chirpy.codeplex.com/
I think this should do what you want.
I'm now building a developers editor using Lazarus and as every good developers editor, it needs to have a syntax highlighting, because of this that I want to know some things:
How is syntax highlight normally built(using many ifs to change the font on a TextField?
TSynEdit is very nice to do this?
How to use TSynEdit(links and resources)?
You can actually see an excellent example for yourself if you look at the editor for SharpDevelop. It's implemented in C# but uses great OOP that should be readily portable to other platforms or languages.
Most home-brewed syntax highlighters tend to use the MS Windows RichText control but they're usually slow and clunky and really slow down when a lot of code is added.
You could read the source code of Eclipse or VIM. In Eclipse you will find an Abstract Syntax Tree base. On top of it are parsers that are carefully written to be tolerant of errors, since code in progress often does not satisfy the full grammar of the language. The highlighting uses the information in the syntax tree.
The SPE IDE that I use for my Python code uses this "visual cue" that looks like a vertical dashed line for alignment of (what I would call) function blocks. How can I get this option in Visual Studio 2008?
Here is what it looks like:
I've seen it called structural highlighting or code outlining.
There's a Visual Studio plug-in called CodeRush from Developer Express that supports this (bottom of the page) and a lot more.
update:
As divo mentioned, there is a free lite version of CodeRush. I confirmed that it includes structural highlighting.
Unfortunately, Visual Studio does not support indentation lines out of the box.
These lines are arguably more useful in Python where indentation denotes nesting. In C#, nesting is explicitly marked by curly braces. I feel as though curly braces provide the visual cues I need to see this kind of thing, so you might just try to persevere -- in time the cognitive load associated with glimpses of C# versus glimpses of Python will reach equilibrium.
VS2010 implements the text editor in WPF and there are some examples online of creating plug-ins that augment the text editor area. This could be a fun project without being too difficult.
I am envious of Python's indentation-centric nesting. I wish that the C# compiler supported something like that. I wish that white space was part of the language. It would make tooling support for the language better as well.