Expression using double quotes #418
Unanswered
bravbravbrav
asked this question in
Q&A
Replies: 4 comments
-
You'll need to use: Value string `"\"" @character "\""` This limitation is, IIRC, because of how Participle uses the Go lexer internally. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Cool. I recommend documenting this behavior though. Thank you for your work :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
@alecthomas I tried to use your suggestion in my code sample, but it still results in error: Codepackage main
import (
"fmt"
"os"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
)
type Syntax struct {
Strings []*String `@@*`
}
type String struct {
Value string `"\"" @character* "\""`
}
var rules = lexer.MustSimple([]lexer.SimpleRule{
{`character`, `[^"]`},
})
var parser = participle.MustBuild[Syntax](
participle.Lexer(rules),
)
func main() {
syntax, err := parser.ParseString("code", `"a"`)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("%v\n", syntax)
} Result
|
Beta Was this translation helpful? Give feedback.
0 replies
-
That is a different issue: your lexer doesn't match |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I believe that there might be some issue related to double quotes.
Code:
Output
Expected output
Beta Was this translation helpful? Give feedback.
All reactions