1 $Id: Lexer_Ops.lhs,v 1.1 1996/01/08 20:17:58 partain Exp $
3 >module Lexer_Ops where
5 >import Lexer_Buffer(Lexer_Buffer, add, empty, flush, len, to_string)
7 > (add to add_char, empty to empty_buffer, to_string to buffer_to_string)
9 >import Lexer_Combinators(and_with, return)
12 > (Lexer_State,Lexer_Action(..),i_buffer,i_source_pos,p_buffer,p_source_pos)
14 >import Oberon_Id(Oberon_Id,from_string) renaming (from_string to string_to_id)
16 >import Oberon_Integer
17 > (Oberon_Integer, from_decimal_string, from_hex_string, from_int)
19 > ( from_decimal_string to decimal_string_to_int
20 > , from_hex_string to hex_string_to_int
23 >import Oberon_Real(Oberon_Real, from_string) renaming
24 > (from_string to string_to_real)
26 >import Oberon_String(Oberon_String, from_string) renaming
27 > (from_string to string_to_string)
29 >import Lexer_Combinators(and_then)
31 >import Source_Position(Source_Position, next_line, shift_column, start)
32 > renaming (start to start_position)
34 >t_source_pos transformer =
35 > p_source_pos `and_with` \pos ->
36 > i_source_pos (transformer pos)
38 >t_buffer transformer =
39 > p_buffer `and_with` \buff ->
40 > i_buffer (transformer buff)
43 >buffer_len :: Lexer_Action Int
45 > p_buffer `and_with` \buff ->
49 >decimal_to_int :: Lexer_Action Oberon_Integer
51 > p_buffer `and_with` \buff ->
52 > return (decimal_string_to_int (buffer_to_string buff))
54 >flush_buffer :: Lexer_Action ()
55 >flush_buffer = t_buffer flush
57 >hex_to_int :: Lexer_Action Oberon_Integer
59 > p_buffer `and_with` \buff ->
60 > return (hex_string_to_int (buffer_to_string buff))
62 >move_input_column :: Int -> Lexer_Action ()
63 >move_input_column dist = t_source_pos (flip shift_column dist)
65 >next_input_line :: Lexer_Action ()
66 >next_input_line = t_source_pos next_line
68 >store_char :: Char -> Lexer_Action ()
69 >store_char c = t_buffer (add_char c)
71 >to_char :: Lexer_Action Oberon_Integer
73 > p_buffer `and_with` \buff ->
74 > return ((from_int . toInteger . ord . head . buffer_to_string) buff)
76 Converts the string in the buffer into a character (actually an
77 integer since characters are represented as integers). The
78 pre-condition is that there is exactly one character in the buffer
82 >to_id :: Lexer_Action Oberon_Id
84 > p_buffer `and_with` \buff ->
85 > return (string_to_id (buffer_to_string buff))
87 >to_real :: Lexer_Action Oberon_Real
89 > p_buffer `and_with` \buff ->
90 > return (string_to_real (buffer_to_string buff))
92 >to_string :: Lexer_Action Oberon_String
94 > p_buffer `and_with` \buff ->
95 > return (string_to_string (buffer_to_string buff))