[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / compiler / tests / rename / bevan-bug-1 / Lexer_Ops.lhs
1   $Id: Lexer_Ops.lhs,v 1.1 1996/01/08 20:17:58 partain Exp $
2
3 >module Lexer_Ops where
4
5 >import Lexer_Buffer(Lexer_Buffer, add, empty, flush, len, to_string)
6 >  renaming
7 >  (add to add_char, empty to empty_buffer, to_string to buffer_to_string)
8
9 >import Lexer_Combinators(and_with, return)
10
11 >import Lexer_State
12 >  (Lexer_State,Lexer_Action(..),i_buffer,i_source_pos,p_buffer,p_source_pos)
13
14 >import Oberon_Id(Oberon_Id,from_string) renaming (from_string to string_to_id)
15
16 >import Oberon_Integer
17 >  (Oberon_Integer, from_decimal_string, from_hex_string, from_int)
18 >  renaming
19 >  ( from_decimal_string to decimal_string_to_int
20 >  , from_hex_string to hex_string_to_int
21 >  )
22
23 >import Oberon_Real(Oberon_Real, from_string) renaming 
24 >  (from_string to string_to_real)
25
26 >import Oberon_String(Oberon_String, from_string) renaming
27 >  (from_string to string_to_string)
28
29 >import Lexer_Combinators(and_then)
30
31 >import Source_Position(Source_Position, next_line, shift_column, start)
32 >  renaming (start to start_position)
33
34 >t_source_pos transformer =
35 >  p_source_pos `and_with` \pos ->
36 >  i_source_pos (transformer pos)
37
38 >t_buffer transformer =
39 >  p_buffer `and_with` \buff ->
40 >  i_buffer (transformer buff)
41
42
43 >buffer_len :: Lexer_Action Int
44 >buffer_len =
45 >  p_buffer `and_with` \buff ->
46 >  return (len buff)
47
48
49 >decimal_to_int :: Lexer_Action Oberon_Integer
50 >decimal_to_int =
51 >  p_buffer `and_with` \buff ->
52 >  return (decimal_string_to_int (buffer_to_string buff))
53
54 >flush_buffer :: Lexer_Action ()
55 >flush_buffer = t_buffer flush
56
57 >hex_to_int :: Lexer_Action Oberon_Integer
58 >hex_to_int =
59 >  p_buffer `and_with` \buff ->
60 >  return (hex_string_to_int (buffer_to_string buff))
61
62 >move_input_column :: Int -> Lexer_Action ()
63 >move_input_column dist = t_source_pos (flip shift_column dist)
64
65 >next_input_line :: Lexer_Action ()
66 >next_input_line = t_source_pos next_line
67
68 >store_char :: Char -> Lexer_Action ()
69 >store_char c = t_buffer (add_char c)
70
71 >to_char :: Lexer_Action Oberon_Integer
72 >to_char =
73 >  p_buffer `and_with` \buff ->
74 >  return ((from_int . toInteger . ord . head . buffer_to_string) buff)
75
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
79 when this is called.
80
81
82 >to_id :: Lexer_Action Oberon_Id
83 >to_id = 
84 >  p_buffer `and_with` \buff ->
85 >  return (string_to_id (buffer_to_string buff))
86
87 >to_real :: Lexer_Action Oberon_Real
88 >to_real =
89 >  p_buffer `and_with` \buff ->
90 >  return (string_to_real (buffer_to_string buff))
91
92 >to_string :: Lexer_Action Oberon_String
93 >to_string =
94 >  p_buffer `and_with` \buff ->
95 >  return (string_to_string (buffer_to_string buff))
96
97 % eof