Moving project files into subdirs
This commit is contained in:
parent
f77eb930ed
commit
bf7fba3646
@ -1,18 +1,10 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
project(langkit)
|
||||
project(jaytea)
|
||||
|
||||
SET (CMAKE_BUILD_TYPE gdb)
|
||||
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
|
||||
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
|
||||
|
||||
find_package( Boost 1.36.0 COMPONENTS regex)
|
||||
if(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
include_directories(langkit boxedcpp)
|
||||
|
||||
add_executable(langkit_test langkit/main.cpp langkit/langkit_lexer.cpp langkit/langkit_parser.cpp)
|
||||
target_link_libraries(langkit_test ${Boost_LIBRARIES})
|
||||
|
||||
add_executable(boxedcpp_test boxedcpp/test.cpp)
|
||||
endif()
|
||||
add_subdirectory(langkit bin)
|
||||
add_subdirectory(boxedcpp bin)
|
||||
|
1
bin/placeholder.txt
Normal file
1
bin/placeholder.txt
Normal file
@ -0,0 +1 @@
|
||||
This is a placeholder
|
15
boxedcpp/CMakeLists.txt
Normal file
15
boxedcpp/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
project(boxedcpp)
|
||||
|
||||
SET (CMAKE_BUILD_TYPE gdb)
|
||||
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
|
||||
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
|
||||
|
||||
find_package( Boost 1.36.0 COMPONENTS regex)
|
||||
if(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
include_directories(.)
|
||||
|
||||
add_executable(boxedcpp_test test.cpp)
|
||||
endif()
|
15
langkit/CMakeLists.txt
Normal file
15
langkit/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
project(langkit)
|
||||
|
||||
SET (CMAKE_BUILD_TYPE gdb)
|
||||
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
|
||||
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
|
||||
|
||||
find_package( Boost 1.36.0 COMPONENTS regex)
|
||||
if(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
add_executable(langkit_test main.cpp langkit_lexer.cpp langkit_parser.cpp)
|
||||
target_link_libraries(langkit_test ${Boost_LIBRARIES})
|
||||
endif()
|
@ -48,15 +48,24 @@ std::pair<Token_Iterator, bool> Or_Rule(Token_Iterator iter, Token_Iterator end,
|
||||
std::pair<Token_Iterator, bool> result = lhs(iter, end, parent);
|
||||
|
||||
if (result.second) {
|
||||
if (new_id != -1) {
|
||||
prev_parent->children.push_back(parent);
|
||||
}
|
||||
|
||||
parent->filename = (*iter)->filename;
|
||||
parent->start = (*iter)->start;
|
||||
parent->end = (*(result.first - 1))->end;
|
||||
|
||||
|
||||
return std::pair<Token_Iterator, bool>(result.first, true);
|
||||
}
|
||||
else {
|
||||
result = rhs(iter, end, parent);
|
||||
if (result.second) {
|
||||
if (new_id != -1) {
|
||||
|
||||
parent->filename = (*iter)->filename;
|
||||
parent->start = (*iter)->start;
|
||||
parent->end = (*(result.first - 1))->end;
|
||||
|
||||
|
||||
prev_parent->children.push_back(parent);
|
||||
}
|
||||
return std::pair<Token_Iterator, bool>(result.first, true);
|
||||
@ -90,6 +99,12 @@ std::pair<Token_Iterator, bool> And_Rule(Token_Iterator iter, Token_Iterator end
|
||||
result = rhs(result.first, end, parent);
|
||||
if (result.second) {
|
||||
if (new_id != -1) {
|
||||
|
||||
parent->filename = (*iter)->filename;
|
||||
parent->start = (*iter)->start;
|
||||
parent->end = (*(result.first - 1))->end;
|
||||
|
||||
|
||||
prev_parent->children.push_back(parent);
|
||||
}
|
||||
return std::pair<Token_Iterator, bool>(result.first, true);
|
||||
@ -110,18 +125,25 @@ std::pair<Token_Iterator, bool> Kleene_Rule
|
||||
|
||||
TokenPtr prev_parent = parent;
|
||||
std::pair<Token_Iterator, bool> result;
|
||||
Token_Iterator new_iter = iter;
|
||||
|
||||
if (new_id != -1) {
|
||||
parent = TokenPtr(new Token("", new_id, parent->filename));
|
||||
}
|
||||
|
||||
result.second = true;
|
||||
while ((iter != end) && (result.second == true)) {
|
||||
while ((new_iter != end) && (result.second == true)) {
|
||||
result = rule(iter, end, parent);
|
||||
iter = result.first;
|
||||
new_iter = result.first;
|
||||
}
|
||||
|
||||
if (new_id != -1) {
|
||||
|
||||
parent->filename = (*iter)->filename;
|
||||
parent->start = (*iter)->start;
|
||||
parent->end = (*(result.first - 1))->end;
|
||||
|
||||
|
||||
prev_parent->children.push_back(parent);
|
||||
}
|
||||
return std::pair<Token_Iterator, bool>(result.first, true);
|
||||
@ -153,6 +175,12 @@ std::pair<Token_Iterator, bool> Plus_Rule
|
||||
}
|
||||
|
||||
if (new_id != -1) {
|
||||
|
||||
parent->filename = (*iter)->filename;
|
||||
parent->start = (*iter)->start;
|
||||
parent->end = (*(result.first - 1))->end;
|
||||
|
||||
|
||||
prev_parent->children.push_back(parent);
|
||||
}
|
||||
|
||||
@ -172,6 +200,7 @@ std::pair<Token_Iterator, bool> Optional_Rule
|
||||
(Token_Iterator iter, Token_Iterator end, TokenPtr parent, bool keep, int new_id, struct Rule rule) {
|
||||
|
||||
TokenPtr prev_parent = parent;
|
||||
Token_Iterator new_iter = iter;
|
||||
|
||||
if (new_id != -1) {
|
||||
parent = TokenPtr(new Token("", new_id, parent->filename));
|
||||
@ -179,12 +208,18 @@ std::pair<Token_Iterator, bool> Optional_Rule
|
||||
|
||||
std::pair<Token_Iterator, bool> result;
|
||||
result.second = true;
|
||||
if ((iter != end) && (result.second == true)) {
|
||||
if ((new_iter != end) && (result.second == true)) {
|
||||
result = rule(iter, end, parent);
|
||||
iter = result.first;
|
||||
new_iter = result.first;
|
||||
}
|
||||
|
||||
if (new_id != -1) {
|
||||
|
||||
parent->filename = (*iter)->filename;
|
||||
parent->start = (*iter)->start;
|
||||
parent->end = (*(result.first - 1))->end;
|
||||
|
||||
|
||||
prev_parent->children.push_back(parent);
|
||||
}
|
||||
return std::pair<Token_Iterator, bool>(result.first, true);
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
class TokenType { public: enum Type { Whitespace, Identifier, Number, Operator, Parens_Open, Parens_Close,
|
||||
Square_Open, Square_Close, Curly_Open, Curly_Close, Comma, Quoted_String, Single_Quoted_String, Carriage_Return, Semicolon,
|
||||
Function_Def}; };
|
||||
Function_Def, Scoped_Block, Statement, Equation, Return}; };
|
||||
|
||||
void debug_print(TokenPtr token, std::string prepend) {
|
||||
std::cout << prepend << "Token: " << token->text << "(" << token->identifier << ") @ " << token->filename << ": (" << token->start.column
|
||||
@ -67,9 +67,31 @@ void parse(std::vector<TokenPtr> &tokens) {
|
||||
//Example: "def add(x,y)"
|
||||
|
||||
Rule params;
|
||||
Rule block(TokenType::Scoped_Block);
|
||||
Rule rule(TokenType::Function_Def);
|
||||
rule = Ign(Str("def")) << Id(TokenType::Identifier) << ~(Ign(Str("(")) << ~params << Ign(Str(")")));
|
||||
Rule statement(TokenType::Statement);
|
||||
Rule return_statement(TokenType::Return);
|
||||
|
||||
rule = Ign(Str("def")) << Id(TokenType::Identifier) << ~(Ign(Str("(")) << ~params << Ign(Str(")"))) << block;
|
||||
params = Id(TokenType::Identifier) << *(Ign(Str(",")) << Id(TokenType::Identifier));
|
||||
block = Ign(Str("{")) << ~return_statement << Ign(Str("}"));
|
||||
return_statement = Ign(Str("return")) << Id(TokenType::Identifier) << Str("+") << Id(TokenType::Identifier);
|
||||
|
||||
|
||||
/*
|
||||
Rule rule(3);
|
||||
rule = Ign(Str("Bob")) << Str("Fred");
|
||||
*/
|
||||
|
||||
/*
|
||||
statement = equation;
|
||||
equation = Id(TokenType::Identifier) << Str("+") << Id(TokenType::Identifier);
|
||||
*/
|
||||
|
||||
/*
|
||||
Rule rule(TokenType::Function_Def);
|
||||
rule = +Str("Bob");
|
||||
*/
|
||||
|
||||
Token_Iterator iter = tokens.begin(), end = tokens.end();
|
||||
TokenPtr parent(new Token("Root", 0, "test"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user