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

Simple example fails with unexpected token "<EOF>" #292

Closed
Dogacel opened this issue Feb 11, 2023 · 3 comments
Closed

Simple example fails with unexpected token "<EOF>" #292

Dogacel opened this issue Feb 11, 2023 · 3 comments

Comments

@Dogacel
Copy link

Dogacel commented Feb 11, 2023

Here is the simple example I am trying to use:

// nolint: govet, golint
package main

import (
	"github.com/alecthomas/participle/v2"
	"github.com/alecthomas/participle/v2/lexer"
	"github.com/alecthomas/repr"
)

type Text struct {
	Pos lexer.Position

	First string `  @ident `
}

var (
	testParser = participle.MustBuild[Text](
		participle.Lexer(
			lexer.MustSimple(
				[]lexer.SimpleRule{
					// Letters and Digits
					{"letter", `[a-zA-Z]`},
					{"decimalDigit", `[0-9]`},

					// Identifiers
					{"ident", `letter ( letter | decimalDigit )*`},
				}),
		),
	)
)

func main() {
	proto, err := testParser.ParseString("string_test", `something`)

	if err != nil {
		panic(err)
	}

	repr.Println(proto, repr.Hide(&lexer.Position{}))
}

And it is giving me the error:

panic: string_test:1:10: unexpected token "<EOF>"

I have tried adding the token for <EOF> but couldn't manage to do it. Also I couldn't find any documentation regarding this.

I am using MacOS w/ go 1.19.3

@alecthomas
Copy link
Owner

Your lexer is not correct. Each entry is a self-contained regex pattern.

@alecthomas
Copy link
Owner

Try looking through the _examples folder.

@Dogacel
Copy link
Author

Dogacel commented Feb 12, 2023

Your lexer is not correct. Each entry is a self-contained regex pattern.

Got it, I am hoping this issue will guide other who also see the same issue.

My observation is: If lever fails to parse any rule it seems like this EOF error is thrown.

@Dogacel Dogacel closed this as completed Feb 12, 2023
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

2 participants