Author Topic: How to add another programming language to C::B? Preparsers?  (Read 1030 times)

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 5
How to add another programming language to C::B? Preparsers?
« on: February 14, 2017, 09:13:41 am »
C::B has built-in support for C, C++ and Fortran I wonder what steps are necessary to add another language (despite of the compiler configuration part which is "open").
Can anybody please leave a link on documentation how to do this or some detailed steps?

A related question: How to work with pre-parsers? If I understood the docs correctly a first step is to add an entry for the file extension in Settings->Compiler->Other settings. How to go on if the resulting file is neither .c nor .cpp?

Thank you for the response,
cb_mensch

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1548
Re: How to add another programming language to C::B? Preparsers?
« Reply #1 on: February 14, 2017, 03:25:14 pm »
can you elaborate more, what the new language needs?
For the lexer (code coloring) http://wiki.codeblocks.org/index.php/Creating_a_custom_lexer_for_Code::Blocks_editor
For code completion you need to write a plugin... See the code for the python plugin or for the clang code completion or the native code completion...
For compiler integration (if you need a compilation step, you do not give any information on that...)  http://wiki.codeblocks.org/index.php/Installing_a_supported_compiler#Misc._Custom_Compilers
For creating a template for the scripting wizard: http://wiki.codeblocks.org/index.php/Scripting_Code::Blocks

your question does not provide any information to give you some hard answers... Ask exact questions, get exact answers...

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to add another programming language to C::B? Preparsers?
« Reply #2 on: February 14, 2017, 11:02:55 pm »
Thank you, this is actual enough to start the work :-)

Offline gafling

  • Single posting newcomer
  • *
  • Posts: 1
Re: How to add another programming language to C::B? Preparsers?
« Reply #3 on: February 19, 2017, 02:06:13 pm »
@BlueHazzard

One language that I would like to be able to integrate into C::B is Cobol.  Before you scoff you should know that the newer dialects of Cobol (like GnuCobol) resolve the source code down to 'c'.  Therefore it would be helpful to be able to build projects that combine both languages and can manage the each type of source code.

The GNUCobol would need to be able to edit source code, call a pre-compiler which will translate the Cobol to 'c', and then call the 'c' compiler of choice to finish up.  C::B appears to be able to do all that except for the actual source code editing part.

Your post suggests the places where Cobol support would need to be added.  Actually I would find it surprising that this has not been addressed by someone, but maybe not.  In any case any additional suggestions are welcome.

Thank you for your time.


Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1548
Re: How to add another programming language to C::B? Preparsers?
« Reply #4 on: February 19, 2017, 03:01:33 pm »
Actually I would find it surprising that this has not been addressed by someone, but maybe not
Never heard of any cobol integration in codeblocks.

In any case any additional suggestions are welcome.
Good luck and have fun! I am happy to answer any specific question!

FYI: The editor of codeblocks bases on scite, so if you find a lexer for cobol there you can easily integrate it in cb. It seems that there are some efforts but this post is 15 years old...
http://git.net/ml/editors.scite.general/2003-12/msg00127.html

[EDIT:] It seems that codeblocks has an lexer for cobol!  https://sourceforge.net/p/codeblocks/code/HEAD/tree/trunk/src/sdk/wxscintilla/src/scintilla/lexers/LexCOBOL.cxx

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9425
Re: How to add another programming language to C::B? Preparsers?
« Reply #5 on: February 19, 2017, 08:01:10 pm »
One language that I would like to be able to integrate into C::B is Cobol.
A lexer for C::B seems feasible (Cobol is supported by scintilla). However, the build system is not really suited to integrate the compiler easily. It could work with custom pre-compiler steps or customising compiler commands.

However, for Cobol I would recommend an own plugin from scratch, similar how its done for Fortran. You will certainly work mainly on the Cobol files and not on the underlying C-Code, won't you? So you'll need more support than just the lexer. Its really similar to Fortran that also translates to C (well hidden) using the GNU compiler tool chain.

So if you want to start such effort, have a look at the Fortran plugin. For the custom lexer you can do it probably yourself, if you read this:
http://wiki.codeblocks.org/index.php/Creating_a_custom_lexer_for_Code::Blocks_editor
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to add another programming language to C::B? Preparsers?
« Reply #6 on: February 20, 2017, 10:35:34 am »
As GnuCOBOL knows best how to call the underlying C compiler (depending on the C compiler it was built with/configured for and depending on the given command line options to the GnuCOBOL compiler `cobc`) - I guess this is what is done for Fortran, too - I'd suggest to not use it as a pre-compiler step but as a "real" compiler.

A different thing is that COBOL is often used via pre-parsers (for example `EXEC SQL` and lot of COBOL-shop-specific-self-written-pre-parsers), therefore it would be nice to end with an option for the chain Source -> Pre-Parser-Step X (for example a shop specifc one) -> maybe Pre-Parser-Step Y (for example the SQL preparser `dbpre`, Oracle's `procob` or whatever) -> plain COBOL source -> `cobc` (+ internal: `gcc`, `clang` or `cl.exe`).

And yes, I think a full-integrated approach - which seems to need a plugin, given the comments so far - would be best.

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to add another programming language to C::B? Preparsers?
« Reply #7 on: November 02, 2017, 08:41:06 pm »
Just to note: the Scintilla Lexer is still nearly unchanged and can be found at https://sourceforge.net/p/scintilla/code/ci/default/tree/lexers/LexCOBOL.cxx (obviously patches for this lexer should go there, first).
Question: if the file is updated can the main change `Sci_PositionU` / `Sci_Position` instead of `(unsigned) int` be used for C::B or not?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10369
Re: How to add another programming language to C::B? Preparsers?
« Reply #8 on: November 02, 2017, 08:57:19 pm »
We'll update scintilla to 3.7.x soon. So if there is cobol lexer in it will have it.
Scintilla 4.x.x requires c++14/17, so we won't be using it for quite a while...
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to add another programming language to C::B? Preparsers?
« Reply #9 on: November 02, 2017, 09:51:20 pm »
Yes, the COBOL lexer is part of Scintilla 3.7.
The thing that is still unclear for me is how to actually *use* the lexer at all (it would be nice to at least allow file types to be assigned using it) and it is unclear where the keyword list for the lexer comes from (I can provide a word list for multiple COBOL dialects [and actually it would be nice to be able to choose the keyword list somewhere).

A different question would be if / how it is possible to use an external (non-c) compiler for these files...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10369
Re: How to add another programming language to C::B? Preparsers?
« Reply #10 on: November 02, 2017, 09:55:59 pm »
1. Info how to add a lexer: http://wiki.codeblocks.org/index.php/Creating_a_custom_lexer_for_Code::Blocks_editor ?
2. About the compiler: http://wiki.codeblocks.org/index.php/Adding_support_for_non_C/C%2B%2B_files_to_the_build_system
    If I were I would make a setup which depends on an external build system like make/cmake or something similar which supports cobol. This will be the easiest method to maintain this in the long run.
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]