Lines Matching full:stream
114 The error handling routines make use of the builtin ``Stream.Failure``
115 and ``Stream.Error``s. ``Stream.Failure`` is raised when the parser is
117 ``Stream.Error`` is raised when the first token matches, but the rest do
167 1) It shows how we use the ``Stream.Error`` exception. When called, this
174 the ``??`` does not match, then ``Stream.Error "parse error"`` will be
195 | [< 'Token.Ident id; stream >] ->
197 | [< e=parse_expr; stream >] ->
201 end stream
214 parse_ident id stream
230 | [< >] -> raise (Stream.Error "unknown token when expecting an expression.")
284 Operator precedence parsing considers this as a stream of primary
299 | [< lhs=parse_primary; stream >] -> parse_bin_rhs 0 lhs stream
311 example, if the current pair stream is [+, x] and
320 and parse_bin_rhs expr_prec lhs stream =
321 match Stream.peek stream with
332 -1, this check implicitly knows that the pair-stream ends when the token
333 stream runs out of binary operators. If this check succeeds, we know
340 Stream.junk stream;
344 match Stream.peek stream with
379 parse_bin_rhs expr_prec lhs stream
398 match Stream.peek stream with
403 then parse_bin_rhs (token_prec + 1) rhs stream
410 parse_bin_rhs expr_prec lhs stream
431 parser at an arbitrary token stream and build an expression from it,
463 raise (Stream.Error "expected function name in prototype")
511 let rec main_loop stream =
512 match Stream.peek stream with
517 Stream.junk stream;
518 main_loop stream
524 ignore(Parser.parse_definition stream);
527 ignore(Parser.parse_extern stream);
531 ignore(Parser.parse_toplevel stream);
533 with Stream.Error s ->
535 Stream.junk stream;
539 main_loop stream
630 | [< ' (' ' | '\n' | '\r' | '\t'); stream >] -> lex stream
633 | [< ' ('A' .. 'Z' | 'a' .. 'z' as c); stream >] ->
636 lex_ident buffer stream
639 | [< ' ('0' .. '9' as c); stream >] ->
642 lex_number buffer stream
645 | [< ' ('#'); stream >] ->
646 lex_comment stream
649 | [< 'c; stream >] ->
650 [< 'Token.Kwd c; lex stream >]
652 (* end of stream. *)
656 | [< ' ('0' .. '9' | '.' as c); stream >] ->
658 lex_number buffer stream
659 | [< stream=lex >] ->
660 [< 'Token.Number (float_of_string (Buffer.contents buffer)); stream >]
663 | [< ' ('A' .. 'Z' | 'a' .. 'z' | '0' .. '9' as c); stream >] ->
665 lex_ident buffer stream
666 | [< stream=lex >] ->
668 | "def" -> [< 'Token.Def; stream >]
669 | "extern" -> [< 'Token.Extern; stream >]
670 | id -> [< 'Token.Ident id; stream >]
673 | [< ' ('\n'); stream=lex >] -> stream
734 | [< 'Token.Ident id; stream >] ->
736 | [< e=parse_expr; stream >] ->
740 end stream
753 parse_ident id stream
755 | [< >] -> raise (Stream.Error "unknown token when expecting an expression.")
759 and parse_bin_rhs expr_prec lhs stream =
760 match Stream.peek stream with
769 Stream.junk stream;
772 let rhs = parse_primary stream in
776 match Stream.peek stream with
782 then parse_bin_rhs (token_prec + 1) rhs stream
789 parse_bin_rhs expr_prec lhs stream
796 | [< lhs=parse_primary; stream >] -> parse_bin_rhs 0 lhs stream
815 raise (Stream.Error "expected function name in prototype")
840 stream =
841 match Stream.peek stream with
846 Stream.junk stream;
847 main_loop stream
853 ignore(Parser.parse_definition stream);
856 ignore(Parser.parse_extern stream);
860 ignore(Parser.parse_toplevel stream);
862 with Stream.Error s ->
864 Stream.junk stream;
868 main_loop stream
887 let stream = Lexer.lex (Stream.of_channel stdin) in
890 Toplevel.main_loop stream;