<commit_before>package main

import (
	"flag"
	"fmt"
	"io/ioutil"
)

type RuneIter struct {
	runes []rune
	cur   int
	size  int
}

type IterError struct {
	error string
}

func (e *IterError) Error() string {
	return fmt.Sprintf("%s\n", e.error)
}

func NewRuneIter(s string) RuneIter {
	runes := make([]rune, 0)
	for _,r := range s {
		runes = append(runes, r)
	}
	return RuneIter{runes, 0, len(runes)}
}

func (r *RuneIter) Peek() (rune, error) {
	if r.cur + 1 > r.size {
		return 'a', &IterError{"No more elements"}
	}
	return r.runes[r.cur + 1], nil
}

func (r *RuneIter) Next() (rune, error) {
	if r.cur + 1 > r.size {
		return 'a', &IterError{"No more elements"}
	}
	n := r.runes[r.cur]
	r.cur += 1
	return n, nil
}


var cFile = flag.String("c", "", "output file")

var cHead = `
#include <stdio.h>

int
main() {
  char array[1000];
  char *ptr = array;

`

var cTail = `
  return 0;
}
`

var indent = `  `

func addIndent(indentLevel int, s string) string {
    var indented string
    for i := 0; i < indentLevel; i++ {
        indented += indent
    }
    indented += s
    return indented
}

func makeCSource(bfSource string) string {
    cSource := cHead
    indentLevel := 1

	rIter := NewRuneIter(bfSource)

    for {
		rune,err := rIter.Next()
		if err != nil {
			break
		}
		var addC string
		switch rune {
		case '>':
			addC = "++ptr;\n"
		case '<':
			addC = "--ptr;\n"
		case '+':
			addC = "++*ptr;\n"
		case '-':
			addC = "--*ptr;\n"
		case '.':
			addC = "putchar(*ptr);\n"
		case ',':
			addC = "*ptr = getchar();\n"
		case '[':
			addC = "while (*ptr) {\n"
			indentLevel += 1
		case ']':
			addC = "}\n"
			indentLevel -= 1
		default:
			continue
		}

        toAdd := addIndent(indentLevel, addC)
        cSource += toAdd
    }
    cSource += cTail
    return cSource
}

func main() {<commit_msg>Condense consecutive calls into (+|-)=<commit_after>package main

import (
	"flag"
	"fmt"
	"io/ioutil"
	"strconv"
)

type RuneIter struct {
	runes []rune
	cur   int
	size  int
}

type IterError struct {
	error string
}

func (e *IterError) Error() string {
	return fmt.Sprintf("%s\n", e.error)
}

func NewRuneIter(s string) RuneIter {
	runes := make([]rune, 0)
	for _,r := range s {
		runes = append(runes, r)
	}
	return RuneIter{runes, 0, len(runes)}
}

func (r *RuneIter) Peek() (rune, error) {
	if r.cur + 1 > r.size - 1 {
		return 'a', &IterError{"No more elements"}
	}
	return r.runes[r.cur], nil
}

func (r *RuneIter) Next() (rune, error) {
	if r.cur + 1 > r.size - 1{
		return 'a', &IterError{"No more elements"}
	}
	n := r.runes[r.cur]
	r.cur += 1
	return n, nil
}


var cFile = flag.String("c", "", "output file")

var cHead = `
#include <stdio.h>

int
main() {
  char array[1000];
  char *ptr = array;

`

var cTail = `
  return 0;
}
`

var indent = `  `

func addIndent(indentLevel int, s string) string {
    var indented string
    for i := 0; i < indentLevel; i++ {
        indented += indent
    }
    indented += s
    return indented
}

func makeCSource(bfSource string) string {
    cSource := cHead
    indentLevel := 1

	rIter := NewRuneIter(bfSource)

    for {
		rune,err := rIter.Next()
		if err != nil {
			break
		}
		var addC string
		switch rune {
		case '>':
			num := 1
            for {
                peeked, err := rIter.Peek()
                if err != nil {
                    break // End of the bf.
                }
                if peeked == '>' {
                    num += 1
                } else {
                    break // No match on next character.
                }
                _, _ = rIter.Next() // This won't fail if peek was fine.
            }

            if num == 1 {
                addC = "++ptr;\n"
            } else {
                addC = "ptr += " + strconv.Itoa(num) + ";\n"
            }

		case '<':

			num := 1
            for {
                peeked, err := rIter.Peek()
                if err != nil {
                    break // End of the bf.
                }
                if peeked == '<' {
                    num += 1
                } else {
                    break // No match on next character.
                }
                _, _ = rIter.Next() // This won't fail if peek was fine.
            }

            if num == 1 {
                addC = "--ptr;\n"
            } else {
                addC = "ptr -= " + strconv.Itoa(num) + ";\n"
            }

		case '+':
			num := 1
			for {
				peeked, err := rIter.Peek()
				if err != nil {
					break // End of the bf.
				}
				if peeked == '+' {
					num += 1
				} else {
					break // No match on next character.
				}
				_, _ = rIter.Next() // This won't fail if peek was fine.
			}

			if num == 1 {
				addC = "++*ptr;\n"
			} else {
				addC = "*ptr += " + strconv.Itoa(num) + ";\n"
			}

		case '-':
			num := 1
            for {
                peeked, err := rIter.Peek()
                if err != nil {
                    break // End of the bf.
                }
                if peeked == '-' {
                    num += 1
                } else {
                    break // No match on next character.
                }
                _, _ = rIter.Next() // This won't fail if peek was fine.
            }

            if num == 1 {
                addC = "--*ptr;\n"
            } else {
                addC = "*ptr -= " + strconv.Itoa(num) + ";\n"
            }

		case '.':
			addC = "putchar(*ptr);\n"
		case ',':
			addC = "*ptr = getchar();\n"
		case '[':
			addC = "while (*ptr) {\n"
			indentLevel += 1
		case ']':
			addC = "}\n"
			indentLevel -= 1
		default:
			continue
		}

        toAdd := addIndent(indentLevel, addC)
        cSource += toAdd
    }
    cSource += cTail
    return cSource
}

func main() {
{'fraction_non_alphanumeric': 0.1533753060510668, 'fraction_numerical': 0.007520111927247289, 'mean_word_length': 1.5680287382128424, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1622353', 'n_tokens_mistral': 2300, 'n_tokens_neox': 2055, 'n_words': 562}