Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Apr 21, 2024
1 parent 3fcaea1 commit c72cae8
Show file tree
Hide file tree
Showing 11 changed files with 4,126 additions and 4,125 deletions.
13 changes: 6 additions & 7 deletions build.hancho
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# matcheroni/build.hancho

print("Building Matcheroni with Hancho")

hancho.build_tag = "debug"

c_lexer = hancho.load("examples/c_lexer/c_lexer.hancho")
c_parser = hancho.load("examples/c_parser/c_parser.hancho",
c_lexer_lib = c_lexer.c_lexer_lib)
hancho.rules = hancho.load("config/rules.hancho")
hancho.c_lexer = hancho.load("examples/c_lexer/c_lexer.hancho")
hancho.c_parser = hancho.load("examples/c_parser/c_parser.hancho")

hancho.rules.c_library("examples/ini/ini_parser.cpp", "examples/ini/ini_parser.a")

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("tests/tests.hancho")
hancho.load("examples/tutorial/tutorial.hancho", c_lexer_lib=c_lexer.c_lexer_lib, c_parser_lib = c_parser.c_parser_lib)
hancho.load("examples/tutorial/tutorial.hancho")
32 changes: 24 additions & 8 deletions config/rules.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,32 @@ run_c_test = hancho.command(

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

def compile_srcs(source_files, **kwargs):
return [compile_cpp(f, **kwargs) for f in hancho.flatten(source_files)]
def compile_srcs(config, source_files):
objs = []
for file in hancho.flatten(source_files):
if isinstance(file, hancho.Task):
objs.append(file)
else:
objs.append(compile_cpp.task(config, source_files = file))
return objs

def c_binary(source_files, build_files, **kwargs):
return link_c_bin(compile_srcs(source_files, **kwargs), build_files, **kwargs)
def c_binary(config):
source_files = config.pop("source_files")
build_files = config.pop("build_files")
objs = compile_srcs(config, source_files)
return link_c_bin.task(config, source_files = objs, build_files = build_files)

def c_library(source_files, build_files, **kwargs):
return link_c_lib(compile_srcs(source_files, **kwargs), build_files, **kwargs)
def c_library(config):
source_files = config.pop("source_files")
build_files = config.pop("build_files")
objs = compile_srcs(config, source_files)
return link_c_lib.task(config, source_files = objs, build_files = build_files)

def c_test(source_files, build_files, **kwargs):
return run_c_test(c_binary(source_files, build_files, **kwargs), **kwargs)
def c_test(config):
return run_c_test.task(config, source_files = c_binary(config))

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

hancho.c_binary = hancho.callback(c_binary)
hancho.c_library = hancho.callback(c_library)
hancho.c_test = hancho.callback(c_test)
8,122 changes: 4,061 additions & 4,061 deletions data/input-text.txt

Large diffs are not rendered by default.

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

rules = hancho.load("{repo_path}/config/rules.hancho")

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

rules.c_test(
hancho.rules.c_test(
"c_lexer_test.cpp",
"c_lexer_test",
libs = c_lexer_lib,
quiet = True,
)

rules.c_binary(
hancho.rules.c_binary(
"c_lexer_benchmark.cpp",
"c_lexer_benchmark",
libs = c_lexer_lib,
)

hancho.lib = c_lexer_lib
12 changes: 5 additions & 7 deletions examples/c_parser/c_parser.hancho
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#-------------------------------------------------------------------------------
# C parser example (not finished)

import sys

rules = hancho.load("{repo_path}/config/rules.hancho")

c_parser_lib = rules.c_library(
c_parser_lib = hancho.rules.c_library(
source_files = ["CContext.cpp", "CNode.cpp", "CScope.cpp"],
build_files = "c_parser.a",
)

rules.c_binary(
hancho.rules.c_binary(
"c_parser_benchmark.cpp",
"c_parser_benchmark",
libs = [hancho.c_lexer_lib, c_parser_lib],
libs = [hancho.c_lexer.lib, c_parser_lib],
)

# Broken?
Expand All @@ -23,3 +19,5 @@ rules.c_binary(
# libs = [c_lexer.c_lexer_lib, c_parser_lib],
# quiet = True
#)

hancho.lib = c_parser_lib
6 changes: 0 additions & 6 deletions examples/ini/ini.hancho

This file was deleted.

14 changes: 7 additions & 7 deletions examples/json/json.hancho
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#-------------------------------------------------------------------------------
# Matcheroni JSON parser example

rules = hancho.load("{repo_path}/config/rules.hancho")

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

rules.c_binary(
hancho.rules.c_binary(
"json_conformance.cpp",
"json_conformance",
libs = json_parser
)

rules.c_binary(
hancho.rules.c_binary(
"json_benchmark.cpp",
"json_benchmark",
libs = json_parser,
)

rules.c_binary(
hancho.rules.c_binary(
"json_demo.cpp",
"json_demo",
libs = json_parser,
)

rules.c_test(
hancho.rules.c_test(
"json_test.cpp",
"json_test",
libs = json_parser,
quiet = True
)

hancho.lib = json_parser
12 changes: 6 additions & 6 deletions examples/regex/regex.hancho
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#-------------------------------------------------------------------------------
# Matcheroni regex parsing example

rules = hancho.load("{repo_path}/config/rules.hancho")

# These are the various regex libraries that Matcheroni can be benchmarked
# against. CTRE and SRELL require that you copy their header into matcheroni/.

Expand All @@ -13,27 +11,29 @@ rules = hancho.load("{repo_path}/config/rules.hancho")
#benchmark_defs = ${benchmark_defs} -DSRELL_NO_NAMEDCAPTURE
#benchmark_defs = ${benchmark_defs} -DSRELL_NO_VMODE

regex_parser = rules.c_library(
regex_parser = hancho.rules.c_library(
"regex_parser.cpp",
"regex_parser.a",
)

rules.c_binary(
hancho.rules.c_binary(
"regex_demo.cpp",
"regex_demo",
libs = regex_parser,
)

rules.c_binary(
hancho.rules.c_binary(
"regex_benchmark.cpp",
"regex_benchmark",
libs = regex_parser,
sys_libs = "-lboost_system -lboost_regex",
)

rules.c_test(
hancho.rules.c_test(
"regex_test.cpp",
"regex_test",
libs = regex_parser,
quiet = True
)

hancho.lib = regex_parser
6 changes: 2 additions & 4 deletions examples/toml/toml.hancho
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#-------------------------------------------------------------------------------
# TOML parser example

rules = hancho.load("{repo_path}/config/rules.hancho")

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

rules.c_test(
hancho.rules.c_test(
"toml_test.cpp",
"toml_test",
libs = toml_lib,
Expand Down
18 changes: 8 additions & 10 deletions examples/tutorial/tutorial.hancho
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#-------------------------------------------------------------------------------
# Tutorial examples

rules = hancho.load("{repo_path}/config/rules.hancho")
hancho.rules.c_test("json_tut0a.cpp", "json_tut0a", command_path="{repo_path}", quiet = True)
hancho.rules.c_test("json_tut1a.cpp", "json_tut1a", command_path="{repo_path}", quiet = True)
hancho.rules.c_test("json_tut1b.cpp", "json_tut1b", command_path="{repo_path}", quiet = True)
hancho.rules.c_test("json_tut1c.cpp", "json_tut1c", command_path="{repo_path}", quiet = True)
hancho.rules.c_test("json_tut2a.cpp", "json_tut2a", command_path="{repo_path}", quiet = True)
hancho.rules.c_test("json_tut2b.cpp", "json_tut2b", command_path="{repo_path}", quiet = True)

rules.c_test("json_tut0a.cpp", "json_tut0a", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut1a.cpp", "json_tut1a", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut1b.cpp", "json_tut1b", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut1c.cpp", "json_tut1c", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut2a.cpp", "json_tut2a", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut2b.cpp", "json_tut2b", command_path="{repo_path}", quiet = True)

rules.c_binary(
hancho.rules.c_binary(
"tiny_c_parser.cpp",
"tiny_c_parser",
libs = [hancho.c_lexer_lib, hancho.c_parser_lib],
libs = [hancho.c_lexer.lib, hancho.c_parser.lib],
)
6 changes: 2 additions & 4 deletions tests/tests.hancho
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#-------------------------------------------------------------------------------
# Tests

rules = hancho.load("{repo_path}/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(
hancho.rules.c_test(
"matcheroni_test.cpp",
"matcheroni_test",
quiet = True,
)

rules.c_test(
hancho.rules.c_test(
"parseroni_test.cpp",
"parseroni_test",
quiet = True,
Expand Down

0 comments on commit c72cae8

Please sign in to comment.