vrtc / pjass (public) (License: BSD) (since 2023-08-03) (hash sha1)
pjass is a free Jass scripting language parser. This repository is a fork of lep/pjass. The goal is to add Debian packaging. As of the time of this writing, it works for current stable, that is Debian 12 (bookworm).
List of commits:
Subject Hash Author Date (UTC)
Added optional variable shadowing warning. 2a0b36f50d2850c4c2ff09f503e6ffad6abf58d9 lep 2016-03-13 14:30:36
Removed the +s and +e<n> flags. 4ab97e853531f2767136602d88c6a86897089eea lep 2016-03-13 10:52:37
Added help target to Makefile a713b03be873950d11e62a7b9e4f2d9a8d2e0945 lep 2016-03-03 16:02:34
Removed strict downcasting check. 5f6ffd725b2ac9d24eff5917d96ceeeaaf748e5f lep 2016-03-03 16:00:49
Added filterreturnsbool check which can be enabled via //# filter 6828cb5e726e7f57cad0ec3f794209c2012c7908 lep 2016-03-03 15:58:59
Moved code into seperate files. 047c531a1c3affb43f53d102c94e765d772ecff3 lep 2016-02-17 20:57:30
Also pack testfiles into the release zip. e2d8ca45c7175b4f0192ddb6202ae71059369495 lep 2016-02-01 15:15:03
Fixed all Warnings. 981e0b8b51eebb4904a42c58c825fa10185f5d23 lep 2016-02-01 15:12:38
Added a test which checks if the utf8-bom can be used as whitespace. cb0ebe275982a65a2ebbd4aca831da4e31739eba lep 2016-01-31 15:04:12
Added utf8 bom as another whitespace token. ea1572ceaa7743fcdff89f206e24540df6358e7b lep 2016-01-31 13:23:27
Added tests to the git repo. 6aca6f760084ee65f8cdd469b18ad5cb37c42ee3 lep 2016-01-17 10:44:56
FreeBsd patches. 6c3acc1dff6ecd5fa486506fabed077be5347afc lep 2016-01-17 10:23:48
Cleaned up string and comment handling in the lexer ebec6e67e248bef82bf92416733b394399c4e1d4 lep 2016-01-17 09:51:44
Added \r, \n (\x10, \x13) as invalid escape characters. 85d0c7e4453c1879bcbc4db8be28527c5ce9f4f7 lep 2016-01-06 13:16:49
Fixed another rare crash. b6edcc3cfd5c1c837318b0efa5ded6f16e86b403 lep 2015-12-21 19:02:41
Fixed various warnings. 6027429ad1895baef4796ac4ae43952ed51f6174 lep 2015-10-28 09:27:40
Added prof target to makefile 9c4b383d3f7416a30a8bde79c735097edaf8d84a lep 2015-10-27 19:14:20
Added gprof support. 374f624967a563dd4c356a3fc104f8ced49fd692 lep 2015-10-27 18:10:13
Changed //! +rb to //# +rb 63af0d3664320cc94ee6e284c308b1983bcfdab2 lep 2015-10-27 17:17:04
Fixed rare segmentation fault. 13a129c8800d306c4117a54cf62cabbb86db3092 lep 2015-10-25 16:11:55
Commit 2a0b36f50d2850c4c2ff09f503e6ffad6abf58d9 - Added optional variable shadowing warning.
Errors for variable shadowing can be enabled via +shadow.
Also found an error where uninitialized variable usaged wouldn't cause
an error in constant functions.
Author: lep
Author date (UTC): 2016-03-13 14:30
Committer name: lep
Committer date (UTC): 2016-03-13 14:30
Parent(s): 4ab97e853531f2767136602d88c6a86897089eea
Signer:
Signing key:
Signing status: N
Tree: fc252aa0cf2950fe1feb0b3e713361178b5573a7
File Lines added Lines deleted
grammar.y 33 78
misc.c 62 2
misc.h 3 0
tests/should-fail/constant-fn-1.j 6 0
tests/should-fail/constant-fn-2.j 4 0
tests/should-fail/shadowing-1.j 8 0
tests/should-fail/shadowing-2.j 7 0
tests/should-fail/shadowing-3.j 4 0
File grammar.y changed (mode: 100644) (index a02117f..f04416a)
... ... funcdefncore: funcbegin localblock codeblock funcend {
347 347 if(retval != gNothing) { if(retval != gNothing) {
348 348 if(!getTypeTag($3.ty)) if(!getTypeTag($3.ty))
349 349 yyerrorline(1, lineno - 1, "Missing return"); yyerrorline(1, lineno - 1, "Missing return");
350 else if ((pjass_flags & flag_rb) || (fnannotations & flag_rb))
350 else if ( flagenabled(flag_rb) )
351 351 canconvertreturn($3.ty, retval, -1); canconvertreturn($3.ty, retval, -1);
352 352 } }
353 353 fnannotations = 0; fnannotations = 0;
 
... ... returnorreturns: RETURNS
363 363 ; ;
364 364
365 365 funcbegin: FUNCTION rid TAKES optparam_list returnorreturns opttype { funcbegin: FUNCTION rid TAKES optparam_list returnorreturns opttype {
366 if (ht_lookup(&locals, $2.str) || ht_lookup(&params, $2.str) || ht_lookup(&globals, $2.str)) {
367 char buf[1024];
368 snprintf(buf, 1024, "%s already defined as variable", $2.str);
369 yyerrorex(3, buf);
370 } else if (ht_lookup(&types, $2.str)) {
371 char buf[1024];
372 snprintf(buf, 1024, "%s already defined as type", $2.str);
373 yyerrorex(3, buf);
374 }
375 inconstant = 0;
376 infunction = 1;
377 curtab = &locals;
378 $$.fd = newfuncdecl();
379 $$.fd->name = strdup($2.str);
380 $$.fd->p = $4.pl;
381 $$.fd->ret = $6.ty;
382 $$.fd->isconst = 0;
383 put(&functions, $$.fd->name, $$.fd);
384 fCurrent = ht_lookup(&functions, $2.str);
385 struct typeandname *tan = $4.pl->head;
386 for (;tan; tan=tan->next) {
387 tan->lineno = lineno;
388 tan->fn = fno;
389 put(&params, strdup(tan->name), newtypeandname(tan->ty, tan->name));
390 if (ht_lookup(&functions, tan->name)) {
391 char buf[1024];
392 snprintf(buf, 1024, "%s already defined as function", tan->name);
393 yyerrorex(3, buf);
394 } else if (ht_lookup(&types, tan->name)) {
395 char buf[1024];
396 snprintf(buf, 1024, "%s already defined as type", tan->name);
397 yyerrorex(3, buf);
366 inconstant = 0;
367 infunction = 1;
368 $$ = checkfunctionheader($2.str, $4.pl, $6.ty);
369 $$.fd->isconst = 0;
398 370 } }
399 }
400 retval = $$.fd->ret;
401 fnannotations = annotations;
402 inblock = 1;
403 inloop = 0;
404 //showfuncdecl($$.fd);
405 }
406 | CONSTANT FUNCTION rid TAKES optparam_list returnorreturns opttype {
407 if (ht_lookup(&locals, $3.str) || ht_lookup(&params, $3.str) || ht_lookup(&globals, $3.str)) {
408 char buf[1024];
409 snprintf(buf, 1024, "%s already defined as variable", $3.str);
410 yyerrorex(3, buf);
411 } else if (ht_lookup(&types, $3.str)) {
412 char buf[1024];
413 snprintf(buf, 1024, "%s already defined as type", $3.str);
414 yyerrorex(3, buf);
415 }
416 inconstant = 1;
417 curtab = &locals;
418 $$.fd = newfuncdecl();
419 $$.fd->name = strdup($3.str);
420 $$.fd->p = $5.pl;
421 $$.fd->ret = $7.ty;
422 $$.fd->isconst = 1;
423 put(&functions, $$.fd->name, $$.fd);
424 struct typeandname *tan = $5.pl->head;
425 for (;tan; tan=tan->next) {
426 tan->lineno = lineno;
427 tan->fn = fno;
428 put(&params, strdup(tan->name), newtypeandname(tan->ty, tan->name));
429 if (ht_lookup(&functions, tan->name)) {
430 char buf[1024];
431 snprintf(buf, 1024, "%s already defined as function", tan->name);
432 yyerrorex(3, buf);
433 } else if (ht_lookup(&types, tan->name)) {
434 char buf[1024];
435 snprintf(buf, 1024, "%s already defined as type", tan->name);
436 yyerrorex(3, buf);
371 | CONSTANT FUNCTION rid TAKES optparam_list returnorreturns opttype {
372 inconstant = 1;
373 infunction = 1;
374 $$ = checkfunctionheader($3.str, $5.pl, $7.ty);
375 $$.fd->isconst = 1;
437 376 } }
438 }
439 retval = $$.fd->ret;
440 inblock = 1;
441 inloop = 0;
442 //showfuncdecl($$.fd);
443 }
444 377 ; ;
445 378
446 379 codeblock: /* empty */ { $$.ty = gEmpty; } codeblock: /* empty */ { $$.ty = gEmpty; }
 
... ... statement: newline { $$.ty = gEmpty; }
499 432 $$.ty = mkretty($2.ty, 1); $$.ty = mkretty($2.ty, 1);
500 433 if(retval == gNothing) if(retval == gNothing)
501 434 yyerrorline(1, lineno - 1, "Cannot return value from function that returns nothing"); yyerrorline(1, lineno - 1, "Cannot return value from function that returns nothing");
502 else if (!(pjass_flags & flag_rb) && !(fnannotations & flag_rb))
435 else if (! flagenabled(flag_rb) )
503 436 canconvertreturn($2.ty, retval, 0); canconvertreturn($2.ty, retval, 0);
504 437 } }
505 438 | RETURN newline { | RETURN newline {
 
... ... vardecl: vartypedecl newline {
748 681 if (tan->isconst) { if (tan->isconst) {
749 682 yyerrorline(3, lineno - 1, "Constants must be initialized"); yyerrorline(3, lineno - 1, "Constants must be initialized");
750 683 } }
684 if(infunction && flagenabled(flag_shadowing) ){
685 if( ht_lookup(&globals, tan->name)){
686 char buf[1024];
687 snprintf(buf, 1024, "Local variable %s shadows global variable", tan->name);
688 yyerrorline(3, lineno -1, buf);
689 } else if( ht_lookup(&params, tan->name)){
690 char buf[1024];
691 snprintf(buf, 1024, "Local variable %s shadows parameter", tan->name);
692 yyerrorline(3, lineno -1, buf);
693 }
694 }
751 695 $$.ty = gNothing; $$.ty = gNothing;
752 696 } }
753 697 | vartypedecl EQUALS expr newline { | vartypedecl EQUALS expr newline {
 
... ... vardecl: vartypedecl newline {
758 702 if(infunction && !ht_lookup(&initialized, tan->name)){ if(infunction && !ht_lookup(&initialized, tan->name)){
759 703 put(&initialized, tan->name, (void*)1); put(&initialized, tan->name, (void*)1);
760 704 } }
705 if(infunction && flagenabled(flag_shadowing) ){
706 if( ht_lookup(&globals, tan->name)){
707 char buf[1024];
708 snprintf(buf, 1024, "Local variable %s shadows global variable", tan->name);
709 yyerror(buf);
710 } else if( ht_lookup(&params, tan->name)){
711 char buf[1024];
712 snprintf(buf, 1024, "Local variable %s shadows parameter", tan->name);
713 yyerror(buf);
714 }
715 }
761 716 canconvert($3.ty, tan->ty, -1); canconvert($3.ty, tan->ty, -1);
762 717 $$.ty = gNothing; $$.ty = gNothing;
763 718 } }
File misc.c changed (mode: 100644) (index 3a98d99..97ee304)
... ... void checkParameters(const struct paramlist *func, const struct paramlist *inp,
278 278 return; return;
279 279 } }
280 280 canconvert(pi->ty, fi->ty, 0); canconvert(pi->ty, fi->ty, 0);
281 bool has_flag = (pjass_flags & flag_filter) || (fnannotations & flag_filter);
282 if(has_flag && mustretbool && typeeq(pi->ty, gCodeReturnsNoBoolean)){
281 if(flagenabled(flag_filter) && mustretbool && typeeq(pi->ty, gCodeReturnsNoBoolean)){
283 282 yyerrorex(semanticerror, "Function passed to Filter or Condition must return a boolean"); yyerrorex(semanticerror, "Function passed to Filter or Condition must return a boolean");
284 283 return; return;
285 284 } }
 
... ... int updateannotation(int cur, char *txt, struct hashtable *flags){
477 476 } }
478 477 return cur; return cur;
479 478 } }
479
480 bool flagenabled(int flag)
481 {
482 return (pjass_flags & flag) || (fnannotations & flag);
483 }
484
485 union node checkfunctionheader(char *fnname, struct paramlist *pl, const struct typenode *retty)
486 {
487 union node ret;
488
489 if (ht_lookup(&locals, fnname) || ht_lookup(&params, fnname) || ht_lookup(&globals, fnname)) {
490 char buf[1024];
491 snprintf(buf, 1024, "%s already defined as variable", fnname);
492 yyerrorex(3, buf);
493 } else if (ht_lookup(&types, fnname)) {
494 char buf[1024];
495 snprintf(buf, 1024, "%s already defined as type", fnname);
496 yyerrorex(3, buf);
497 }
498
499 curtab = &locals;
500 ret.fd = newfuncdecl();
501 ret.fd->name = strdup(fnname);
502 ret.fd->p = pl;
503 ret.fd->ret = retty;
504
505 put(&functions, ret.fd->name, ret.fd);
506
507 fCurrent = ht_lookup(&functions, fnname);
508 fnannotations = annotations;
509
510 struct typeandname *tan = pl->head;
511 for (;tan; tan=tan->next) {
512 tan->lineno = lineno;
513 tan->fn = fno;
514 put(&params, strdup(tan->name), newtypeandname(tan->ty, tan->name));
515 if (ht_lookup(&functions, tan->name)) {
516 char buf[1024];
517 snprintf(buf, 1024, "%s already defined as function", tan->name);
518 yyerrorex(3, buf);
519 } else if (ht_lookup(&types, tan->name)) {
520 char buf[1024];
521 snprintf(buf, 1024, "%s already defined as type", tan->name);
522 yyerrorex(3, buf);
523 }
524
525 if( flagenabled(flag_shadowing) ){
526 if( ht_lookup(&globals, tan->name) ){
527 char buf[1024];
528 snprintf(buf, 1024, "Parmeter %s shadows global variable", tan->name);
529 yyerrorex(3, buf);
530 }
531 }
532
533 }
534 retval = ret.fd->ret;
535 inblock = 1;
536 inloop = 0;
537
538 return ret;
539 }
File misc.h changed (mode: 100644) (index e347434..ff8f701)
... ... void checkeqtest(const struct typenode *a, const struct typenode *b);
68 68 int isflag(char *txt, struct hashtable *flags); int isflag(char *txt, struct hashtable *flags);
69 69 int updateflag(int cur, char *txt, struct hashtable *flags); int updateflag(int cur, char *txt, struct hashtable *flags);
70 70 int updateannotation(int cur, char *txt, struct hashtable *flags); int updateannotation(int cur, char *txt, struct hashtable *flags);
71 bool flagenabled(int flag);
71 72
72 73 extern int pjass_flags; extern int pjass_flags;
73 74
 
... ... extern const struct typenode *retval;
95 96
96 97 extern struct hashtable available_flags; extern struct hashtable available_flags;
97 98
99 union node checkfunctionheader(char *fnname, struct paramlist *pl, const struct typenode *retty);
100
98 101 #endif #endif
File tests/should-fail/constant-fn-1.j added (mode: 100644) (index 0000000..fd3122f)
1 globals
2 integer x
3 endglobals
4 constant function foo takes nothing returns nothing
5 set x = 1
6 endfunction
File tests/should-fail/constant-fn-2.j added (mode: 100644) (index 0000000..f591d0e)
1 constant function x takes nothing returns integer
2 local integer y
3 return y
4 endfunction
File tests/should-fail/shadowing-1.j added (mode: 100644) (index 0000000..b5655c4)
1 globals
2 integer i
3 endglobals
4
5 //# +shadow
6 function foo takes nothing returns nothing
7 local integer i
8 endfunction
File tests/should-fail/shadowing-2.j added (mode: 100644) (index 0000000..6e76475)
1 globals
2 integer i
3 endglobals
4
5 //# +shadow
6 function foo takes integer i returns nothing
7 endfunction
File tests/should-fail/shadowing-3.j added (mode: 100644) (index 0000000..cebe078)
1 //# +shadow
2 function foo takes integer i returns nothing
3 local integer i
4 endfunction
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/vrtc/pjass

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/vrtc/pjass

Clone this repository using git:
git clone git://git.rocketgit.com/user/vrtc/pjass

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main