Example #1
0
func jsonObject(str, value *tomato.Automaton) *tomato.Automaton {
	q0 := tomato.NewState()
	q1 := tomato.NewState()
	q2 := tomato.NewState()
	q3 := tomato.NewState()
	q4 := tomato.NewState()
	q5 := tomato.NewState()
	q6 := tomato.NewState()
	q7 := tomato.NewState()

	q0.Add(transition.NewRune('{', q1))

	q1.Add(transition.NewEpsilon(q2))
	q1.Add(transition.NewEpsilon(q6))

	q2.Add(transition.NewAutomaton(str, []*tomato.State{q3}))

	q3.Add(transition.NewRune(':', q4))

	q4.Add(transition.NewAutomaton(value, []*tomato.State{q5}))

	q5.Add(transition.NewRune(',', q2))
	q5.Add(transition.NewEpsilon(q6))

	q6.Add(transition.NewRune('}', q7))

	return tomato.NewAutomaton(q0, []*tomato.State{q7})
}
Example #2
0
func jsonValue(number, str, array, object *tomato.Automaton) *tomato.Automaton {
	q0 := tomato.NewState()
	q1 := tomato.NewState()

	q0.Add(transition.NewAutomaton(str, []*tomato.State{q1}))
	q0.Add(transition.NewAutomaton(number, []*tomato.State{q1}))
	q0.Add(transition.NewAutomaton(object, []*tomato.State{q1}))
	q0.Add(transition.NewAutomaton(array, []*tomato.State{q1}))
	q0.Add(transition.NewString("true", q1))
	q0.Add(transition.NewString("false", q1))
	q0.Add(transition.NewString("null", q1))

	return tomato.NewAutomaton(q0, []*tomato.State{q1})
}
Example #3
0
func New(endsNbr int) (*tomato.Automaton, func(*tomato.Automaton)) {
	start := tomato.NewState()

	ends := make([]*tomato.State, endsNbr)
	for i := 0; i < endsNbr; i++ {
		ends[i] = tomato.NewState()
	}

	return tomato.NewAutomaton(start, ends), func(automaton *tomato.Automaton) {
		start.Reset()
		start.Add(transition.NewAutomaton(automaton, ends))
	}
}
Example #4
0
func jsonArray(value *tomato.Automaton) *tomato.Automaton {
	q0 := tomato.NewState()
	q1 := tomato.NewState()
	q2 := tomato.NewState()
	q3 := tomato.NewState()
	q4 := tomato.NewState()
	q5 := tomato.NewState()

	q0.Add(transition.NewRune('[', q1))

	q1.Add(transition.NewEpsilon(q2))
	q1.Add(transition.NewEpsilon(q4))

	q2.Add(transition.NewAutomaton(value, []*tomato.State{q3}))

	q3.Add(transition.NewRune(',', q2))
	q3.Add(transition.NewEpsilon(q4))

	q4.Add(transition.NewRune(']', q5))

	return tomato.NewAutomaton(q0, []*tomato.State{q5})
}