Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize rules in group that only differ in filters #333

Open
quasilyte opened this issue Jan 1, 2022 · 0 comments
Open

Optimize rules in group that only differ in filters #333

quasilyte opened this issue Jan 1, 2022 · 0 comments

Comments

@quasilyte
Copy link
Owner

func strconv(m dsl.Matcher) {
	m.Match(`fmt.Sprintf("%d", $x)`).Where(m["x"].Type.Is(`int`)).Suggest(`strconv.Atoi($x)`)

	m.Match(`fmt.Sprintf("%d", $x)`).
		Where(m["x"].Type.Is(`int64`)).
		Suggest(`strconv.FormatInt($x, 10)`)

	m.Match(`fmt.Sprintf("%d", $x)`).
		Where(m["x"].Type.OfKind(`int`)).
		Suggest(`strconv.FormatInt(int64($x), 10)`)

	m.Match(`fmt.Sprintf("%d", $x)`).
		Where(m["x"].Type.OfKind(`uint`)).
		Suggest(`strconv.FormatUint(uint64($x), 10)`)
}

In the example above, we have 4 rules that have identical syntax patterns.
We should be able to merge them and branch by their filter conditions.

syntax pattern 1
  -- filter 1 -- action 1
  -- filter 2 -- action 2
  -- filter 3 -- action 3
  -- filter 4 -- action 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant