<commit_before>package coffeephp

/* vim:list: */

import "testing"
import "coffeephp/codegen/phpcodegen"

func TestParser(t *testing.T) {
	inputs := []string{
		`pi = 3.1415926`,
		`pi = 3.1415926 + 4`,
		`pi = 4455
a = 4 * (2 + 3)
b = a`,

		// XXX: need trailing line
		`x = 3 * -2`,
		`if a > 10
    a = 10
`,
		`if a > 10
    a = 10
else
    a = 0
`,
	}
	for _, input := range inputs {
		t.Log(input)
		lexer := CoffeeLex{
			input: input,
			start: 0,
			pos:   0,
			items: make(chan *CoffeeSymType, 100),
		}
		go lexer.run()

		// dumpLexItems(lexer.items)

		parser := CoffeeParser{}
		if parser.Parse(&lexer) == 1 {
			t.Fatal("syntax error")
		}
		lexer.close()
		t.Logf("AST: %#v", parser.Val.val)
		visitor := phpcodegen.Visitor{}
		t.Log(visitor.Visit(parser.Val.val))
	}
}<commit_msg>block testing<commit_after>package coffeephp

/* vim:list: */

import "testing"
import "coffeephp/codegen/phpcodegen"

func TestParser(t *testing.T) {
	inputs := []string{
		`pi = 3.1415926`,
		`pi = 3.1415926 + 4`,
		`pi = 4455
a = 4 * (2 + 3)
b = a`,

		// XXX: need trailing line
		`x = 3 * -2`,
		`if a > 10
    a = 10
`,
		`if a > 10
    a = 10
else
    a = 0
`,
		`if a > 10
    a = 10
    b = 20
else
    a = 0
    b = 0
`,
	}
	for _, input := range inputs {
		t.Log(input)
		lexer := CoffeeLex{
			input: input,
			start: 0,
			pos:   0,
			items: make(chan *CoffeeSymType, 100),
		}
		go lexer.run()

		// dumpLexItems(lexer.items)

		parser := CoffeeParser{}
		if parser.Parse(&lexer) == 1 {
			t.Fatal("syntax error")
		}
		lexer.close()
		t.Logf("AST: %#v", parser.Val.val)
		visitor := phpcodegen.Visitor{}
		t.Log(visitor.Visit(parser.Val.val))
	}
}
{'fraction_non_alphanumeric': 0.17799158147925437, 'fraction_numerical': 0.054119061936259774, 'mean_word_length': 2.5254237288135593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '7561646', 'n_tokens_mistral': 856, 'n_tokens_neox': 701, 'n_words': 171}