Parser Stream #
Parsers read input tokens from a stream. In contrast to the Std.Stream class, the stream itself
does not change, but instead we keep track of the position inside the stream. This helps with
error reporting and and allows for backtracking.
Parser stream class
This class implements streams based on a static stream with a moving position.
- The type
Positionis used to record position data for the stream type. start (s : σ) : Positionreturns starting position for the streamsnext? (s : σ) (pos : Position) : Option (τ × Position)returns the token at positionposinstogether with the next position. It returnsnoneif the end of the stream has been reached.
Implementations should try to make the Position type as lightweight as possible. Often Position
is just a scalar type or another simple type.
This may allow for parsers to use the stream state more efficiently.
- Position : Type u
Parser stream class
This class implements streams based on a static stream with a moving position.
- The type
Positionis used to record position data for the stream type. start (s : σ) : Positionreturns starting position for the streamsnext? (s : σ) (pos : Position) : Option (τ × Position)returns the token at positionposinstogether with the next position. It returnsnoneif the end of the stream has been reached.
Implementations should try to make the
Positiontype as lightweight as possible. OftenPositionis just a scalar type or another simple type. This may allow for parsers to use the stream state more efficiently. - The type
- start : σ → Position σ
Parser stream class
This class implements streams based on a static stream with a moving position.
- The type
Positionis used to record position data for the stream type. start (s : σ) : Positionreturns starting position for the streamsnext? (s : σ) (pos : Position) : Option (τ × Position)returns the token at positionposinstogether with the next position. It returnsnoneif the end of the stream has been reached.
Implementations should try to make the
Positiontype as lightweight as possible. OftenPositionis just a scalar type or another simple type. This may allow for parsers to use the stream state more efficiently. - The type
Parser stream class
This class implements streams based on a static stream with a moving position.
- The type
Positionis used to record position data for the stream type. start (s : σ) : Positionreturns starting position for the streamsnext? (s : σ) (pos : Position) : Option (τ × Position)returns the token at positionposinstogether with the next position. It returnsnoneif the end of the stream has been reached.
Implementations should try to make the
Positiontype as lightweight as possible. OftenPositionis just a scalar type or another simple type. This may allow for parsers to use the stream state more efficiently.- The type
Instances
Equations
- instInhabitedPosition = { default := Parser.Stream.start default }
Stream segment type.
Equations
Instances For
Default wrapper to make a Parser.Stream from a plain Stream.
This wrapper uses the entire stream state as position information; this is not efficient. Always
prefer tailored Parser.Stream instances to this default.
Equations
- Parser.Stream.mkDefault σ τ = σ
Instances For
Equations
- Parser.Stream.instMkDefault σ τ = { Position := σ, start := fun (s : Parser.Stream.mkDefault σ τ) => s, next? := fun (x : Parser.Stream.mkDefault σ τ) => Std.Stream.next? }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.