Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
restructure error log when thrown for easy IDE integration with full …
Browse files Browse the repository at this point in the history
…file path
  • Loading branch information
Thecarisma committed May 12, 2019
1 parent 714250a commit 3ae9974
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 65 deletions.
14 changes: 14 additions & 0 deletions examples/basic/Error_1_Test.sim
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
from "../testfiles/test_call_1.sim"
from "../testfiles/test_call_2.sim"
from "../testfiles/test_camel_bake/test_call_1.sim"


block main()
num = 30
if num == 30 {
@"Yes it is number 30"
}
one()
two()
three = new Three()
three.Three(3)
6 changes: 2 additions & 4 deletions examples/basic/test.sim
Original file line number Diff line number Diff line change
@@ -1,8 1,6 @@

num = 30
if num == 30 {
@"Yes it is number 30"
}
final var name:string = "Hello World"
@name

/*from simple.util.Console

Expand Down
4 changes: 4 additions & 0 deletions examples/testfiles/test_call_1.sim
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@

block one()
@"Hello World from 1"
end
5 changes: 5 additions & 0 deletions examples/testfiles/test_call_2.sim
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@


block two()
@"Hello World from 2"
end
48 changes: 25 additions & 23 deletions simple/include/simple_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 59,31 @@ typedef struct Parser {
SimpleState *sState ;
} Parser ;
/* Error Messages */
#define PARSER_ERROR_PARALIST "COMPILER ERROR 0 : Check your parameters, Identifier expected"
#define PARSER_ERROR_CLASSNAME "COMPILER ERROR 1 : Invalid class name"
#define PARSER_ERROR_END "COMPILER ERROR 2 : The structure is not closed missing end | {}"
#define PARSER_ERROR_BLOCKNAME "COMPILER ERROR 3 : Invalid block name"
#define PARSER_ERROR_LISTITEM "COMPILER ERROR 4 : Error in list items"
#define PARSER_ERROR_MISSPARENTHESES "COMPILER ERROR 5 : Parentheses ')' is required "
#define PARSER_ERROR_MISSBRACKETS "COMPILER ERROR 6 : Brackets ']' is required "
#define PARSER_ERROR_PRENTCLASSNAME "COMPILER ERROR 7 : You need to provide a valid parent class name"
#define PARSER_ERROR_EXPROPERATOR "COMPILER ERROR 8 : Unknown expression operator"
#define PARSER_ERROR_NOCLASSDEFINED "COMPILER ERROR 9 : Specified class is not defined"
#define PARSER_ERROR_VARNAME "COMPILER ERROR 10 : Invalid variable name"
#define PARSER_ERROR_NOCATCH "COMPILER ERROR 11 : 'catch' keyword is missing in try | catch"
#define PARSER_ERROR_SWITCHEXPR "COMPILER ERROR 12 : Error in Switch statement expression"
#define PARSER_ERROR_BRACESNOTCLOSED "COMPILER ERROR 13 : Missing closing brace for the opened block"
#define PARSER_ERROR_NUMERICOVERFLOW "COMPILER ERROR 14 : Numeric Overflow!"
#define PARSER_ERROR_MODULENAME "COMPILER ERROR 15 : Error in module name"
#define PARSER_ERROR_BLOCKREDEFINE "COMPILER ERROR 16 : The block is already defined "
#define PARSER_ERROR_USINGBRACTAFTERNUM "COMPILER ERROR 17 : Using '(' after number"
#define PARSER_ERROR_PARENTLIKESUBCLASS "COMPILER ERROR 18 : The parent class name is identical to class name"
#define PARSER_ERROR_ACCESSSELFREF "COMPILER ERROR 19 : Object reference is out of context"
#define PARSER_ERROR_CLASSREDEFINE "COMPILER ERROR 20 : Class is already defined"
#define PARSER_ERROR_ALREADY_VARIADIC "COMPILER ERROR 21 : The block cannot have another parameter after variadic parameter "
#define PARSER_ERROR_INVALID_VARIADIC "COMPILER ERROR 22 : Invalid variadic parameter. Expecting ellipsis '...' after parameter"
#define PARSER_ERROR_FILE_ALREADY_SCANNED "COMPILER ERROR 0 : The source file has already been scanned"
#define PARSER_ERROR_CANNOT_FIND_SOURCE "COMPILER ERROR 1 : Cannot find the source file in search paths"
#define PARSER_ERROR_PARALIST "COMPILER ERROR 2 : Check your parameters, Identifier expected"
#define PARSER_ERROR_CLASSNAME "COMPILER ERROR 3 : Invalid class name"
#define PARSER_ERROR_END "COMPILER ERROR 4 : The structure is not closed missing end | {}"
#define PARSER_ERROR_BLOCKNAME "COMPILER ERROR 5 : Invalid block name"
#define PARSER_ERROR_LISTITEM "COMPILER ERROR 6 : Error in list items"
#define PARSER_ERROR_MISSPARENTHESES "COMPILER ERROR 7 : Parentheses ')' is required "
#define PARSER_ERROR_MISSBRACKETS "COMPILER ERROR 8 : Brackets ']' is required "
#define PARSER_ERROR_PRENTCLASSNAME "COMPILER ERROR 9 : You need to provide a valid parent class name"
#define PARSER_ERROR_EXPROPERATOR "COMPILER ERROR 10 : Unknown expression operator"
#define PARSER_ERROR_NOCLASSDEFINED "COMPILER ERROR 11 : Specified class is not defined"
#define PARSER_ERROR_VARNAME "COMPILER ERROR 12 : Invalid variable name"
#define PARSER_ERROR_NOCATCH "COMPILER ERROR 13 : 'catch' keyword is missing in try | catch"
#define PARSER_ERROR_SWITCHEXPR "COMPILER ERROR 14 : Error in Switch statement expression"
#define PARSER_ERROR_BRACESNOTCLOSED "COMPILER ERROR 15 : Missing closing brace for the opened block"
#define PARSER_ERROR_NUMERICOVERFLOW "COMPILER ERROR 16 : Numeric Overflow!"
#define PARSER_ERROR_MODULENAME "COMPILER ERROR 17 : Error in module name"
#define PARSER_ERROR_BLOCKREDEFINE "COMPILER ERROR 18 : The block is already defined "
#define PARSER_ERROR_USINGBRACTAFTERNUM "COMPILER ERROR 19 : Using '(' after number"
#define PARSER_ERROR_PARENTLIKESUBCLASS "COMPILER ERROR 20 : The parent class name is identical to class name"
#define PARSER_ERROR_ACCESSSELFREF "COMPILER ERROR 21 : Object reference is out of context"
#define PARSER_ERROR_CLASSREDEFINE "COMPILER ERROR 22 : Class is already defined"
#define PARSER_ERROR_ALREADY_VARIADIC "COMPILER ERROR 23 : The block cannot have another parameter after variadic parameter "
#define PARSER_ERROR_INVALID_VARIADIC "COMPILER ERROR 24 : Invalid variadic parameter. Expecting ellipsis '...' after parameter"
/* Blocks */

int accept_token_token( Parser *parser, SCANNER_OPERATOR nType );
Expand Down
5 changes: 5 additions & 0 deletions simple/include/simple_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 20,11 @@
#define SIMPLE_FILE FILE *
#define SIMPLE_OPENFILE(x,y) fopen(x,y)
#define SIMPLE_CLOSEFILE(x) fclose(x)
#ifdef _WIN32
#define full_file_path(x,y,z) GetFullPathName(x, y, z, 0)
#else
#define full_file_path(x,y,z) realpath(x, z)
#endif
#define SIMPLE_READCHAR(x,y,z) y = getc(x) /* z is unused here = number of characters - default = 1 */

/* Data */
Expand Down
1 change: 1 addition & 0 deletions simple/include/simple_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 736,7 @@ SIMPLE_API void simple_vm_setthenullvariable ( VM *vm ) ;
#define SIMPLE_VM_TRACEEVENT_ERROR 4
#define SIMPLE_VM_TRACEEVENT_BEFORECBLOCK 5
#define SIMPLE_VM_TRACEEVENT_AFTERCBLOCK 6

/* Runtime Error Messages */
#define SIMPLE_VM_ERROR_DIVIDEBYZERO "RUNTIME ERROR 1 : Can't divide by zero "
#define SIMPLE_VM_ERROR_INDEXOUTOFRANGE "RUNTIME ERROR 2 : Array Access (Index out of range) "
Expand Down
2 changes: 1 addition & 1 deletion simple/sources/simple_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 252,5 @@ void parser_error ( Parser *parser,const char *cStr )
printf( "\nLine %d -> %s\n",parser->nLineNumber,cStr ) ;
printf( "\tin file %s",file_real_name(simple_list_getstring(parser->sState->files_stack,SimpleActiveFile)) ) ;
}
if (parser->sState->skip_error == 0) { exit(0); }
if (parser->sState->skip_error == 0) { exit(0); }
}
54 changes: 29 additions & 25 deletions simple/sources/simple_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 77,12 @@ int simple_scanner_readfile ( SimpleState *sState,char *file_name )
int x,nSize,is_start_file ;
char* simple_env_path;
char file_name_two[200] ;
char logable_name[SIMPLE_PATHSIZE] ;
char full_file_name[SIMPLE_PATHSIZE] ;
char simple_folder[100] ;
char module_path[SIMPLE_PATHSIZE] ;
strcpy(logable_name,file_name); simple_justfilename(logable_name) ;
strcpy(full_file_name,file_name);
simple_justfilename(full_file_name) ;
is_start_file = 1 ;
/* Check file */
if ( sState->files_list == NULL ) {
sState->files_list = simple_list_new_gc(sState,0);
sState->files_stack = simple_list_new_gc(sState,0);
sState->main_file_path = file_name ;
simple_list_addstring_gc(sState,sState->files_list,logable_name);
simple_list_addstring_gc(sState,sState->files_stack,logable_name);
nFreeFilesList = 1 ;
} else {
if ( simple_list_findstring(sState->files_list,logable_name,0) == 0) {
simple_list_addstring_gc(sState,sState->files_list,logable_name);
simple_list_addstring_gc(sState,sState->files_stack,logable_name);
} else {
//TODO : make warning level 1
if ( sState->nWarning ) {
//printf( "\nWarning : Duplication in FileName, %s\n",logable_name ) ;
}
return 1 ;
}
}
if (!simple_fexists(file_name)) {
for ( x = 1 ; x <= simple_list_getsize(sState->module_paths) ; x ) {
snprintf(module_path, sizeof(module_path), "%s/%s", simple_list_getstring(sState->module_paths,x), file_name);
Expand All @@ -111,6 92,7 @@ int simple_scanner_readfile ( SimpleState *sState,char *file_name )
}
}
}

/* Switch To File Folder */
if (is_start_file) {
strcpy(file_name_two,file_name);
Expand All @@ -122,10 104,32 @@ int simple_scanner_readfile ( SimpleState *sState,char *file_name )
}
/* Read File */
if ( fp==NULL ) {
printf( "COMPILER ERROR 0 : Can't open file/module : %s\n", file_name) ;
exit(-1);
return 0 ;
printf("%s : %s", PARSER_ERROR_CANNOT_FIND_SOURCE, full_file_name);
SIMPLE_CLOSEFILE(fp);
exit(1);
return 0 ;
}

/* Check file */
full_file_path(file_name,SIMPLE_PATHSIZE,full_file_name);
if ( sState->files_list == NULL ) {
sState->files_list = simple_list_new_gc(sState,0);
sState->files_stack = simple_list_new_gc(sState,0);
sState->main_file_path = full_file_name ;
simple_list_addstring_gc(sState,sState->files_list,full_file_name);
simple_list_addstring_gc(sState,sState->files_stack,full_file_name);
nFreeFilesList = 1 ;
} else {
if ( simple_list_findstring(sState->files_list,full_file_name,0) == 0) {
simple_list_addstring_gc(sState,sState->files_list,full_file_name);
simple_list_addstring_gc(sState,sState->files_stack,full_file_name);
} else {
printf("%s : %s%", PARSER_ERROR_FILE_ALREADY_SCANNED, full_file_name);
exit(1);
return 1 ;
}
}

SIMPLE_READCHAR(fp,c,nSize);
scanner = new_simple_scanner(sState);
/* Check Startup file */
Expand Down
31 changes: 19 additions & 12 deletions simple/sources/simple_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 1124,9 @@ SIMPLE_API void simple_vm_showerrormessage ( VM *vm,const char *cStr )
const char *cFile ;
/* Print the Error Message */
printe( "\n%s",cStr ) ;
string = simple_string_new_gc(vm->sState,"at line ");
string = simple_string_new_gc(vm->sState,"at ");
string2 = simple_string_new_gc(vm->sState,"");
simple_string_setfromint_gc(vm->sState,string2,vm->nLineNumber);
simple_string_add_gc(vm->sState,string,string2->str);
/* Print Calling Information */
lBlockCall = 0 ; is_last_block = 1 ;
for ( x = simple_list_getsize(vm->pBlockCallList) ; x >= 1 ; x-- ) {
Expand All @@ -1144,10 1143,9 @@ SIMPLE_API void simple_vm_showerrormessage ( VM *vm,const char *cStr )
** Prepare Message
** In
*/
simple_string_add_gc(vm->sState,string," at ");
simple_string_add_gc(vm->sState,string,simple_list_getstring(list,SIMPLE_BLOCKCL_NAME));
/* Adding () */
simple_string_add_gc(vm->sState,string,"() in file ");
simple_string_add_gc(vm->sState,string,"()");
/* File Name */
if ( lBlockCall == 1 ) {
cFile = (const char *) simple_list_getpointer(list,SIMPLE_BLOCKCL_NEWFILENAME) ;
Expand All @@ -1160,33 1158,42 @@ SIMPLE_API void simple_vm_showerrormessage ( VM *vm,const char *cStr )
cFile = vm->file_name ;
}
}
simple_string_add_gc(vm->sState,string,file_real_name(cFile));
simple_string_add_gc(vm->sState,string," (");
simple_string_add_gc(vm->sState,string,cFile);
simple_string_add_gc(vm->sState,string,":");
simple_string_add_gc(vm->sState,string,string2->str);
simple_string_add_gc(vm->sState,string,")");
printe("\n\t%s", string->str);
/* Called From */
string = simple_string_new_gc(vm->sState,"at line ");
string = simple_string_new_gc(vm->sState,"at ");
string2 = simple_string_new_gc(vm->sState,"");
simple_string_setfromint_gc(vm->sState,string2,simple_list_getint(list,SIMPLE_BLOCKCL_LINENUMBER));
simple_string_add_gc(vm->sState,string,string2->str);
is_last_block = 0;
lBlockCall = 1 ;
}
else {
simple_string_add_gc(vm->sState,string," in ");
simple_string_add_gc(vm->sState,string,file_real_name(simple_list_getstring(list,SIMPLE_BLOCKCL_NAME)));
simple_string_add_gc(vm->sState,string,simple_list_getstring(list,SIMPLE_BLOCKCL_NAME));
}
}
if ( lBlockCall ) {
simple_string_add_gc(vm->sState,string," in file ");
simple_string_add_gc(vm->sState,string,file_real_name(simple_list_getstring(vm->sState->files_list,1)));
simple_string_add_gc(vm->sState,string,"(");
simple_string_add_gc(vm->sState,string,simple_list_getstring(vm->sState->files_list,1));
simple_string_add_gc(vm->sState,string,":");
simple_string_add_gc(vm->sState,string,string2->str);
simple_string_add_gc(vm->sState,string,")");
} else {
if ( vm->within_class ) {
cFile = vm->file_name_within_class ;
}
else {
cFile = file_real_name(vm->file_name) ;
cFile = vm->file_name ;
}
simple_string_add_gc(vm->sState,string," in file ");
simple_string_add_gc(vm->sState,string,"(");
simple_string_add_gc(vm->sState,string,cFile);
simple_string_add_gc(vm->sState,string,":");
simple_string_add_gc(vm->sState,string,string2->str);
simple_string_add_gc(vm->sState,string,")");
}
printe("\n\t%s\n", string->str);
simple_string_delete_gc(vm->sState,string);
Expand Down

0 comments on commit 3ae9974

Please sign in to comment.