Get makefile working
This commit is contained in:
parent
fd757c20d0
commit
2c56612650
32 changed files with 87 additions and 97 deletions
49
Makefile
49
Makefile
|
|
@ -1,48 +1,40 @@
|
|||
.PHONY: all clean install install-dev test test-c test-scm valgrind
|
||||
.PHONY: all clean test debug valgrind
|
||||
|
||||
### install configuration ###
|
||||
CPP = c++
|
||||
CC = cc
|
||||
RM ?= rm -f
|
||||
INSTALL ?= install
|
||||
MKDIR ?= $(INSTALL) -d
|
||||
SYMLINK ?= ln -s
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
SOLIBDIR ?= $(PREFIX)/lib
|
||||
INCDIR ?= $(PREFIX)/include
|
||||
MODDIR ?= $(PREFIX)/share
|
||||
BINMODDIR ?= $(PREFIX)/lib
|
||||
MANDIR ?= $(PREFIX)/share/man/man1
|
||||
|
||||
### library configuration ###
|
||||
LIB_NAME = tree_sitter
|
||||
DIR = $(shell pwd)
|
||||
HEADERS = $(wildcard include/*.h)
|
||||
SOURCES = $(wildcard src/*.cpp)
|
||||
TESTS = $(wildcard spec/*.cpp)
|
||||
OBJECTS = $(foreach file, $(C_SOURCES), $(basename $(file)).o)
|
||||
LIB_FILE = lib$(LIB_NAME)$(SO)
|
||||
TEST_BIN = spec/run.out
|
||||
LIB_NAME = tree_sitter
|
||||
DIR = $(shell pwd)
|
||||
SOURCES = $(shell find src -name '*.cpp' -or -name '*.c')
|
||||
TESTS = $(shell find spec -name '*.cpp') $(shell find examples -name '*.c')
|
||||
SRC_OBJECTS = $(foreach file, $(SOURCES), $(basename $(file)).o)
|
||||
TEST_OBJECTS = $(foreach file, $(TESTS), $(basename $(file)).o)
|
||||
LIB_FILE = lib$(LIB_NAME)$(SO)
|
||||
TEST_BIN = spec/run.out
|
||||
|
||||
### build configuration ###
|
||||
CFLAGS ?= -Wall -std=c++11 -stdlib=libc++ -g -m64
|
||||
CFLAGS ?= -Wall -g -m64
|
||||
CPPFLAGS ?= -Wall -std=c++11 -stdlib=libc++ -g -m64
|
||||
|
||||
### targets ###
|
||||
all: $(LIB_FILE)
|
||||
|
||||
src/%.o: src/%.cpp
|
||||
$(CPP) $(CFLAGS) -c $< -o $@
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -Iinclude -Isrc/runtime -c $< -o $@
|
||||
|
||||
%.o: %.cpp
|
||||
$(CPP) $(CPPFLAGS) -Iinclude -Isrc/compiler -Isrc/runtime -Iexternals/bandit -Ispec -c $< -o $@
|
||||
|
||||
test: $(TEST_BIN)
|
||||
./$<
|
||||
|
||||
$(TEST_BIN): $(TESTS) $(SOURCES)
|
||||
$(CPP) $(CFLAGS) -Ispec/externals/igloo -Isrc -L. $^ -o $@
|
||||
|
||||
# $(TEST_BIN): $(LIB_FILE) $(C_TESTS)
|
||||
# $(CPP) $(CFLAGS) -Ispec/externals/igloo -Isrc -L. -l$(LIB_NAME) test/c/_runner.cc -o $@
|
||||
$(TEST_BIN): $(TEST_OBJECTS) $(SRC_OBJECTS)
|
||||
$(CPP) $(CPPFLAGS) $(TEST_OBJECTS) $(SRC_OBJECTS) -o $@
|
||||
|
||||
debug: $(TEST_BIN)
|
||||
gdb $<
|
||||
|
|
@ -51,5 +43,4 @@ valgrind: $(TEST_BIN)
|
|||
valgrind --track-origins=yes $(TEST_BIN)
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJECTS) $(LIB_FILE) $(TEST_BIN)
|
||||
|
||||
$(RM) $(SRC_OBJECTS) $(TEST_OBJECTS) $(LIB_FILE) $(TEST_BIN)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "spec_helper.h"
|
||||
#include "rule_can_be_blank.h"
|
||||
#include "build_tables/rule_can_be_blank.h"
|
||||
|
||||
using namespace rules;
|
||||
using build_tables::rule_can_be_blank;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "spec_helper.h"
|
||||
#include "rule_transitions.h"
|
||||
#include "build_tables/rule_transitions.h"
|
||||
|
||||
using namespace rules;
|
||||
using namespace build_tables;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "spec_helper.h"
|
||||
#include "character_set.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
using namespace rules;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "spec_helper.h"
|
||||
#include "pattern.h"
|
||||
#include "character_set.h"
|
||||
#include "rules/pattern.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
using namespace rules;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "spec_helper.h"
|
||||
#include "rule.h"
|
||||
#include "rules/rule.h"
|
||||
|
||||
using namespace rules;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime.h"
|
||||
|
||||
extern TSParseConfig ts_parse_config_arithmetic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime.h"
|
||||
|
||||
extern TSParseConfig ts_parse_config_json;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime.h"
|
||||
|
||||
START_TEST
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "spec_helper.h"
|
||||
|
||||
string src_dir() {
|
||||
return string(getenv("TREESITTER_SRC_DIR"));
|
||||
const char * dir = getenv("TREESITTER_DIR");
|
||||
if (!dir) dir = getenv("PWD");
|
||||
return dir;
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
#include "helpers/stream_methods.h"
|
||||
#include "helpers/equals_pointer.h"
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "tree_sitter/runtime.h"
|
||||
|
||||
using namespace tree_sitter;
|
||||
using namespace std;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __tree_sitter__first_set__
|
||||
#define __tree_sitter__first_set__
|
||||
|
||||
#include "symbol.h"
|
||||
#include "rules/symbol.h"
|
||||
#include <set>
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define __tree_sitter__follow_sets__
|
||||
|
||||
#include "item.h"
|
||||
#include "symbol.h"
|
||||
#include "rules/symbol.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __tree_sitter__item__
|
||||
#define __tree_sitter__item__
|
||||
|
||||
#include "symbol.h"
|
||||
#include "rules/symbol.h"
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef __tree_sitter__merge_transitions__
|
||||
#define __tree_sitter__merge_transitions__
|
||||
|
||||
#include "character_set.h"
|
||||
#include "symbol.h"
|
||||
#include "rules/character_set.h"
|
||||
#include "rules/symbol.h"
|
||||
#include <map>
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
#include "item_set_transitions.h"
|
||||
#include "tree_sitter/compiler.h"
|
||||
|
||||
#include "stream_methods.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::pair;
|
||||
using std::string;
|
||||
|
|
@ -111,21 +109,20 @@ namespace tree_sitter {
|
|||
return state_index;
|
||||
}
|
||||
|
||||
// TODO - remove
|
||||
void dump_item_sets() {
|
||||
std::vector<const ParseItemSet *> item_sets(parse_state_indices.size());
|
||||
for (auto &pair : parse_state_indices)
|
||||
item_sets[pair.second] = &pair.first;
|
||||
|
||||
for (int i = 0; i < item_sets.size(); i++) {
|
||||
std:cout << "\n\n" << i;
|
||||
for (auto &item : *item_sets[i]) {
|
||||
cout << "\n" << item.lhs;
|
||||
cout << "\n " << item.rule;
|
||||
cout << "\n " << item.lookahead_sym.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// void dump_item_sets() {
|
||||
// std::vector<const ParseItemSet *> item_sets(parse_state_indices.size());
|
||||
// for (auto &pair : parse_state_indices)
|
||||
// item_sets[pair.second] = &pair.first;
|
||||
//
|
||||
// for (int i = 0; i < item_sets.size(); i++) {
|
||||
// std:cout << "\n\n" << i;
|
||||
// for (auto &item : *item_sets[i]) {
|
||||
// cout << "\n" << item.lhs;
|
||||
// cout << "\n " << item.rule;
|
||||
// cout << "\n " << item.lookahead_sym.name;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef __tree_sitter__transitions__
|
||||
#define __tree_sitter__transitions__
|
||||
|
||||
#include "character_set.h"
|
||||
#include "symbol.h"
|
||||
#include "rules/character_set.h"
|
||||
#include "rules/symbol.h"
|
||||
#include <map>
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -74,9 +74,9 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
class CCodeGenerator {
|
||||
const string name;
|
||||
const ParseTable parse_table;
|
||||
const LexTable lex_table;
|
||||
const string name;
|
||||
public:
|
||||
CCodeGenerator(string name, const ParseTable &parse_table, const LexTable &lex_table) :
|
||||
name(name),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "tree_sitter/compiler.h"
|
||||
#include "symbol.h"
|
||||
#include "rules/symbol.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::vector;
|
||||
|
|
@ -13,15 +13,15 @@ namespace tree_sitter {
|
|||
|
||||
Grammar::Grammar(std::string start_rule_name,
|
||||
const std::map<const std::string, const rule_ptr> &rules) :
|
||||
rules(rules),
|
||||
start_rule_name(start_rule_name) {}
|
||||
start_rule_name(start_rule_name),
|
||||
rules(rules) {}
|
||||
|
||||
Grammar::Grammar(std::string start_rule_name,
|
||||
const map<const string, const rule_ptr> &rules,
|
||||
const map<const string, const rule_ptr> &aux_rules) :
|
||||
start_rule_name(start_rule_name),
|
||||
rules(rules),
|
||||
aux_rules(aux_rules),
|
||||
start_rule_name(start_rule_name) {}
|
||||
aux_rules(aux_rules) {}
|
||||
|
||||
const rule_ptr Grammar::rule(const Symbol &symbol) const {
|
||||
auto map = symbol.is_auxiliary ? aux_rules : rules;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ namespace tree_sitter {
|
|||
|
||||
LexAction::LexAction(LexActionType type, size_t state_index, Symbol symbol) :
|
||||
type(type),
|
||||
state_index(state_index),
|
||||
symbol(symbol) {}
|
||||
symbol(symbol),
|
||||
state_index(state_index) {}
|
||||
|
||||
LexAction LexAction::Error() {
|
||||
return LexAction(LexActionTypeError, -1, Symbol(""));
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include "symbol.h"
|
||||
#include "character_set.h"
|
||||
#include "rules/symbol.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
typedef enum {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ namespace tree_sitter {
|
|||
|
||||
ParseAction::ParseAction(ParseActionType type, size_t state_index, Symbol symbol, const vector<bool> &child_flags) :
|
||||
type(type),
|
||||
state_index(state_index),
|
||||
symbol(symbol),
|
||||
state_index(state_index),
|
||||
child_flags(child_flags) {};
|
||||
|
||||
ParseAction ParseAction::Error() {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include "symbol.h"
|
||||
#include "rules/symbol.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
typedef enum {
|
||||
|
|
@ -25,9 +25,9 @@ namespace tree_sitter {
|
|||
bool operator<(const ParseAction &action) const;
|
||||
|
||||
ParseActionType type;
|
||||
std::vector<bool> child_flags;
|
||||
rules::Symbol symbol;
|
||||
size_t state_index;
|
||||
std::vector<bool> child_flags;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream &stream, const ParseAction &item);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "search_for_symbols.h"
|
||||
#include "rules/visitor.h"
|
||||
#include "choice.h"
|
||||
#include "seq.h"
|
||||
#include "repeat.h"
|
||||
#include "rules/choice.h"
|
||||
#include "rules/seq.h"
|
||||
#include "rules/repeat.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using namespace rules;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __tree_sitter__search_for_symbols__
|
||||
#define __tree_sitter__search_for_symbols__
|
||||
|
||||
#include "rule.h"
|
||||
#include "tree_sitter/compiler.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace prepare_grammar {
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ namespace tree_sitter {
|
|||
public:
|
||||
PatternParser(const string &input) :
|
||||
input(input),
|
||||
position(0),
|
||||
length(input.length()) {}
|
||||
length(input.length()),
|
||||
position(0) {}
|
||||
|
||||
rule_ptr rule() {
|
||||
auto result = term();
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
#include "tree_sitter/compiler.h"
|
||||
#include "rule.h"
|
||||
#include "blank.h"
|
||||
#include "symbol.h"
|
||||
#include "choice.h"
|
||||
#include "seq.h"
|
||||
#include "string.h"
|
||||
#include "pattern.h"
|
||||
#include "character_set.h"
|
||||
#include "repeat.h"
|
||||
#include "./rule.h"
|
||||
#include "./blank.h"
|
||||
#include "./symbol.h"
|
||||
#include "./choice.h"
|
||||
#include "./seq.h"
|
||||
#include "./string.h"
|
||||
#include "./pattern.h"
|
||||
#include "./character_set.h"
|
||||
#include "./repeat.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::make_shared;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "runtime.h"
|
||||
#include "tree_sitter/runtime.h"
|
||||
|
||||
struct TSDocument {
|
||||
TSParseFn *parse_fn;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "runtime.h"
|
||||
#include "tree_sitter/runtime.h"
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "runtime.h"
|
||||
#include "tree_sitter/runtime.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@
|
|||
1236A7C318B287DC00593ABB /* character_range.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = character_range.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
1236A7C918B2A79F00593ABB /* rule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rule.h; sourceTree = "<group>"; };
|
||||
1236A7CA18B2ABB900593ABB /* equals_pointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = equals_pointer.h; sourceTree = "<group>"; };
|
||||
1236A7CC18B2B4F000593ABB /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
|
||||
1251209A1830145300C9B56A /* rule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rule.cpp; sourceTree = "<group>"; };
|
||||
125120A3183083BD00C9B56A /* arithmetic.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = arithmetic.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
12661BF318A1505A00A259FB /* character_set_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = character_set_spec.cpp; path = spec/compiler/rules/character_set_spec.cpp; sourceTree = SOURCE_ROOT; };
|
||||
|
|
@ -294,9 +295,10 @@
|
|||
12E716F9181D010E0051A649 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
12E71795181D02A80051A649 /* Products */,
|
||||
12FD40D3185FED630041A84E /* include */,
|
||||
12FD40AF185EE81D0041A84E /* examples */,
|
||||
12FD40D3185FED630041A84E /* include */,
|
||||
1236A7CC18B2B4F000593ABB /* Makefile */,
|
||||
12E71795181D02A80051A649 /* Products */,
|
||||
12E71796181D02A80051A649 /* spec */,
|
||||
12E71701181D01890051A649 /* src */,
|
||||
12D1369E18342088005F3369 /* todo.md */,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</BuildableProductRunnable>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "TREESITTER_SRC_DIR"
|
||||
key = "TREESITTER_DIR"
|
||||
value = "$(SRCROOT)"
|
||||
isEnabled = "YES">
|
||||
</EnvironmentVariable>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue