alecthomas / alecthomas/participle

Request for feature: partial parsing

Offen
#192 4 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Go
Sterne
3.9k
Forks
213
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Description:

A new method that starts the parser as usual, but returns:
- (State, Resumption, Error)

State is either "Incomplete" (the structure isn't fully parsed) or "Complete" (the structure is fully parsed).
Resumption is something that will allow you to resume parsing with more tokens if State == Incomplete.

If it hits EOF while in the middle of parsing a structure, it pauses, returning something to allow you to resume the parsing from where it left off with new input instead of erroring.

Usecase:

REPLs.

Something like:

```go
document := &ast{}
line := readline()
state, resumption, error := parser.ParsePartial(&document, line)

for {
if err != nil {
// input is malformed
}
if state == Complete {
// evaluate code
} else if state == Incomplete {
line = readline()
state, resumption, err = resumption.Resume(line)
}
}
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.