added AUTOMATE base code
This commit is contained in:
parent
30c6e8a607
commit
ecad8a63e2
18
src/Makefile
18
src/Makefile
|
@ -7,11 +7,25 @@ compile: install
|
|||
|
||||
install: linter
|
||||
|
||||
clean:
|
||||
rm *.o;
|
||||
rm lib/*.o;
|
||||
rm linter;
|
||||
|
||||
|
||||
|
||||
lib/common.o: lib/common/common.h lib/common/common.c
|
||||
gcc -c -o lib/common.o lib/common/common.c;
|
||||
|
||||
lib/automate.o: lib/automate/automate.h lib/automate/automate.c
|
||||
gcc -c -o lib/automate.o lib/automate/automate.c;
|
||||
|
||||
lib/scope.o: lib/scope/scope.h lib/scope/scope.c
|
||||
gcc -c -o lib/scope.o lib/scope/scope.c;
|
||||
|
||||
linter.o: linter.h linter.c
|
||||
gcc -c -o linter.o linter.c;
|
||||
|
||||
linter: linter.o
|
||||
gcc $(GCCARGV) -o linter linter.o;
|
||||
linter: lib/scope.o lib/automate.o lib/common/common.o linter.o
|
||||
gcc $(GCCARGV) -o linter lib/automate.o lib/scope.o lib/common/common.o linter.o;
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/**************************
|
||||
* Automate *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#include "automate.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int browse(struct Automate pAutomate, const char* pString){
|
||||
|
||||
/* [0] Initialize variables
|
||||
=========================================================*/
|
||||
unsigned int strIndex = 0; // String current char index
|
||||
int c, len, i, l; // counters
|
||||
|
||||
|
||||
/* [1] For each char
|
||||
=========================================================*/
|
||||
c = 0; len = strlen(pString);
|
||||
|
||||
for( ; c < len ; c++ ){
|
||||
|
||||
/* (1) Check if the current char can lead to a state
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Check current state choices */
|
||||
i = 0; l = pAutomate.states[pAutomate.state].n;
|
||||
|
||||
for( ; i < l ; i++ ){
|
||||
|
||||
/* (2) If part of set */
|
||||
if( is_part(pString[strIndex], pAutomate.set[pAutomate.states[pAutomate.state].set[i]]) == 1 ){
|
||||
pAutomate.state = pAutomate.states[pAutomate.state].state[i];
|
||||
strIndex++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return pAutomate.state;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char is_part(const char pChar, const char* pSet){
|
||||
|
||||
unsigned int a;
|
||||
unsigned int A = strlen(pSet);
|
||||
|
||||
/* [1] For each char of @pSet
|
||||
=========================================================*/
|
||||
for( a = 0 ; a < A ; a++ )
|
||||
if( pChar == pSet[a] )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**************************
|
||||
* Automate *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#ifndef _LIB_AUTOMATE_AUTOMATE_H_
|
||||
#define _LIB_AUTOMATE_AUTOMATE_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
struct AutomateState{
|
||||
unsigned int n; // number of associations
|
||||
char* set; // list of set_id
|
||||
char* state; // list of state_id
|
||||
};
|
||||
|
||||
struct Automate{
|
||||
struct AutomateState* states; // states
|
||||
unsigned int n_state; // Max state index
|
||||
unsigned int state; // current state index
|
||||
unsigned int n_set; // Max set index
|
||||
char** set; // list of sets
|
||||
};
|
||||
|
||||
|
||||
/* Try to browse an automate with a string
|
||||
*
|
||||
* @pAutomate The current automate
|
||||
* @pString The string to test
|
||||
*
|
||||
*
|
||||
* @return state<int> The final state we can browse to
|
||||
*
|
||||
*/
|
||||
int browse(struct Automate pAutomate, const char* pString);
|
||||
|
||||
|
||||
|
||||
/* Checks if a char is part of a set
|
||||
*
|
||||
* @pChar The char to test
|
||||
* @pSet The set to test in
|
||||
*
|
||||
* @return is_part<char> 1 if is part, 0 if not
|
||||
*
|
||||
*/
|
||||
char is_part(const char pChar, const char* pSet);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,64 @@
|
|||
/**************************
|
||||
* Common *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#include "common.h"
|
||||
|
||||
int isolate_line(char* pLine, const size_t pCount){
|
||||
|
||||
unsigned int start = 0;
|
||||
unsigned int end = 0;
|
||||
|
||||
/* [1] Copy input line
|
||||
=========================================================*/
|
||||
char input[pCount+1];
|
||||
strcpy(input, pLine);
|
||||
|
||||
/* [2] Remove surrounding whitespace
|
||||
=========================================================*/
|
||||
/* (1) Starting whitespace */
|
||||
while( input[start] == ' ' || input[start] == '\t' ) start++;
|
||||
|
||||
/* (2) Trailing whitespace */
|
||||
while( input[pCount-end] == ' ' || input[pCount-end] == '\t' ) end++;
|
||||
|
||||
|
||||
/* [3] Copy isolated in buffer
|
||||
=========================================================*/
|
||||
bzero(pLine, pCount);
|
||||
sprintf(pLine, "%.*s", (int)pCount-end-start, input+start);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getIndentation(char* pLine, const size_t pCount){
|
||||
|
||||
unsigned int c;
|
||||
unsigned int depth = 0;
|
||||
|
||||
|
||||
/* [1] Count number of tabs
|
||||
=========================================================*/
|
||||
for( c = 0 ; c < pCount ; c++ )
|
||||
if( pLine[c] == '\t' ) depth++;
|
||||
else break;
|
||||
|
||||
/* [2] Count number of 4x spaces
|
||||
=========================================================*/
|
||||
if( depth == 0 ){
|
||||
for( c = 0 ; c < pCount ; c++ )
|
||||
if( pLine[c] == ' ' ) depth++;
|
||||
else break;
|
||||
|
||||
depth /= 4;
|
||||
}
|
||||
|
||||
return depth;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/**************************
|
||||
* Common *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#ifndef _LIB_COMMON_COMMON_H_
|
||||
#define _LIB_COMMON_COMMON_H_
|
||||
|
||||
/* GLOBAL */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* LOCAL */
|
||||
|
||||
/* SIGNATURES */
|
||||
|
||||
/* [1] Isolates the useful content of a line
|
||||
*
|
||||
* @pLine<char*> Input line char array
|
||||
* @pCount<size_t> Line length (strlen)
|
||||
*
|
||||
* @return status<int> 0 if Success, -1 on failure
|
||||
*
|
||||
*/
|
||||
int isolate_line(char* pLine, const size_t pCount);
|
||||
|
||||
|
||||
/* [2] Get indentation depth
|
||||
*
|
||||
* @pLine<char*> Input line char array
|
||||
* @pCount<size_t> Line length (strlen)
|
||||
*
|
||||
* @return depth<int> Depth or -1 on failure
|
||||
*
|
||||
*/
|
||||
int getIndentation(char* pLine, const size_t pCount);
|
||||
|
||||
|
||||
#endif
|
|
@ -10,19 +10,21 @@
|
|||
#ifndef _LIB_PHP_CONST_H_
|
||||
#define _LIB_PHP_CONST_H_
|
||||
|
||||
typedef enum PHP_SCOPE{
|
||||
#define MAX_LINE 512
|
||||
|
||||
typedef enum{
|
||||
PHP = 0x00, // <?php ... ?>
|
||||
FUNCTION = 0x01,
|
||||
CLASS = 0x02,
|
||||
FUNCTION = 0x01, // function name(){ ... }
|
||||
CLASS = 0x02, // class name{ ... }
|
||||
WHILE = 0x04,
|
||||
FOR = 0x08,
|
||||
FOREACH = 0x10,
|
||||
IF = 0x20,
|
||||
ELSE = 0x40,
|
||||
ELSIF = 0x80
|
||||
};
|
||||
} PHP_SCOPE;
|
||||
|
||||
typedef enum PHP_STATEMENT{
|
||||
typedef enum{
|
||||
VOID = 0x0000, // \r?\n
|
||||
DECLARE_VAR = 0x0001, // \s?\$(\w+)(\[(?:["']\w+["']|\$\w+)\])*;
|
||||
ASSIGN_VAR = 0x0002, // \s?\$(\w+)\s*([\.\+\/\*|&-]?=)\s*(.+);
|
||||
|
@ -35,31 +37,32 @@
|
|||
COMMENT = 0x0100, // //, /**/, ...
|
||||
RETURN = 0x0200, // return ...
|
||||
ECHO = 0x0400, // echo "", echo $var, ...
|
||||
DEPENDENCY = 0x0800 // require_once, include, require, ...
|
||||
PROPERTY = 0x1000 // require_once, include, require, ...
|
||||
DEPENDENCY = 0x0800, // require_once, include, require, ...
|
||||
PROPERTY = 0x1000, // require_once, include, require, ...
|
||||
METHOD = 0x2000 // require_once, include, require, ...
|
||||
};
|
||||
} PHP_STATEMENT;
|
||||
|
||||
typedef enum PHP_COMMENT{
|
||||
typedef enum{
|
||||
INLINE = 0x001,
|
||||
MULTILINE = 0x002,
|
||||
CHAPTER = 0x004,
|
||||
SUBCHAPTER = 0x008,
|
||||
SECTION = 0x010,
|
||||
SUBSECTION = 0x020,
|
||||
FUNCTION_HEAD = 0x040,
|
||||
FUNCTION_CHAPTER_HEAD = 0x080,
|
||||
FUNCTION_SUBCHAPTER_HEAD = 0x100,
|
||||
FUNC_HEAD = 0x040,
|
||||
FUNC_CHAPTER_HEAD = 0x080,
|
||||
FUNC_SUBCHAPTER_HEAD = 0x100,
|
||||
TITLE = 0x200,
|
||||
HEADER = 0x400
|
||||
};
|
||||
} PHP_COMMENT;
|
||||
|
||||
typedef enum PHP_TYPE{
|
||||
NULL = 0x00, // null
|
||||
typedef enum{
|
||||
NUL = 0x00, // null
|
||||
STRING = 0x01, // ".+" | '.+' | STRING.STRING
|
||||
INT = 0x02, // -?\d+
|
||||
FLOAT = 0x04, // -?\d*.\d+
|
||||
ARRAY = 0x08 // \[((, )?(PHP_TYPE|CLASS|FUNC|VAR))\]
|
||||
};
|
||||
} PHP_TYPE;
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue