AST no templates

This commit is contained in:
ridiculousfish 2013-07-25 15:24:22 -07:00
parent 3e3eefc2dc
commit 4f8d4f378c
5 changed files with 133 additions and 5 deletions

View file

@ -152,6 +152,7 @@
D0F019FD15A977CA0034B3B1 /* config.fish in CopyFiles */ = {isa = PBXBuildFile; fileRef = D0C4FD9415A7D7EE00212EF1 /* config.fish */; }; D0F019FD15A977CA0034B3B1 /* config.fish in CopyFiles */ = {isa = PBXBuildFile; fileRef = D0C4FD9415A7D7EE00212EF1 /* config.fish */; };
D0F01A0315A978910034B3B1 /* osx_fish_launcher.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D02AFA159871B2008E62BD /* osx_fish_launcher.m */; }; D0F01A0315A978910034B3B1 /* osx_fish_launcher.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D02AFA159871B2008E62BD /* osx_fish_launcher.m */; };
D0F01A0515A978A10034B3B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0CBD583159EEE010024809C /* Foundation.framework */; }; D0F01A0515A978A10034B3B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0CBD583159EEE010024809C /* Foundation.framework */; };
D0FE8EE8179FB760008C9F21 /* parse_productions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D0FE8EE7179FB75F008C9F21 /* parse_productions.cpp */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -465,7 +466,8 @@
D0D2693C159835CA005D9B9C /* fish */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fish; sourceTree = BUILT_PRODUCTS_DIR; }; D0D2693C159835CA005D9B9C /* fish */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fish; sourceTree = BUILT_PRODUCTS_DIR; };
D0F3373A1506DE3C00ECEFC0 /* builtin_test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_test.cpp; sourceTree = "<group>"; }; D0F3373A1506DE3C00ECEFC0 /* builtin_test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_test.cpp; sourceTree = "<group>"; };
D0F5E28415A7A32D00315DFF /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; }; D0F5E28415A7A32D00315DFF /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
D0FE8EE6179CA8A5008C9F21 /* parse_tree_construction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parse_tree_construction.h; sourceTree = "<group>"; }; D0FE8EE6179CA8A5008C9F21 /* parse_productions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parse_productions.h; sourceTree = "<group>"; };
D0FE8EE7179FB75F008C9F21 /* parse_productions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parse_productions.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -589,8 +591,9 @@
D0A0853C13B3ACEE0099B651 /* exec.cpp */, D0A0853C13B3ACEE0099B651 /* exec.cpp */,
D0A0850C13B3ACEE0099B651 /* expand.h */, D0A0850C13B3ACEE0099B651 /* expand.h */,
D0A0853D13B3ACEE0099B651 /* expand.cpp */, D0A0853D13B3ACEE0099B651 /* expand.cpp */,
D0FE8EE6179CA8A5008C9F21 /* parse_productions.h */,
D0FE8EE7179FB75F008C9F21 /* parse_productions.cpp */,
D0C52F361765284C00BFAB82 /* parse_tree.h */, D0C52F361765284C00BFAB82 /* parse_tree.h */,
D0FE8EE6179CA8A5008C9F21 /* parse_tree_construction.h */,
D0C52F351765284C00BFAB82 /* parse_tree.cpp */, D0C52F351765284C00BFAB82 /* parse_tree.cpp */,
D0C52F341765281F00BFAB82 /* parse_exec.h */, D0C52F341765281F00BFAB82 /* parse_exec.h */,
D0C52F331765281F00BFAB82 /* parse_exec.cpp */, D0C52F331765281F00BFAB82 /* parse_exec.cpp */,
@ -1116,6 +1119,7 @@
D0D02A89159839DF008E62BD /* fish.cpp in Sources */, D0D02A89159839DF008E62BD /* fish.cpp in Sources */,
D0C52F371765284C00BFAB82 /* parse_tree.cpp in Sources */, D0C52F371765284C00BFAB82 /* parse_tree.cpp in Sources */,
D0C52F381765720600BFAB82 /* parse_exec.cpp in Sources */, D0C52F381765720600BFAB82 /* parse_exec.cpp in Sources */,
D0FE8EE8179FB760008C9F21 /* parse_productions.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

63
parse_productions.cpp Normal file
View file

@ -0,0 +1,63 @@
#include "parse_productions.h"
using namespace parse_productions;
#define PRODUCTIONS(sym) static const Production_t sym##_productions
PRODUCTIONS(job_list) =
{
{},
{symbol_job, symbol_job_list},
{parse_token_type_end, symbol_job_list}
};
/* A job_list is a list of jobs, separated by semicolons or newlines */
DEC(job_list) {
symbol_job_list,
{
{},
{symbol_job, symbol_job_list},
{parse_token_type_end, symbol_job_list}
},
resolve_job_list
};
static int resolve_job_list(parse_token_type_t token_type, parse_keyword_t token_keyword)
{
switch (token_type)
{
case parse_token_type_string:
// 'end' is special
switch (token_keyword)
{
case parse_keyword_end:
case parse_keyword_else:
// End this job list
return 0;
default:
// Normal string
return 1;
}
case parse_token_type_pipe:
case parse_token_type_redirection:
case parse_token_type_background:
return 1;
case parse_token_type_end:
// Empty line
return 2;
case parse_token_type_terminate:
// no more commands, just transition to empty
return 0;
break;
default:
return NO_PRODUCTION;
}
}

View file

@ -10,6 +10,67 @@
/* Terrifying template black magic. */ /* Terrifying template black magic. */
/*
- Get info for symbol
- Resolve production from info
- Get productions for children
- Get symbols for productions
Production may be:
1. Single value
2. Sequence of values (possibly empty)
3. Options of Single / Sequence
Info to specify:
1. Number of different productions
2. Resolver function
3. Symbols for associated productions
Choice: should info be a class or a data?
data:
struct Symbol_t
{
enum parse_token_type_t token_type;
int (*resolver)(parse_token_type_t tok, parse_keyword_t key); //may be trivial
production productions[5];
}
struct Production_t
{
enum parse_token_type_t symbols[5];
}
*/
namespace parse_productions
{
#define MAX_PRODUCTIONS 5
#define MAX_SYMBOLS_PER_PRODUCTION 5
struct Production_t
{
enum parse_token_type_t symbols[MAX_SYMBOLS_PER_PRODUCTION];
};
struct Symbol_t
{
enum parse_token_type_t token_type;
int (*resolver)(parse_token_type_t tok, parse_keyword_t key);
Production_t productions[MAX_PRODUCTIONS];
};
}
namespace parse_symbols namespace parse_symbols
{ {

View file

@ -1,4 +1,4 @@
#include "parse_tree_construction.h" #include "parse_productions.h"
#include "tokenizer.h" #include "tokenizer.h"
#include <vector> #include <vector>

View file

@ -3,8 +3,8 @@
Programmatic representation of fish code. Programmatic representation of fish code.
*/ */
#ifndef FISH_PARSE_TREE_H #ifndef FISH_PARSE_PRODUCTIONS_H
#define FISH_PARSE_TREE_H #define FISH_PARSE_PRODUCTIONS_H
#include <wchar.h> #include <wchar.h>