Skip to content

Commit

Permalink
Use maleeni v0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nihei9 committed Oct 27, 2021
1 parent 1dd7fef commit 1d0a67b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
5 changes: 3 additions & 2 deletions cmd/vartan/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ func runParse(cmd *cobra.Command, args []string) (retErr error) {
case tok.EOF:
msg = "<eof>"
case tok.Invalid:
msg = fmt.Sprintf("'%v' (<invalid>)", tok.Text())
msg = fmt.Sprintf("'%v' (<invalid>)", string(tok.Lexeme))
default:
msg = fmt.Sprintf("'%v' (%v)", tok.Text(), tok.KindName)
k := cgram.LexicalSpecification.Maleeni.Spec.KindNames[tok.KindID]
msg = fmt.Sprintf("'%v' (%v)", string(tok.Lexeme), k)
}

fmt.Fprintf(os.Stderr, "%v:%v: %v: %v", synErr.Row+1, synErr.Col+1, synErr.Message, msg)
Expand Down
2 changes: 1 addition & 1 deletion driver/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Parser struct {
}

func NewParser(gram *spec.CompiledGrammar, src io.Reader, opts ...ParserOption) (*Parser, error) {
lex, err := mldriver.NewLexer(gram.LexicalSpecification.Maleeni.Spec, src)
lex, err := mldriver.NewLexer(mldriver.NewLexSpec(gram.LexicalSpecification.Maleeni.Spec), src)
if err != nil {
return nil, err
}
Expand Down
24 changes: 12 additions & 12 deletions driver/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ id: "[A-Za-z_][0-9A-Za-z_]*";
nonTermNode("term",
nonTermNode("term",
nonTermNode("factor",
termNode("__3__", "("),
termNode("x_3", "("),
nonTermNode("expr",
nonTermNode("expr",
nonTermNode("term",
Expand All @@ -64,10 +64,10 @@ id: "[A-Za-z_][0-9A-Za-z_]*";
),
),
),
termNode("__1__", "+"),
termNode("x_1", "+"),
nonTermNode("term",
nonTermNode("factor",
termNode("__3__", "("),
termNode("x_3", "("),
nonTermNode("expr",
nonTermNode("expr",
nonTermNode("term",
Expand All @@ -76,27 +76,27 @@ id: "[A-Za-z_][0-9A-Za-z_]*";
),
),
),
termNode("__1__", "+"),
termNode("x_1", "+"),
nonTermNode("term",
nonTermNode("factor",
termNode("id", "c"),
),
),
),
termNode("__4__", ")"),
termNode("x_4", ")"),
),
),
),
termNode("__4__", ")"),
termNode("x_4", ")"),
),
),
termNode("__2__", "*"),
termNode("x_2", "*"),
nonTermNode("factor",
termNode("id", "d"),
),
),
),
termNode("__1__", "+"),
termNode("x_1", "+"),
nonTermNode("term",
nonTermNode("factor",
termNode("id", "e"),
Expand Down Expand Up @@ -272,19 +272,19 @@ id: "[A-Za-z]+";
`,
src: `[Byers, Frohike, Langly]`,
cst: nonTermNode("list",
termNode("__1__", "["),
termNode("x_1", "["),
nonTermNode("elems",
nonTermNode("elems",
nonTermNode("elems",
termNode("id", "Byers"),
),
termNode("__3__", ","),
termNode("x_3", ","),
termNode("id", "Frohike"),
),
termNode("__3__", ","),
termNode("x_3", ","),
termNode("id", "Langly"),
),
termNode("__2__", "]"),
termNode("x_2", "]"),
),
ast: nonTermNode("list",
termNode("id", "Byers"),
Expand Down
4 changes: 2 additions & 2 deletions driver/semantic_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ func (a *SyntaxTreeActionSet) Shift(tok *mldriver.Token, recovered bool) {
if a.makeAST {
ast = &Node{
KindName: a.gram.ParsingTable.Terminals[term],
Text: tok.Text(),
Text: string(tok.Lexeme),
Row: tok.Row,
Col: tok.Col,
}
}
if a.makeCST {
cst = &Node{
KindName: a.gram.ParsingTable.Terminals[term],
Text: tok.Text(),
Text: string(tok.Lexeme),
Row: tok.Row,
Col: tok.Col,
}
Expand Down
5 changes: 3 additions & 2 deletions driver/semantic_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ type testSemAct struct {
}

func (a *testSemAct) Shift(tok *mldriver.Token, recovered bool) {
k := a.gram.LexicalSpecification.Maleeni.Spec.KindNames[tok.KindID]
if recovered {
a.actLog = append(a.actLog, fmt.Sprintf("shift/%v/recovered", tok.KindName))
a.actLog = append(a.actLog, fmt.Sprintf("shift/%v/recovered", k))
} else {
a.actLog = append(a.actLog, fmt.Sprintf("shift/%v", tok.KindName))
a.actLog = append(a.actLog, fmt.Sprintf("shift/%v", k))
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/nihei9/vartan
go 1.16

require (
github.com/nihei9/maleeni v0.4.0
github.com/nihei9/maleeni v0.5.1
github.com/spf13/cobra v1.1.3
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nihei9/maleeni v0.4.0 h1:ca1V9U7lZuf5c01Ls4HqlYf7eyhDWdGBv+uyBkChdf0=
github.com/nihei9/maleeni v0.4.0/go.mod h1:d5x5jHHuema6IUi+aDPczMZQ4AlNokcKbEgB5T+70dI=
github.com/nihei9/maleeni v0.5.1 h1:/w5fT7rYpiOdYZ86OCf+V0FX7mNlEwOKYoDMA2igxJU=
github.com/nihei9/maleeni v0.5.1/go.mod h1:d5x5jHHuema6IUi+aDPczMZQ4AlNokcKbEgB5T+70dI=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
5 changes: 4 additions & 1 deletion grammar/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ func (b *GrammarBuilder) Build() (*Grammar, error) {
return nil, b.errs
}

// FIXME
symTabAndLexSpec.lexSpec.Name = "lex"

return &Grammar{
lexSpec: symTabAndLexSpec.lexSpec,
skipLexKinds: symTabAndLexSpec.skip,
Expand Down Expand Up @@ -336,7 +339,7 @@ func (b *GrammarBuilder) genSymbolTableAndLexSpec(root *spec.RootNode) (*symbolT
}

for i, p := range anonPats {
kind := fmt.Sprintf("__%v__", i+1)
kind := fmt.Sprintf("x_%v", i+1)

sym, err := symTab.registerTerminalSymbol(kind)
if err != nil {
Expand Down

0 comments on commit 1d0a67b

Please sign in to comment.