سؤال

Im writing a simple code editor just like visual studio code editor. btw i have a textbox and wanna know how can i underline syntactical errors?

i`v searched the web, but did not find something usefull. any one got any refernce of documentation for C# compiler to help me in this topic? thanks all and sorry for my bad english..

هل كانت مفيدة؟

المحلول

If you're doing this for a real-world scenario, there are good commercial options available. You need to look at using the CodeDom classes which can take your input text and convert it into an object model which can then be compiled into an assembly.

If there are compiler errors, they will be returned as a collection of CompilerError objects. These will tell you the line number, character number, and error message, so you can display the error.

There are significant drawbacks to using CodeDom, however. It is older technology and has not been updated to keep pace with the language changes so there are limitations in what it can parse. If you want to write your own parser, you need to look at language tools like lexx and yacc or Roslyn.

نصائح أخرى

With a simple textbox control you certainly cannot do that. At least you need to use a RichTextBox control (comes in a variety of flavors, for WPF, WinForms, from Office...), to do some code formatting. As a first exercise, I would suggest you try to color keywords in your editor. That's a fairly easy task (and error recovery is not a problem) and may show you how to use the control.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top