From 10132e160f98a1922d4bd8c445485d73859187c4 Mon Sep 17 00:00:00 2001 From: Intelligide Date: Thu, 11 Aug 2016 15:11:45 +0200 Subject: [PATCH] Update --- CMakeLists.txt.user | 480 ++++++++++++++++++++++++++++++++++++++++++ src/include/Lexer.hpp | 25 ++- src/include/Token.hpp | 52 ++--- src/lib/Lexer.cpp | 43 +++- utils/src/string.hpp | 9 +- 5 files changed, 572 insertions(+), 37 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000..0c47ec8 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,480 @@ + + + + + + EnvironmentId + {3fb93d8a-9d4c-46aa-821b-80ac79602a86} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.6.1 MinGW 32bit + Desktop Qt 5.6.1 MinGW 32bit + qt.56.win32_mingw49_kit + 0 + 0 + 2 + + + CMAKE_CXX_COMPILER:FILEPATH=C:/Dev/mingw32/bin/g++.exe + + C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build + + + + + all + + true + Make + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + Make + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Default + Default + CMakeProjectManager.CMakeBuildConfiguration + + 1 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + PreBlang + + + C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/tools/PreBlang + -1 + + PreBlang + + CMakeProjectManager.CMakeRunConfiguration.PreBlang + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + Lex + + + C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/tools/lex + -1 + + Lex + + CMakeProjectManager.CMakeRunConfiguration.Lex + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + Blang + + + C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/src + 2 + + Blang + + CMakeProjectManager.CMakeRunConfiguration.Blang + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + LibBlangTests + + + C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/unittests/libblang + -1 + + LibBlangTests (disabled) + + CMakeProjectManager.CMakeRunConfiguration.LibBlangTests + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + lexTest + + + C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/unittests/lex + -1 + + lexTest (disabled) + + CMakeProjectManager.CMakeRunConfiguration.lexTest + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + MustacheTest + + + C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/unittests/Mustache + -1 + + MustacheTest (disabled) + + CMakeProjectManager.CMakeRunConfiguration.MustacheTest + 3768 + false + true + false + false + true + + 6 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/include/Lexer.hpp b/src/include/Lexer.hpp index 7409144..67b3f5b 100644 --- a/src/include/Lexer.hpp +++ b/src/include/Lexer.hpp @@ -8,16 +8,25 @@ #include "TokenList.hpp" namespace Blang{ - class Lexer - { - public: - TokenList tokenize(std::string); - TokenList tokenizeFile(std::string); - private: - static std::map _tokenRegexMap; +class Buffer{ +public: + Buffer(const std::string& text); - }; + char nextChar(); + std::string nextChars(int n); + +private: + std::string _text; +}; + +class Lexer +{ +public: + TokenList tokenize(const std::string& text); + TokenList tokenizeFile(const std::string& filename); + +}; } #endif diff --git a/src/include/Token.hpp b/src/include/Token.hpp index 4094b2e..a410317 100644 --- a/src/include/Token.hpp +++ b/src/include/Token.hpp @@ -6,40 +6,42 @@ #include "SourceLocation.hpp" namespace Blang{ - class Token{ - public: +class Token{ +public: - enum TokenKind{ - Token_StringLiteral, - Token_NumberLiteral, - Token_Operator, - Token_Keyword, - Token_Identifier, - Token_EndOfStatement, - Token_Unknown, - Token_Whitespace, - Token_LeftDelimiter, - Token_RightDelimiter - }; + enum TokenKind{ + Token_StringLiteral, + Token_NumberLiteral, + Token_Operator, + Token_Keyword, + Token_Identifier, + Token_EndOfStatement, + Token_Unknown, + Token_Whitespace, + Token_LeftDelimiter, + Token_RightDelimiter + }; - void setText(std::string); - std::string text(); + Token(TokenKind kind, const std::string& txt); - void setKind(TokenKind); - TokenKind kind(); + void setText(std::string); + std::string text(); - const Token& operator=(Token const & second) const; + void setKind(TokenKind); + TokenKind kind(); - bool operator==(Token const & second) const; + const Token& operator=(Token const & second) const; - private: - SourceLocation _loc; + bool operator==(Token const & second) const; - std::string _text; +private: + SourceLocation _loc; - TokenKind _kind; + std::string _text; - }; + TokenKind _kind; + +}; } #endif diff --git a/src/lib/Lexer.cpp b/src/lib/Lexer.cpp index 95ed68d..307afc4 100644 --- a/src/lib/Lexer.cpp +++ b/src/lib/Lexer.cpp @@ -1,9 +1,46 @@ #include "Lexer.hpp" +#include "TokenList.hpp" -Blang::Lexer::tokenize(std::string text){ +#include +#include +#include +#include + +using namespace Blang; + +static std::map regexMap; + +TokenList Lexer::tokenize(const std::string& t){ + + string text(t); + + std::string::const_iterator itt; + TokenList tokenList; + + for ( itt = text.begin (); itt != text.end (); ++ itt ){ + if(text.substr(itt, itt+1) == "If"){ + itt += 2; + }else if(*itt == '\"'){ + int bpos = itt; + while(*itt != '\"') + itt++; + tokenList << Token(Token::Token_StringLiteral, text.substr(itt, itt+1)); + } else if(std::string(" \t").find(*itt) >= 0){ + tokenList << Token(Token::Token_Whitespace, itt); + } + } } -Blang::Lexer::tokenizeFile(std::string filename){ - +TokenList Lexer::tokenizeFile(const std::string& filename){ + std::ifstream fileStream(filename); + if(fileStream){ + std::string text, line; + while(getline(fileStream, line)){ + text += line + std::endl; + } + tokenizeFile(text); + } else { + std::cout << "Error: Unable to read file" << std::endl; + } } diff --git a/utils/src/string.hpp b/utils/src/string.hpp index ad168d0..60c8d5d 100644 --- a/utils/src/string.hpp +++ b/utils/src/string.hpp @@ -2,6 +2,8 @@ #define BLANGSTRING_HPP #include +#include +#include namespace Blang{ class string : public std::string @@ -14,7 +16,12 @@ namespace Blang{ string ltrim(); string rtrim(); string trim(); + + bool startsWith(string str, bool caseSensitive = true); + bool startsWith(string str,string splitter, bool caseSensitive = true); + bool startsWith(std::list str, bool caseSensitive = true); + bool startsWith(std::regex reg, bool caseSensitive = true); }; } -#endif \ No newline at end of file +#endif