Skip to content

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

@aimestereo

Description

@aimestereo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions