Skip to content

Commit

Permalink
Merge pull request #18 from daxida/bugfixing
Browse files Browse the repository at this point in the history
Fixing spacing, writejoin and casing in C templates
  • Loading branch information
ellnix authored Mar 19, 2024
2 parents d249361 + 8a42475 commit e04cfd4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
12 changes: 3 additions & 9 deletions config/stub_templates/c/main.c.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
{% if debug_mode %}
---- 🇲 AIN
{% endif -%}
{% if debug_mode -%}
---- 🇸 TATEMENT
{% endif -%}

{%- for line in statement %}
{% for line in statement %}
// {{ line }}
{% endfor %}
{%- endfor %}

int main() {
{%- for line in code_lines %}
{{ line }}
Expand Down
1 change: 1 addition & 0 deletions config/stub_templates/c/stub_config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "c"
variable_format = "snake_case"
source_file_ext = "c"
allow_uppercase_vars = false
# TODO
keywords = [
"for"
Expand Down
19 changes: 13 additions & 6 deletions config/stub_templates/c/write_join.c.jinja
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{#
This only deals with WriteJoin with literals at the moment.
#}

{%- if debug_mode -%}
---- 🇼 RITE_JOIN
{% endif -%}

puts "
{%- set_global joined_terms = [] -%}
{%- for term in terms -%}
{%- if term.term_type=="Variable" -%}
{{- '#{' }}{{ term.name }}{{ '}' -}}
{%- if term.term_type == "Variable"%}
{%- set ref = "TODO" -%}
{%- else -%}
{{- term.name -}}
{%- set ref = term.name -%}
{%- endif -%}
{% if loop.last == false %} {% endif %}
{%- endfor -%}"
{%- set_global joined_terms = joined_terms | concat(with=ref) -%}
{%- endfor -%}
{%- set fmt_joined_terms = joined_terms | join(sep=" ") -%}

printf("{{ fmt_joined_terms }}");
4 changes: 2 additions & 2 deletions config/stub_templates/rust/write.rs.jinja
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if debug_mode -%}
{%- if debug_mode -%}
---- 🇼 RITE
{%- endif -%}
{% endif -%}

{%- for line in output_comments %}
// {{ line }}
Expand Down
52 changes: 34 additions & 18 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ check-not-matching:
editor := "code"

launch-rb:
cargo run --quiet -- generate-stub "ruby" > tmp.rb
{{editor}} tmp.rb
cargo run --quiet -- generate-stub "ruby" > tmp.rb
cargo run --quiet -- show
ls *.rb | entr -p cargo run --quiet -- run --command "ruby tmp.rb"

launch-new-rb:
{{editor}} tmp.rb
cargo run --quiet -- next
cargo run --quiet -- generate-stub "ruby" > tmp.rb
{{editor}} tmp.rb
cargo run --quiet -- show
ls *.rb | entr -p cargo run --quiet -- run --command "ruby tmp.rb"

Expand All @@ -81,6 +81,20 @@ launch-c:
ls *.c | entr -p cargo run --quiet -- run \
--build-command "gcc -o tmp tmp.c" --command "./tmp"

launch-new-c:
{{editor}} tmp.c
cargo run --quiet -- next
cargo run --quiet -- generate-stub "c" > tmp.c
cargo run --quiet -- show
ls *.c | entr -p cargo run --quiet -- run \
--build-command "gcc -o tmp tmp.c" --command "./tmp"

launch-c-debug:
{{editor}} tmp.c
cargo run --quiet -- show
ls *.c | entr -p cargo run --quiet -- run \
--build-command "gcc -o tmp tmp.c" --command "./tmp" --ignore-failures

# Requires Cargo.toml to look be like this:
# [package]
# name = "clash"
Expand All @@ -95,27 +109,29 @@ launch-rs:
{{editor}} tmp.rs
cargo run --quiet -- show
ls *.rs | entr -p cargo run --quiet -- run \
--command "cargo run --bin tmp"
--build-command "cargo build --bin tmp" --command "./target/debug/tmp"

launch-rs-debug:
{{editor}} tmp.rs
cargo run --quiet -- show
ls *.rs | entr -p sh -c 'export RUST_BACKTRACE=1; cargo run --quiet -- run --ignore-failures --command "cargo run --bin tmp"'
ls *.rs | entr -p sh -c 'export RUST_BACKTRACE=1; cargo run --quiet -- run \
--build-command "cargo build --bin tmp" --command "./target/debug/tmp"'

# Test against CG STUB puzzle
# [[bin]]
# name = "templates"
# path = "tmp_templates.rs"
launch-templates:
cargo run fetch 759481e6afefea199836a6cb76e15b21d673d
cargo run next 759481e6afefea199836a6cb76e15b21d673d
cargo run --quiet -- run \
--ignore-failures --testcases 3,5,7 \
--build-command "cargo build --bin templates" --command "./target/debug/templates"

run:
cargo run -- run --command "ruby tmp.rb"

# Test the stub generator with a random clash in ruby
test-stub-rb:
cargo run -- next
cargo run -- generate-stub "ruby"

# Test the stub generator with a random clash in rust
test-stub-rs:
cargo run -- next
cargo run -- generate-stub "rust"

# Test the stub generator with a random clash in C
test-stub-c:
cargo run -- next
cargo run -- generate-stub "c"
# Test the stub generator with a random clash in LANG
test-stub LANG:
cargo run next
cargo run generate-stub {{LANG}}
6 changes: 1 addition & 5 deletions src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ Live long
and prosper
and a line with spaces both sides
write care, here spaces everywhere
and some more
write something something join(a, b)
write something join(a, b) something
write join(a, "b", aBc)
Expand Down Expand Up @@ -143,8 +140,6 @@ gets.split.each_slice(3) do |x, y, z|
x = x.to_i
y = y.to_i
end
puts "care, here spaces everywhere"
puts "and some more"
puts "#{a} #{b}"
puts "#{a} #{b}"
puts "#{a} b #{a_bc}"
Expand All @@ -158,6 +153,7 @@ puts "hello #{a} planet""##;

#[test]
fn test_reference_stub_rust() {
// TODO
let lang = Language::try_from("rust").unwrap();
let received = generate(lang, REFERENCE_STUB).unwrap();
let expected = r##"[Live long , and prosper]
Expand Down

0 comments on commit e04cfd4

Please sign in to comment.