Eclipse CDT and ESQL syntax errors - syntax-highlighting

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.

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.

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.

Related

Custom ABAP Code Folding in ABAP for Eclipse

I'm trying to find out if Code Folding in Eclipse is possible.
(I dont mean the automated Folding for Source Code by the way)
Is there something like the equivalent in Visual Studio?
#region Region1
'Sample Code
#endregion
Would love to hear from you
This region feature used to exist in the ABAP editor of the ABAP Workbench (SAP GUI), but I didn't see this option in Eclipse ADT. I guess it became useless since the SAP recommendation is to write short methods.
If you really need to use regions, you may use the old ABAP editor (transaction codes SE24, SE37, SE38, SE80...) from Eclipse ADT, by first editing the ABAP code as usually, switch to the SAP GUI via the context menu Open with > SAP GUI, then write the regions this way:
"$. Region region-name followed by an optional text and a final dot.
ANY ABAP CODE
"$. Endregion region-name followed by a final dot.
Regions have a number of rules: their names must not contain spaces, are case-insensitive, they must not "cut" an ABAP block (like IF...ENDIF) in the middle, they may be nested, etc.

Adding keyword commands and functions to Textmate 2 bundle syntax

I want to add some additional syntax highlighting definitions to an existing bundle, but I need some general advice on how to do this. I'm not building a syntax from scratch, and I think my request is pretty simple, but I think it involves some subtleties for which I find the manual somewhat impenetrable in finding the answer.
Basically, I'm trying to fill out the syntax definitions for the Stata bundle. It's great, but there is no built in support for automatically highlighting the base commands and the installed functions, only a handful of basic control statements. Stata is a language which is primarily used by calling lots of different high level pre-defined command calls, like command foo bar, options(). The convention is that these command calls be highlighted.
There are a ton of these commands, and stubs which are used for convenience. Just the base install has almost 3500. Even optimizing them using the bundle helper, which obviously gets rid of the stub issue, still yields a massive regex list. I can easily cut this down to less than 1000 important ones, but its still a lot. There are also 350 "functions" which I would like to match with the syntax function()
I essentially have 3 questions:
Am I creating a serious problem by including a very comprehensive list of matching definitions?
How do I restrict a command to only highlight when it either begins a line or there is only whitespace between the beginning line and the command
What is the preferred way of restricting the list of functions() to only highlight when they have attached parentheses?

Is there a way to have Xcode auto-align variable names like in Apple's example code?

Apple's example projects often have the variable names aligned, in addition to their type specification/general code indentation:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
As opposed to:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
Is there a shortcut to make this happen? (I don't know what it would be called or else I could search the docs for it.)
It sounds like you're looking for Uncrustify. I've not used it in anger myself, but the feature list seems to include your requirement:
Features
Ident code, aligning on parens, assignments, etc
Align on '=' and variable definitions
Align structure initializers
Align #define stuff
Align backslash-newline stuff
Reformat comments (a little bit)
Fix inter-character spacing
Add or remove parens on return statements
Add or remove braces on single-statement if/do/while/for statements
Supports embedded SQL 'EXEC SQL' stuff
Highly configurable - 412 configurable options as of version 0.59
The popular pretty-printer uncrustify has at least a dozen different variable alignment parameters that you can specify in its config file. Tony Arnold's project shows you how to use uncrustify as an automator service (which means that you can access it from Xcode or any other editor). Robert Payne suggests using it from a shell script that you can incorporate into your build process.
My guess is that Apple runs its examples through uncrustify or some other pretty-printer before publishing so that they're all formatted using a common style. It may take some fiddling if you want to exactly reproduce Apple's style, but at a minimum it should be pretty easy to get your variable declarations to align the way you want. It's been a while since I played with all the options, but I'd start by looking at the align_var_def_span, align_var_def_thresh, and align_var_def_gap settings.
I don't know whether there is already a shortcut, but you can create a program which accepts a big string as input (variables) and the output would be the aligned version of this. Writing this program should not cause too many problems.
There is no built in function in Xcode to do that automatically, however you can easily align variable names with tab . You have to press tab after the type multiple time and align to the same width .

Create Visual Studio 2010 extension to generate compiler warning

I want to create an extension to recognize specific comments in my code. I will use this to signal code smells by using the //# comment prefix. One feature of this extension will be to generate warnings for each comment encountered while compiling the code. Is it possible to do this?
I don't think you can hook into the compiler to generate warning. However, the "Error List" view aggregates errors, warnings and messages from multiple sources. Would it be good enough for you to simply append to that list?
Here's a link I could find on the subject : http://www.mztools.com/articles/2008/MZ2008022.aspx
There is a sample called CodeSweep that detects certain strings in comments (it is written to look for mild swear words) that adds tasks to your Task List. http://code.msdn.microsoft.com/Code-Sweep-3bfb7bb5 Reading this code could help you write your own extension if you can't use it as-is.
You could also use the existing task functionality and add your own keywords (like the out-of-the-box //HACK and //TODO - you could add //SMELL) which is quicker but gives you less control. http://msdn.microsoft.com/en-us/library/zce12xx2(v=VS.100).aspx. This may be all you need.

SWeave with non-R code chunks?

I often use Sweave to produce LaTeX documents where certain chunks are produced dynamically by executing R code. This works well - but is it also possible to have code chunks that are executed in different ways, e.g. by executing the code in the shell, or by running Perl, and so on? It would be helpful to be able to mix things up, so I could do things like run some shell commands to fetch some data, run some perl commands to pre-process it, and then run R commands to analyze it.
Of course I could use all R chunks and use system() as a poor-man's substitute, but that doesn't make for very pleasant reading in the document.
The new new thing (for multi-language, multi-format) docs may be dexy.it which for example these guys at opengamma.org use as the backend.
Ana, who is behind dexy, is also giving a lot of talks about it so also look at the dexy blog.
It's not directly related to Sweave, but org-babel, which is part of Emacs org-mode, allows to mix code chunks of different languages in one file, pass data from one chunk to another, execute them, and generate LaTeX or HTML export from the output.
You can find more informations about org-mode here :
http://www.orgmode.org/
And to see how org-babel works :
http://orgmode.org/worg/org-contrib/babel/
There is certainly no easy way to do this other than through either foreign language interfaces from R (maybe through inline if it's supported), or system(). For what it's worth, I would just use system(); that should be easy enough.
You can see this previous question about having a Sweave equivalent for Python, where one of the respondents actually creates a separate interface. This can give you a sense what what it would take to embed other languages which may not already be supported. At a minimum, you have to do major hacking on the Sweave driver.
Do you know emacs" org-mode and, more specifically, Babel? If you already know Emacs or are willing to switch to Emacs, then org-mode and Babel are the answer to your question(s).
For instance, I am currently working on a document which contains some shell-scripts, does computations with R and creates flow charts with dot (graphviz). Org-mode can export a variety of formats, e.g. LaTeX (that's what I use).
There is the StatWeave project which uses java rather than R to do the weaving, but will run multiple programs instead of just R. I don't know how hard it would be to get it to do Perl or other programs like that, but the homepage indicates that it already works with R, SAS, Stata, and others:
http://www.cs.uiowa.edu/~rlenth/StatWeave/

Resources