Skip to content

Commit dd5726a

Browse files
authored
wdte: funcmod functions (#204)
* res/grammar: Change funcmods. * scanner: Remove funcmod keywords. * wdte: Implenent new funcmod system. * std: Reimplement `memo` and `rev` as funcmod functions. * std: Attempt to reimplement method. * scanner: Fix FuncMods test. * multiple: Fix a bunch of linter warnings. * multiple: Remove the `nolint`s.
1 parent 1d75089 commit dd5726a

File tree

23 files changed

+449
-399
lines changed

23 files changed

+449
-399
lines changed

ast/internal/pgen/table.go

Lines changed: 135 additions & 142 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ast/node.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Term struct {
2323
p Node
2424
}
2525

26-
func (t Term) Parent() Node { // nolint
26+
func (t Term) Parent() Node {
2727
return t.p
2828
}
2929

@@ -32,7 +32,7 @@ func (t Term) Tok() scanner.Token {
3232
return t.tok
3333
}
3434

35-
func (t Term) Children() []Node { // nolint
35+
func (t Term) Children() []Node {
3636
return nil
3737
}
3838

@@ -49,7 +49,7 @@ func (nt NTerm) Name() string {
4949
return string(nt.nt)
5050
}
5151

52-
func (nt NTerm) Parent() Node { // nolint
52+
func (nt NTerm) Parent() Node {
5353
return nt.p
5454
}
5555

@@ -63,7 +63,7 @@ func (nt *NTerm) AddChild(n Node) {
6363
nt.c = append(nt.c, n)
6464
}
6565

66-
func (nt NTerm) Children() []Node { // nolint
66+
func (nt NTerm) Children() []Node {
6767
return nt.c
6868
}
6969

@@ -72,10 +72,10 @@ type Epsilon struct {
7272
p Node
7373
}
7474

75-
func (e Epsilon) Parent() Node { // nolint
75+
func (e Epsilon) Parent() Node {
7676
return e.p
7777
}
7878

79-
func (e Epsilon) Children() []Node { // nolint
79+
func (e Epsilon) Children() []Node {
8080
return nil
8181
}

cmd/pgen/grammar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (g Grammar) followWithout(nt NTerm, ignore []NTerm) TokenSet {
175175
continue
176176
}
177177

178-
for i := i + 1; i < len(rule); i++ { // nolint
178+
for i := i + 1; i < len(rule); i++ {
179179
ts.AddAll(g.First(rule[i]), rule)
180180
if !g.Nullable(rule[i]) {
181181
break

cmd/pgen/pgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func main() {
3737

3838
out := &formatter{w: os.Stdout}
3939
if *output != "" {
40-
file, err := os.Create(*output) // nolint
40+
file, err := os.Create(*output)
4141
if err != nil {
4242
fmt.Fprintf(os.Stderr, "Error creating %q: %v", *output, err)
4343
os.Exit(1)

cmd/wdte/stdin.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ func printRet(ret wdte.Func) {
1818
case error, fmt.Stringer:
1919
fmt.Printf(": %v\n", ret)
2020
return
21-
22-
case wdte.GoFunc:
23-
fmt.Println(": complex value (GoFunc)")
24-
return
2521
}
2622

2723
switch k := reflect.Indirect(reflect.ValueOf(ret)).Kind(); k {

readme_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func Sum(frame wdte.Frame, args ...wdte.Func) wdte.Func {
4040
return sum
4141
}
4242

43-
func ExampleREADME() {
43+
func Example() {
4444
m, err := wdte.Parse(strings.NewReader(src), wdte.ImportFunc(im), nil)
4545
if err != nil {
4646
fmt.Fprintf(os.Stderr, "Error parsing script: %v\n", err)

repl/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func ExamplePartial() {
1414
stack, partial = repl.Partial(strings.NewReader("import 'io'"), stack, nil)
1515
fmt.Println(partial)
1616

17-
stack, partial = repl.Partial(strings.NewReader(";"), stack, nil)
17+
_, partial = repl.Partial(strings.NewReader(";"), stack, nil)
1818
fmt.Println(partial)
1919
// Output: true
2020
// true

res/grammar.ebnf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<script> -> <cexprs> Ω
2-
<funcmods> -> <funcmod> <funcmods>
2+
<funcmods> -> ( <expr> ; ) <funcmods>
33
| ε
4-
<funcmod> -> memo
5-
| rev
6-
| method
74
<argdecls> -> <argdecl> <argdecls>
85
| ε
96
<argdecl> -> id

scanner/scanner_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ o => print "double\n" 'single\\';`,
104104
},
105105
{
106106
name: "FuncMods",
107-
in: `memo test => ();`,
107+
in: `let (memo) test => ();`,
108108
out: []scanner.Token{
109-
{Type: scanner.Keyword, Val: "memo"},
109+
{Type: scanner.Keyword, Val: "let"},
110+
{Type: scanner.Keyword, Val: "("},
111+
{Type: scanner.ID, Val: "memo"},
112+
{Type: scanner.Keyword, Val: ";"},
113+
{Type: scanner.Keyword, Val: ")"},
110114
{Type: scanner.ID, Val: "test"},
111115
{Type: scanner.Keyword, Val: "=>"},
112116
{Type: scanner.Keyword, Val: "("},

scanner/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Token struct {
1515
type TokenType uint
1616

1717
const (
18-
Invalid TokenType = iota // nolint
18+
Invalid TokenType = iota
1919
Number
2020
String
2121
ID

0 commit comments

Comments
 (0)