File: examples_test.go

package info (click to toggle)
golang-github-ganigeorgiev-fexpr 0.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 104 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 541 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package fexpr_test

import (
	"fmt"

	"github.com/ganigeorgiev/fexpr"
)

func ExampleScanner_Scan() {
	s := fexpr.NewScanner([]byte("id > 123"))

	for {
		t, err := s.Scan()
		if t.Type == fexpr.TokenEOF || err != nil {
			break
		}

		fmt.Println(t)
	}

	// Output:
	// {<nil> identifier id}
	// {<nil> whitespace  }
	// {<nil> sign >}
	// {<nil> whitespace  }
	// {<nil> number 123}
}

func ExampleParse() {
	result, _ := fexpr.Parse("id > 123")

	fmt.Println(result)

	// Output:
	// [{{{<nil> identifier id} > {<nil> number 123}} &&}]
}