Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Can't parse double slash "//" #423

Closed
aimestereo opened this issue Nov 3, 2024 · 1 comment
Closed

Can't parse double slash "//" #423

aimestereo opened this issue Nov 3, 2024 · 1 comment

Comments

@aimestereo
Copy link

aimestereo commented Nov 3, 2024

Hello, I've took simpleexpr example as my starting point and extended it to cover all my cases.

But for some reason I can't parse simple math operation: floor division: //

I've prepared a simplified example to highlight my exact case:

Demo repo: https://github.com/aimestereo/go-dsl-floor-division-issue

package main

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

type Expr struct {
    // doesn't matter if it's "/" "/" or "//"
	Op string `@(  "+" | "!" "=" | "&" "&" | "/" "/" | "/" )`
}

var (
	parser = participle.MustBuild[Expr]()
)

EBNF:

Expr = ("+" | ("!" "=") | ("&" "&") | ("/" "/") | "/") .

Diagram:
image

Tests that I'm checking:

  • + - ok
  • != - ok
  • && - ok
  • / - ok
  • // - fails
@alecthomas
Copy link
Owner

You will need to define a custom lexer, the default lexer is the Go one which treats // as comments

Repository owner locked and limited conversation to collaborators Nov 3, 2024
@alecthomas alecthomas converted this issue into discussion #424 Nov 3, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants