Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

Commit

Permalink
Parser Initial
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Feenstra <evilissimo@gmail.com>
  • Loading branch information
vinzenz committed Jun 4, 2014
1 parent c762277 commit 01fa3bf
Show file tree
Hide file tree
Showing 10 changed files with 654 additions and 50 deletions.
1 change: 1 addition & 0 deletions pypa.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ADD PREDEFINED MACROS HERE!
1 change: 1 addition & 0 deletions pypa.creator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[General]
186 changes: 186 additions & 0 deletions pypa.creator.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-06-04T23:03:31. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{3c951fb4-3dcb-460a-b4a7-ec8e18b6400a}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/evilissimo/devel/apps/pypa</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="GenericProjectManager.GenericMakeStep.Clean">false</value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeArguments"></value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand"></value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="GenericProjectManager.GenericMakeStep.Clean">true</value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeArguments"></value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand"></value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Default</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">/home/evilissimo/devel/apps/pypa/src/parser-test</value>
<value type="bool" key="ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal">true</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">/home/evilissimo/devel/apps/pypa/src</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run /home/evilissimo/devel/apps/pypa/src/parser-test</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">false</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
<value type="QByteArray">{deb9579e-93a4-4a9e-80d7-67bfb4f602e1}</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">15</value>
</data>
</qtcreator>
14 changes: 14 additions & 0 deletions pypa.files
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
src/pypa/ast/ast.cc
src/pypa/ast/ast.hh
src/pypa/lexer/delim.hh
src/pypa/lexer/keyword.hh
src/pypa/lexer/lexer.cc
src/pypa/lexer/lexer.hh
src/pypa/lexer/op.hh
src/pypa/lexer/tokendef.hh
src/pypa/lexer/tokens.hh
src/pypa/parser/parser.cc
src/pypa/parser/parser.hh
src/pypa/parser/test.cc
src/pypa/filebuf.cc
src/pypa/filebuf.hh
1 change: 1 addition & 0 deletions pypa.includes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PYPA_CXXFLAGS=-std=c++11 -I$(top_srcdir)/src $(CXXFLAGS)
PYPA_CXXFLAGS=-std=c++11 -I$(top_srcdir)/src

lib_LTLIBRARIES=libpypa.la
libpypa_la_CXXFLAGS=$(PYPA_CXXFLAGS)
Expand Down
52 changes: 39 additions & 13 deletions src/pypa/ast/ast.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef GUARD_PYPA_AST_AST_HH_INCLUDED
#define GUARD_PYPA_AST_AST_HH_INCLUDED

#include <type_traits>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -36,7 +37,12 @@ enum class AstUnaryOpType {
Sub,
};

enum class AstCompareType {
enum class AstBoolOpType {
And,
Or
};

enum class AstCompareOpType {
Equals,
In,
Is,
Expand Down Expand Up @@ -124,10 +130,19 @@ struct Ast {
typedef std::shared_ptr<Ast> AstPtr;
typedef std::vector<AstPtr> AstLst;

template<typename T>
inline T AstInit(AstType, T*) {
return T{};
}

inline Ast AstInit(AstType t, Ast*) {
return Ast{t, 0, 0};
}

template<AstType Type, typename Base = Ast>
struct AstT : Base {
static constexpr AstType TYPE = Type;
AstT() : Base{Type, 0, 0} {}
AstT() : Base(AstInit(Type, (Base*)nullptr)) {}
};

template<AstType Type, typename Base>
Expand Down Expand Up @@ -166,17 +181,19 @@ struct AstAlias : AstT<AstType::Alias> {
String name;
String as_name;
};
typedef std::vector<AstAlias> AstAliasList;
typedef std::shared_ptr<AstAlias> AstAliasPtr;
typedef std::vector<AstAliasPtr> AstAliasList;

struct AstComprehension : AstT<AstType::Comprehension> {
AstExpr target;
AstExpr iter;
AstExprList ifs;
};
typedef std::vector<AstComprehension> AstComprList;
typedef std::shared_ptr<AstComprehension> AstComprPtr;
typedef std::vector<AstComprPtr> AstComprList;

struct AstSliceKind : Ast {};
typedef std::shared_ptr<AstSliceKind> AstSlicePtr;
typedef std::shared_ptr<AstSliceKind> AstSliceKindPtr;

template<AstType Type>
struct AstSliceT : AstT<Type, AstSliceKind> {
Expand All @@ -190,27 +207,36 @@ struct AstSliceT : AstT<Type, AstSliceKind> {
};

struct AstEllipsis : AstSliceT<AstType::Ellipsis> {};
typedef std::shared_ptr<AstEllipsis> AstEllipsisPtr;

struct AstSlice : AstSliceT<AstType::Slice> {
AstExpr lower;
AstExpr upper;
AstExpr step;
};
typedef std::shared_ptr<AstSlice> AstSlicePtr;

struct AstExtSlice : AstSliceT<AstType::ExtSlice> {
AstExprList dims;
};
typedef std::shared_ptr<AstExtSlice> AstExtSlicePtr;

struct AstIndex : AstSliceT<AstType::Index> {
AstExpr value;
};
typedef std::shared_ptr<AstIndex> AstIndexPtr;

struct AstModule : AstT<AstType::Module> {
AstStmtList body;
};
typedef std::shared_ptr<AstModule> AstModulePtr;

#define PYPA_AST_STMT(AST_TYPE) struct Ast##AST_TYPE : AstStmtT<AstType::AST_TYPE>
#define PYPA_AST_EXPR(AST_TYPE) struct Ast##AST_TYPE : AstExprT<AstType::AST_TYPE>
#define PYPA_AST_STMT(AST_TYPE) \
typedef std::shared_ptr<struct Ast##AST_TYPE> Ast##AST_TYPE##Ptr; \
struct Ast##AST_TYPE : AstStmtT<AstType::AST_TYPE>
#define PYPA_AST_EXPR(AST_TYPE) \
typedef std::shared_ptr<struct Ast##AST_TYPE> Ast##AST_TYPE##Ptr; \
struct Ast##AST_TYPE : AstExprT<AstType::AST_TYPE>

PYPA_AST_STMT(Assert) {
AstExpr expression;
Expand Down Expand Up @@ -241,8 +267,8 @@ PYPA_AST_EXPR(BinOp) {
};

PYPA_AST_EXPR(BoolOp) {
AstType op;
AstExprList values;
AstBoolOpType op;
AstExprList values;
};

PYPA_AST_STMT(Break) {};
Expand All @@ -256,7 +282,7 @@ PYPA_AST_STMT(Call) {
};

PYPA_AST_STMT(Compare) {
std::vector<AstCompareType> ops;
std::vector<AstCompareOpType> ops;
AstExprList comperators;
AstExpr left;
};
Expand Down Expand Up @@ -411,9 +437,9 @@ PYPA_AST_EXPR(Str) {
};

PYPA_AST_EXPR(Subscript) {
AstExpr value;
AstSlicePtr slice;
AstContext context;
AstExpr value;
AstSliceKindPtr slice;
AstContext context;
};

PYPA_AST_STMT(TryExcept) {
Expand Down
Loading

0 comments on commit 01fa3bf

Please sign in to comment.