Author Topic: JADE - generate-keywords.cc  (Read 4122 times)

Offline AIR

  • Moderator
  • Posts: 932
  • Coder
JADE - generate-keywords.cc
« on: December 22, 2018, 06:19:22 PM »
I originally used BASH with the 'ack' program to generate the Keywords.txt and Prototypes.txt files for Jade.

Problem was that 'ack' is a 3rd party program which isn't typically installed on Linux/macOS machines (I don't even know if there's a version for Windows, to be honest).

I rewrote the script using Python, but while it typically comes pre-installed on Linux/macOS, it definitely is not pre-installed on Windows.

Rather than require the installation on OS's that don't have Python installed, I decided to re-write the generate-keywords using Jade itself.

Here is what it looks like, feedback is encouraged!!!

Code: C
  1. #include "jade.h"
  2.  
  3. /*
  4.  *  generate-keywords
  5.  *  
  6.  *  Jade program to generate Jade Keywords.txt and Prototypes.txt files
  7.  *
  8.  *  Copyright 2018, Armando I. Rivera
  9.  *  
  10.  *  License:  MIT
  11.  *
  12.  *  Compile with:  g++ -std=c++11 -O2 -s generate-keywords.cc -o generate-keywords
  13. */
  14.  
  15.  
  16. SUB jadeKeywordProto(STRING srcFile,STRING query, STRARRAY& sarray) BEGIN
  17.     REGQUERY term(query);
  18.     STRING src(LOADFILE$(srcFile));
  19.     std::sregex_token_iterator it(src.begin(), src.end(), term,2);
  20.  
  21.     WHILE ( it != std::sregex_token_iterator() ) BEGIN
  22.         IF ( NOT it->str().empty() && it->str() != " "  ) THEN
  23.             sarray.push_back(it->str());
  24.         ENDIF
  25.         it++;
  26.     WEND
  27. END
  28.  
  29.  
  30. MAIN
  31.     STRARRAY KEYWORDS,PROTOTYPES;
  32.  
  33.     jadeKeywordProto("runtime.inc", "(FUNCTION|SUB) (.+\\)) BEGIN", PROTOTYPES);
  34.     jadeKeywordProto("header.inc", "(#define\\s+|typedef .+ )(\\w+\\$|\\w+)", KEYWORDS);
  35.     jadeKeywordProto("runtime.inc", "(FUNCTION .+ |SUB|SUB )(\\w+|\\w+\\$) \\(.+ BEGIN", KEYWORDS);
  36.  
  37.     OUTFILE keyFile("KEYWORDS.txt");
  38.     FOR (VAR item IN KEYWORDS) BEGIN
  39.         keyFile << item << std::endl;
  40.     END
  41.  
  42.     OUTFILE protoFile("PROTOTYPES.txt");
  43.     FOR (VAR item IN PROTOTYPES) BEGIN
  44.         protoFile << item << std::endl;
  45.     END    
  46.  
  47. ENDMAIN
  48.  
  49.  

Keep in mind that this is C++; I didn't use DIM, etc because it's redundant with my Jade implementation, and just clutters things up.


AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: JADE - generate-keywords.cc
« Reply #1 on: December 22, 2018, 07:03:43 PM »
Quote
feedback is encouraged!!!

I would like to see JADE hide variable typing altogether. (like SB)

While on the SB topic, have you thought about using SB to generate your JADE keywords?
« Last Edit: December 22, 2018, 07:10:47 PM by John »

Offline AIR

  • Moderator
  • Posts: 932
  • Coder
Re: JADE - generate-keywords.cc
« Reply #2 on: December 22, 2018, 07:19:43 PM »
For example?

Offline AIR

  • Moderator
  • Posts: 932
  • Coder
Re: JADE - generate-keywords.cc
« Reply #3 on: December 22, 2018, 07:30:30 PM »
Quote
feedback is encouraged!!!

While on the SB topic, have you thought about using SB to generate your JADE keywords?

No, that's an additional dependency, which I'm trying to avoid.  Otherwise, I would have just stayed with Bash/Ack or Python.

But you're more than welcome to give it a try in SB, if you like.

AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: JADE - generate-keywords.cc
« Reply #4 on: December 22, 2018, 07:31:49 PM »
Code: ScriptBasic
  1. a = 1
  2. b = "2"
  3. c[1000000] = .3
  4.  
  5. PRINT a + b,"\n"
  6. PRINT a & b,"\n"
  7. PRINT FORMAT("%~#.#~\n",c[1000000])
  8.  


$ scriba varless.sb
3
12
0.3
$



Offline AIR

  • Moderator
  • Posts: 932
  • Coder
Re: JADE - generate-keywords.cc
« Reply #5 on: December 22, 2018, 09:09:13 PM »
Code: ScriptBasic
  1. a = 1
  2. b = "2"
  3. c[1000000] = .3
  4.  
  5. PRINT a + b,"\n"
  6. PRINT a & b,"\n"
  7. PRINT FORMAT("%~#.#~\n",c[1000000])
  8.  


$ scriba varless.sb
3
12
0.3
$


Because JADE is not using a Parser/Lexer like SB is (JADE uses the c++ preprocessor for a lot of stuff), doing it like you ask isn't possible.

Doesn't mean I can't duplicate what your output is, though, with only a single explicit declaration (for the array):

Code: C
  1. #include "jade.h"
  2.  
  3.  
  4. MAIN
  5.     VAR a=1;
  6.     VAR b="2";
  7.     ARRAY<double>c(1000001, .3);
  8.  
  9.     PRINT(a+VAL(b));
  10.     PRINT(a,b);
  11.     PRINT(c[1000000]);
  12. END

[riveraa@MPD /Users/Shared/src/Jade] $ ./varless
3
12
0.3


AIR.