Skip to content

Commit

Permalink
fixing matcheroni build
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Mar 3, 2024
1 parent 07f1dcb commit 2b8ab92
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 90 deletions.
16 changes: 8 additions & 8 deletions build.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hancho
# matcheroni/build.hancho

print("Building Matcheroni with Hancho")

Expand All @@ -10,10 +10,10 @@ hancho.config.set(


hancho.load("examples/c_lexer/c_lexer.hancho")
#hancho.load("examples/c_parser")
#hancho.load("examples/ini")
#hancho.load("examples/json")
#hancho.load("examples/regex")
#hancho.load("examples/toml")
#hancho.load("examples/tutorial")
#hancho.load("tests")
hancho.load("examples/c_parser/c_parser.hancho")
hancho.load("examples/ini/ini.hancho")
hancho.load("examples/json/json.hancho")
hancho.load("examples/regex/regex.hancho")
hancho.load("examples/toml/toml.hancho")
hancho.load("examples/tutorial/tutorial.hancho")
hancho.load("tests/tests.hancho")
21 changes: 10 additions & 11 deletions config/rules.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hancho
# matcheroni/config/rules.hancho

#-------------------------------------------------------------------------------

Expand All @@ -10,8 +10,7 @@ compile_cpp = hancho.Rule(
warnings = "-Wall -Werror -Wno-unused-variable -Wno-unused-local-typedefs -Wno-unused-but-set-variable",
includes = "-I.",
files_out = "{swap_ext(files_in, '.o')}",
# FIXME - why can't this be files_out[0]?
depfile = "{swap_ext(files_in, '.d')}",
depfile = "{swap_ext(files_out, '.d')}",
)

link_c_lib = hancho.Rule(
Expand All @@ -34,17 +33,17 @@ test_rule = hancho.Rule(

#-------------------------------------------------------------------------------

def compile_srcs(srcs):
return [compile_cpp(f) for f in hancho.flatten(srcs)]
def compile_srcs(files_in, **kwargs):
return [compile_cpp(f, **kwargs) for f in hancho.flatten(files_in)]

def c_binary(*, name, srcs, **kwargs):
return link_c_bin(compile_srcs(srcs), name, **kwargs)
def c_binary(files_in, files_out, **kwargs):
return link_c_bin(compile_srcs(files_in, **kwargs), files_out, **kwargs)

def c_library(*, name, srcs):
return link_c_lib(compile_srcs(srcs), name)
def c_library(files_in, files_out, **kwargs):
return link_c_lib(compile_srcs(files_in, **kwargs), files_out, **kwargs)

def c_test(*, name, srcs, **kwargs):
return test_rule(c_binary(name = name, srcs = srcs, **kwargs))
def c_test(files_in, files_out, **kwargs):
return test_rule(c_binary(files_in, files_out, **kwargs), **kwargs)


#-------------------------------------------------------------------------------
14 changes: 6 additions & 8 deletions examples/c_lexer/c_lexer.hancho
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#-------------------------------------------------------------------------------
# Matcheroni C lexer demo

import hancho
rules = hancho.load("config/rules.hancho")

c_lexer_lib = rules.c_library(
name = "c_lexer.a",
srcs = ["CLexer.cpp", "CToken.cpp"],
["CLexer.cpp", "CToken.cpp"],
"c_lexer.a",
)

rules.c_test(

name = "c_lexer_test",
srcs = "c_lexer_test.cpp",
"c_lexer_test.cpp",
"c_lexer_test",
deps = c_lexer_lib,
quiet = True,
)

rules.c_binary(
name = "c_lexer_benchmark",
srcs = "c_lexer_benchmark.cpp",
"c_lexer_benchmark.cpp",
"c_lexer_benchmark",
deps = c_lexer_lib,
)
19 changes: 7 additions & 12 deletions examples/c_parser/c_parser.hancho
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
#-------------------------------------------------------------------------------
# C parser example (not finished)

import hancho
rules = hancho.load("config/rules.hancho")
c_lexer = hancho.load("../c_lexer")
c_lexer = hancho.load("../c_lexer/c_lexer.hancho")

c_parser_lib = rules.c_library(
name = "c_parser.a",
srcs = [
"CContext.cpp",
"CNode.cpp",
"CScope.cpp"
]
["CContext.cpp", "CNode.cpp", "CScope.cpp"],
"c_parser.a",
)

rules.c_binary(
name = "c_parser_benchmark",
srcs = "c_parser_benchmark.cpp",
"c_parser_benchmark.cpp",
"c_parser_benchmark",
deps = [c_lexer.c_lexer_lib, c_parser_lib],
)

# Broken?
#rules.c_test(
# name = "c_parser_test",
# srcs = ["c_parser_test.cpp"],
# "c_parser_test.cpp",
# "c_parser_test",
# deps = [c_lexer.c_lexer_lib, c_parser_lib],
# quiet = True
#)
6 changes: 1 addition & 5 deletions examples/ini/ini.hancho
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#-------------------------------------------------------------------------------
# INI parser example

import hancho
rules = hancho.load("config/rules.hancho")

ini_parser_lib = rules.c_library(
name = "ini_parser.a",
srcs = "ini_parser.cpp",
)
ini_parser_lib = rules.c_library("ini_parser.cpp", "ini_parser.a")
21 changes: 10 additions & 11 deletions examples/json/json.hancho
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
#-------------------------------------------------------------------------------
# Matcheroni JSON parser example

import hancho
rules = hancho.load("config/rules.hancho")

json_parser = rules.c_library(
name = "json_parser.a",
srcs = ["json_matcher.cpp", "json_parser.cpp"]
["json_matcher.cpp", "json_parser.cpp"],
"json_parser.a",
)

rules.c_binary(
name = "json_conformance",
srcs = "json_conformance.cpp",
"json_conformance.cpp",
"json_conformance",
deps = json_parser
)

rules.c_binary(
name = "json_benchmark",
srcs = "json_benchmark.cpp",
"json_benchmark.cpp",
"json_benchmark",
deps = json_parser,
)

rules.c_binary(
name = "json_demo",
srcs = "json_demo.cpp",
"json_demo.cpp",
"json_demo",
deps = json_parser,
)

rules.c_test(
name = "json_test",
srcs = "json_test.cpp",
"json_test.cpp",
"json_test",
deps = json_parser,
quiet = True
)
File renamed without changes.
17 changes: 8 additions & 9 deletions examples/regex/regex.hancho
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#-------------------------------------------------------------------------------
# Matcheroni regex parsing example

import hancho
rules = hancho.load("config/rules.hancho")

# These are the various regex libraries that Matcheroni can be benchmarked
Expand All @@ -15,26 +14,26 @@ rules = hancho.load("config/rules.hancho")
#benchmark_defs = ${benchmark_defs} -DSRELL_NO_VMODE

regex_parser = rules.c_library(
name = "regex_parser.a",
srcs = "regex_parser.cpp",
"regex_parser.cpp",
"regex_parser.a",
)

rules.c_binary(
name = "regex_demo",
srcs = "regex_demo.cpp",
"regex_demo.cpp",
"regex_demo",
deps = regex_parser,
)

rules.c_binary(
name = "regex_benchmark",
srcs = "regex_benchmark.cpp",
"regex_benchmark.cpp",
"regex_benchmark",
deps = regex_parser,
sys_libs = "-lboost_system -lboost_regex",
)

rules.c_test(
name = "regex_test",
srcs = "regex_test.cpp",
"regex_test.cpp",
"regex_test",
deps = regex_parser,
quiet = True
)
9 changes: 4 additions & 5 deletions examples/toml/toml.hancho
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#-------------------------------------------------------------------------------
# TOML parser example

import hancho
rules = hancho.load("config/rules.hancho")

toml_lib = rules.c_library(
name = "toml_lib.a",
srcs = "toml_parser.cpp"
"toml_parser.cpp",
"toml_lib.a",
)

rules.c_test(
name = "toml_test",
srcs = "toml_test.cpp",
"toml_test.cpp",
"toml_test",
deps = toml_lib,
quiet = True
)
21 changes: 10 additions & 11 deletions examples/tutorial/tutorial.hancho
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#-------------------------------------------------------------------------------
# Tutorial examples

import hancho
rules = hancho.load("config/rules.hancho")

c_lexer = hancho.load("examples/c_lexer")
c_parser = hancho.load("examples/c_parser")
c_lexer = hancho.load("examples/c_lexer/c_lexer.hancho")
c_parser = hancho.load("examples/c_parser/c_parser.hancho")

rules.c_test(name = "json_tut0a", srcs = "json_tut0a.cpp", quiet = True)
rules.c_test(name = "json_tut1a", srcs = "json_tut1a.cpp", quiet = True)
rules.c_test(name = "json_tut1b", srcs = "json_tut1b.cpp", quiet = True)
rules.c_test(name = "json_tut1c", srcs = "json_tut1c.cpp", quiet = True)
rules.c_test(name = "json_tut2a", srcs = "json_tut2a.cpp", quiet = True)
rules.c_test(name = "json_tut2b", srcs = "json_tut2b.cpp", quiet = True)
rules.c_test("json_tut0a.cpp", "json_tut0a", quiet = True)
rules.c_test("json_tut1a.cpp", "json_tut1a", quiet = True)
rules.c_test("json_tut1b.cpp", "json_tut1b", quiet = True)
rules.c_test("json_tut1c.cpp", "json_tut1c", quiet = True)
rules.c_test("json_tut2a.cpp", "json_tut2a", quiet = True)
rules.c_test("json_tut2b.cpp", "json_tut2b", quiet = True)

rules.c_binary(
name = "tiny_c_parser",
srcs = "tiny_c_parser.cpp",
"tiny_c_parser.cpp",
"tiny_c_parser",
deps = [c_lexer.c_lexer_lib, c_parser.c_parser_lib],
)
3 changes: 2 additions & 1 deletion tests/matcheroni_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ void test_charset() {
//------------------------------------------------------------------------------

int main(int argc, char** argv) {
printf("matcheroni_test begin\n");
test_span();
test_atom();
test_notatom();
Expand All @@ -990,7 +991,7 @@ int main(int argc, char** argv) {
test_charset();

if (fail_count) printf("Failed %d tests!\n", fail_count);

printf("matcheroni_test end\n");
return fail_count ? -1 : 0;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/parseroni_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ void test_pathological() {
//------------------------------------------------------------------------------

int main(int argc, char** argv) {
//printf("parseroni_test begin\n");
printf("parseroni_test begin\n");
test_basic();
test_rewind();
test_begin_end();
test_pathological();
//printf("parseroni_test done\n");
printf("parseroni_test done\n");
return 0;
}

Expand Down
13 changes: 6 additions & 7 deletions tests/tests.hancho
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#-------------------------------------------------------------------------------
# Tests

import hancho
rules = hancho.load("config/rules.hancho")

#build obj/matcheroni/Matcheroni.hpp.iwyu : iwyu matcheroni/Matcheroni.hpp
#build obj/matcheroni/Parseroni.hpp.iwyu : iwyu matcheroni/Parseroni.hpp
#build obj/matcheroni/Utilities.hpp.iwyu : iwyu matcheroni/Utilities.hpp

rules.c_test(
name = "matcheroni_test",
srcs = "matcheroni_test.cpp",
quiet = True
"matcheroni_test.cpp",
"matcheroni_test",
quiet = True,
)

rules.c_test(
name = "parseroni_test",
srcs = "parseroni_test.cpp",
quiet = True
"parseroni_test.cpp",
"parseroni_test",
quiet = True,
)

0 comments on commit 2b8ab92

Please sign in to comment.