~ubuntu-branches/ubuntu/jaunty/alex/jaunty

« back to all changes in this revision

Viewing changes to alex/src/Scan.hs

  • Committer: Bazaar Package Importer
  • Author(s): Ian Lynagh (wibble)
  • Date: 2003-10-01 12:31:01 UTC
  • Revision ID: james.westby@ubuntu.com-20031001123101-yquo14mvjqh3e0sk
Tags: upstream-2.0
ImportĀ upstreamĀ versionĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{-# OPTIONS -cpp #-}
 
2
{-# LINE 13 "Scan.x" #-}
 
3
module Scan(lexer, AlexPosn(..), Token(..), Tkn(..), tokPosn) where
 
4
 
 
5
import Data.Char
 
6
import ParseMonad
 
7
--import Debug.Trace
 
8
 
 
9
#if __GLASGOW_HASKELL__ >= 503
 
10
import Data.Array
 
11
import Data.Char (ord)
 
12
import Data.Array.Base (unsafeAt)
 
13
#else
 
14
import Array
 
15
import Char (ord)
 
16
#endif
 
17
alex_base :: Array Int Int
 
18
alex_base = listArray (0,76) [-8,110,137,119,124,-4,-3,-37,-36,0,128,129,0,114,-35,115,-34,251,365,256,116,117,-33,0,138,0,423,0,-106,-100,-82,-96,-95,-83,-94,222,331,515,594,617,341,649,0,0,655,770,884,644,968,1052,1113,1227,1341,1455,1453,1537,1598,0,135,396,167,168,-26,0,169,801,170,281,-24,0,0,1682,1766,0,0,0,736]
 
19
 
 
20
alex_table :: Array Int Int
 
21
alex_table = listArray (0,2021) [0,4,4,4,4,4,-1,-1,5,5,12,12,20,29,30,31,32,33,34,60,27,66,0,0,4,43,10,25,26,28,43,43,25,25,25,25,25,8,25,25,43,43,43,43,43,43,43,43,43,43,16,25,69,43,43,25,44,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,25,37,25,25,43,43,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,24,25,25,25,4,4,4,4,4,-1,-1,-1,-1,4,4,4,4,4,4,4,4,4,4,-1,-1,0,0,4,0,0,-1,4,4,4,4,4,4,0,0,0,7,4,0,0,0,13,0,9,9,7,0,0,0,0,4,0,0,15,15,15,15,0,-1,-1,-1,-1,73,7,0,0,70,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,58,0,0,74,0,0,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,58,58,64,64,0,76,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,19,19,19,19,19,19,19,19,19,19,35,35,35,35,35,35,35,35,35,35,0,0,0,19,0,0,0,0,19,0,18,-1,0,0,0,0,22,0,0,18,18,18,18,18,18,18,18,18,18,14,0,0,0,0,14,0,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,64,0,0,0,18,0,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,35,35,35,35,35,35,35,35,35,35,40,40,40,40,40,40,40,40,19,0,0,0,0,0,0,18,59,59,59,59,59,22,0,0,18,18,18,18,18,18,18,18,18,18,14,0,0,0,0,59,0,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,0,57,0,0,18,0,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,0,0,0,0,0,0,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,50,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,36,36,36,36,36,36,36,36,36,36,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,41,42,42,42,42,42,42,42,42,39,42,42,42,42,42,42,38,38,38,38,38,38,38,38,38,38,0,59,59,59,59,59,0,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,0,59,0,0,0,0,0,38,38,38,38,38,38,0,62,0,38,38,38,38,38,38,40,40,40,40,40,40,40,40,57,0,0,0,0,0,0,0,0,38,38,38,38,38,38,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,0,0,0,0,0,0,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,56,59,59,59,59,59,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,59,0,0,0,0,0,0,46,65,65,65,65,65,62,0,0,46,46,46,46,46,46,46,46,46,46,0,0,0,57,0,65,0,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,0,63,0,0,46,0,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,59,59,59,59,59,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,0,0,0,0,0,0,46,0,0,0,0,0,62,0,0,46,46,46,46,46,46,46,46,46,46,0,0,0,57,0,0,0,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,0,0,0,0,46,0,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,49,0,0,0,0,0,0,0,0,49,49,49,49,49,49,49,49,49,49,0,0,0,0,0,0,0,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,0,0,0,0,49,0,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,0,47,0,0,0,0,0,0,49,49,49,49,49,49,49,49,49,49,0,0,0,0,0,0,0,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,0,0,0,0,49,0,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,0,0,47,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,0,0,0,0,0,0,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,65,65,65,65,65,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,0,0,0,0,0,0,52,0,0,0,0,0,68,0,0,52,52,52,52,52,52,52,52,52,52,0,0,0,63,0,0,0,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,0,0,0,0,52,0,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,65,65,65,65,65,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,0,0,0,0,0,0,52,0,0,0,0,0,68,0,0,52,52,52,52,52,52,52,52,52,52,0,0,0,63,0,0,0,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,0,0,0,0,52,0,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,65,65,65,65,65,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,0,0,0,0,55,0,0,0,0,0,0,0,68,55,55,55,55,55,55,55,55,55,55,0,0,0,0,0,63,0,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,0,0,0,0,55,0,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,0,53,0,0,0,0,0,0,55,55,55,55,55,55,55,55,55,55,0,0,0,0,0,0,0,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,0,0,0,0,55,0,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,0,0,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,0,0,0,0,0,0,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,72,0,0,0,0,0,0,0,0,72,72,72,72,72,72,72,72,72,72,0,0,0,0,0,0,0,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,0,0,0,0,72,0,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,0,0,0,0,0,0,0,0,72,72,72,72,72,72,72,72,72,72,0,0,0,0,0,0,0,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,0,0,0,0,72,0,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
 
22
 
 
23
alex_check :: Array Int Int
 
24
alex_check = listArray (0,2021) [-1,9,10,11,12,13,10,10,45,45,45,45,45,119,114,97,112,112,101,45,114,45,-1,-1,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,9,10,11,12,13,10,10,10,10,9,10,11,12,13,9,10,11,12,13,10,10,-1,-1,32,-1,-1,10,9,10,11,12,13,32,-1,-1,-1,45,32,-1,-1,-1,45,-1,34,34,45,-1,-1,-1,-1,32,-1,-1,58,58,58,58,-1,10,10,10,10,44,45,-1,-1,48,48,49,50,51,52,53,54,55,56,57,61,-1,-1,62,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,61,61,61,61,-1,123,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,9,10,11,12,13,9,10,11,12,13,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,32,-1,-1,-1,-1,32,-1,39,10,-1,-1,-1,-1,45,-1,-1,48,49,50,51,52,53,54,55,56,57,58,-1,-1,-1,-1,58,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,61,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,9,10,11,12,13,48,49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,32,-1,-1,-1,-1,-1,-1,39,9,10,11,12,13,45,-1,-1,48,49,50,51,52,53,54,55,56,57,58,-1,-1,-1,-1,32,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,61,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,-1,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,48,49,50,51,52,53,54,55,56,57,-1,9,10,11,12,13,-1,65,66,67,68,69,70,48,49,50,51,52,53,54,55,56,57,-1,32,-1,-1,-1,-1,-1,65,66,67,68,69,70,-1,45,-1,97,98,99,100,101,102,48,49,50,51,52,53,54,55,61,-1,-1,-1,-1,-1,-1,-1,-1,97,98,99,100,101,102,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,-1,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,9,10,11,12,13,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,-1,-1,-1,32,-1,-1,-1,-1,-1,-1,39,9,10,11,12,13,45,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,61,-1,32,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,61,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,9,10,11,12,13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,-1,-1,-1,-1,-1,-1,39,-1,-1,-1,-1,-1,45,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,61,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,39,-1,-1,-1,-1,-1,-1,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,39,-1,125,-1,-1,-1,-1,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,-1,-1,125,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,-1,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,9,10,11,12,13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,-1,-1,-1,-1,-1,-1,39,-1,-1,-1,-1,-1,45,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,61,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,9,10,11,12,13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,-1,-1,-1,-1,-1,-1,39,-1,-1,-1,-1,-1,45,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,61,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,9,10,11,12,13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,-1,-1,-1,-1,39,-1,-1,-1,-1,-1,-1,-1,45,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,61,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,39,-1,125,-1,-1,-1,-1,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,-1,-1,125,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,-1,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,39,-1,-1,-1,-1,-1,-1,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,39,-1,-1,-1,-1,-1,-1,-1,-1,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,-1,-1,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,-1,-1,-1,-1,95,-1,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
 
25
 
 
26
alex_deflt :: Array Int Int
 
27
alex_deflt = listArray (0,76) [-1,-1,-1,-1,-1,6,6,-1,-1,-1,11,11,-1,21,-1,21,-1,-1,-1,-1,21,21,-1,-1,23,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,61,-1,61,61,-1,-1,67,-1,67,67,-1,-1,-1,-1,-1,-1,-1,-1,75]
 
28
 
 
29
alex_accept = listArray (0::Int,76) [[],[(AlexAcc (alex_action_21))],[],[],[(AlexAcc (alex_action_0))],[(AlexAcc (alex_action_0))],[(AlexAcc (alex_action_0))],[],[(AlexAcc (alex_action_4))],[(AlexAcc (alex_action_1))],[(AlexAcc (alex_action_10))],[],[(AlexAcc (alex_action_2))],[(AlexAcc (alex_action_2))],[],[],[(AlexAcc (alex_action_10))],[(AlexAcc (alex_action_10))],[],[],[],[],[],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_4))],[(AlexAcc (alex_action_4))],[(AlexAcc (alex_action_4))],[(AlexAcc (alex_action_5))],[],[],[],[],[],[],[],[(AlexAcc (alex_action_6))],[(AlexAcc (alex_action_6))],[(AlexAcc (alex_action_10))],[(AlexAcc (alex_action_7))],[(AlexAcc (alex_action_9))],[(AlexAcc (alex_action_8))],[(AlexAcc (alex_action_9))],[(AlexAcc (alex_action_9))],[(AlexAcc (alex_action_10))],[(AlexAcc (alex_action_10))],[(AlexAcc (alex_action_11))],[(AlexAcc (alex_action_11))],[(AlexAcc (alex_action_11))],[],[],[],[(AlexAcc (alex_action_12))],[(AlexAcc (alex_action_12))],[(AlexAcc (alex_action_12))],[],[],[],[(AlexAcc (alex_action_13))],[(AlexAcc (alex_action_13))],[],[],[],[],[(AlexAcc (alex_action_14))],[(AlexAcc (alex_action_14))],[],[],[],[],[(AlexAcc (alex_action_15))],[(AlexAcc (alex_action_16))],[(AlexAcc (alex_action_17))],[(AlexAcc (alex_action_17))],[(AlexAcc (alex_action_18))],[(AlexAcc (alex_action_19))],[(AlexAcc (alex_action_20))],[]]
 
30
{-# LINE 73 "Scan.x" #-}
 
31
 
 
32
-- -----------------------------------------------------------------------------
 
33
-- Token type
 
34
 
 
35
data Token = T AlexPosn Tkn
 
36
  deriving Show
 
37
 
 
38
tokPosn (T p _) = p
 
39
 
 
40
data Tkn
 
41
 = SpecialT Char
 
42
 | CodeT String
 
43
 | ZeroT
 
44
 | IdT String
 
45
 | StringT String
 
46
 | BindT String
 
47
 | CharT Char
 
48
 | SMacT String
 
49
 | RMacT String  
 
50
 | SMacDefT String
 
51
 | RMacDefT String  
 
52
 | NumT Int     
 
53
 | WrapperT
 
54
 | EOFT
 
55
 deriving Show
 
56
 
 
57
-- -----------------------------------------------------------------------------
 
58
-- Token functions
 
59
 
 
60
special   (p,_,str) ln = return $ T p (SpecialT  (head str))
 
61
zero      (p,_,str) ln = return $ T p ZeroT
 
62
string    (p,_,str) ln = return $ T p (StringT (extract ln str))
 
63
bind      (p,_,str) ln = return $ T p (BindT (takeWhile isIdChar str))
 
64
escape    (p,_,str) ln = return $ T p (CharT (esc str))
 
65
decch     (p,_,str) ln = return $ T p (CharT (do_ech 10 ln (take (ln-1) (tail str))))
 
66
hexch     (p,_,str) ln = return $ T p (CharT (do_ech 16 ln (take (ln-2) (drop 2 str))))
 
67
octch     (p,_,str) ln = return $ T p (CharT (do_ech 8  ln (take (ln-2) (drop 2 str))))
 
68
char      (p,_,str) ln = return $ T p (CharT (head str))
 
69
smac      (p,_,str) ln = return $ T p (SMacT (mac ln str))
 
70
rmac      (p,_,str) ln = return $ T p (RMacT (mac ln str))
 
71
smacdef   (p,_,str) ln = return $ T p (SMacDefT (macdef ln str))
 
72
rmacdef   (p,_,str) ln = return $ T p (RMacDefT (macdef ln str))
 
73
startcode (p,_,str) ln = return $ T p (IdT (take ln str))
 
74
wrapper   (p,_,str) ln = return $ T p WrapperT
 
75
 
 
76
isIdChar c = isAlphaNum c || c `elem` "_'"
 
77
 
 
78
extract ln str = take (ln-2) (tail str)
 
79
                
 
80
do_ech radix ln str = chr (parseInt radix str)
 
81
 
 
82
mac ln (_ : str) = take (ln-1) str
 
83
 
 
84
macdef ln (_ : str) = takeWhile (not.isSpace) str
 
85
 
 
86
esc (_ : x : _)  =
 
87
 case x of
 
88
   'a' -> '\a'
 
89
   'b' -> '\b'
 
90
   'f' -> '\f'
 
91
   'n' -> '\n'
 
92
   'r' -> '\r'
 
93
   't' -> '\t'
 
94
   'v' -> '\v'
 
95
   c   ->  c
 
96
 
 
97
parseInt :: Int -> String -> Int
 
98
parseInt radix ds = foldl1 (\n d -> n * radix + d) (map digitToInt ds)
 
99
 
 
100
-- In brace-delimited code, we have to be careful to match braces
 
101
-- within the code, but ignore braces inside strings and character
 
102
-- literals.  We do an approximate job (doing it properly requires
 
103
-- implementing a large chunk of the Haskell lexical syntax).
 
104
 
 
105
code (p,_,inp) len = do
 
106
 inp <- getInput
 
107
 go inp 1 ""
 
108
 where
 
109
  go inp 0 cs = do
 
110
    setInput inp
 
111
    return (T p (CodeT (reverse (tail cs))))
 
112
  go inp n cs = do
 
113
    case alexGetChar inp of
 
114
        Nothing  -> err inp
 
115
        Just (c,inp)   -> 
 
116
          case c of
 
117
                '{'  -> go inp (n+1) (c:cs) 
 
118
                '}'  -> go inp (n-1) (c:cs)
 
119
                '\'' -> go_char inp n (c:cs)
 
120
                '\"' -> go_str inp n (c:cs) '\"'
 
121
                c    -> go inp n (c:cs)
 
122
 
 
123
        -- try to catch occurrences of ' within an identifier
 
124
  go_char inp n (c1:c2:cs) | isAlphaNum c2 = go inp n (c1:c2:cs)
 
125
  go_char inp n cs = go_str inp n cs '\''
 
126
 
 
127
  go_str inp n cs end = do
 
128
    case alexGetChar inp of
 
129
        Nothing -> err inp
 
130
        Just (c,inp)
 
131
          | c == end  -> go inp n (c:cs)
 
132
          | otherwise -> 
 
133
                case c of
 
134
                   '\\' -> case alexGetChar inp of
 
135
                             Nothing -> err inp
 
136
                             Just (d,inp)  -> go_str inp n (d:c:cs) end
 
137
                   c -> go_str inp n (c:cs) end
 
138
 
 
139
  err inp = do setInput inp; lexError "lexical error in code fragment"
 
140
                                  
 
141
 
 
142
 
 
143
lexError s = do
 
144
  (p,_,input) <- getInput
 
145
  failP (s ++ (if (not (null input))
 
146
                  then " at " ++ show (head input)
 
147
                  else " at end of file"))
 
148
 
 
149
lexer :: (Token -> P a) -> P a
 
150
lexer cont = lexToken >>= cont
 
151
 
 
152
lexToken :: P Token
 
153
lexToken = do
 
154
  inp@(p,_,_) <- getInput
 
155
  sc <- getStartCode
 
156
  case alexScan inp sc of
 
157
    AlexEOF -> return (T p EOFT)
 
158
    AlexError _ -> lexError "lexical error"
 
159
    AlexSkip inp1 len -> do
 
160
        setInput inp1
 
161
        lexToken
 
162
    AlexToken inp1 len t -> do
 
163
        setInput inp1
 
164
        t inp len
 
165
 
 
166
type Action = AlexInput -> Int -> P Token
 
167
 
 
168
skip :: Action
 
169
skip _ _ = lexToken
 
170
 
 
171
andBegin :: Action -> StartCode -> Action
 
172
andBegin act sc inp len = setStartCode sc >> act inp len
 
173
 
 
174
 
 
175
afterstartcodes,startcodes :: Int
 
176
afterstartcodes = 1
 
177
startcodes = 2
 
178
alex_action_0 = skip 
 
179
alex_action_1 = string 
 
180
alex_action_2 = bind 
 
181
alex_action_3 = code 
 
182
alex_action_4 = special 
 
183
alex_action_5 = wrapper 
 
184
alex_action_6 = decch 
 
185
alex_action_7 = hexch 
 
186
alex_action_8 = octch 
 
187
alex_action_9 = escape 
 
188
alex_action_10 = char 
 
189
alex_action_11 = smac 
 
190
alex_action_12 = rmac 
 
191
alex_action_13 = smacdef 
 
192
alex_action_14 = rmacdef 
 
193
alex_action_15 = special `andBegin` startcodes 
 
194
alex_action_16 = zero 
 
195
alex_action_17 = startcode 
 
196
alex_action_18 = special 
 
197
alex_action_19 = special `andBegin` afterstartcodes 
 
198
alex_action_20 = special `andBegin` 0 
 
199
alex_action_21 = skip `andBegin` 0 
 
200
{-# LINE 1 "GenericTemplate.hs" #-}
 
201
-- -----------------------------------------------------------------------------
 
202
-- ALEX TEMPLATE
 
203
--
 
204
-- This code is in the PUBLIC DOMAIN; you may copy it freely and use
 
205
-- it for any purpose whatsoever.
 
206
 
 
207
-- -----------------------------------------------------------------------------
 
208
-- INTERNALS and main scanner engine
 
209
 
 
210
{-# LINE 22 "GenericTemplate.hs" #-}
 
211
 
 
212
 
 
213
 
 
214
 
 
215
 
 
216
 
 
217
 
 
218
 
 
219
 
 
220
 
 
221
 
 
222
 
 
223
 
 
224
 
 
225
 
 
226
 
 
227
 
 
228
 
 
229
 
 
230
 
 
231
 
 
232
 
 
233
 
 
234
{-# LINE 66 "GenericTemplate.hs" #-}
 
235
 
 
236
alexIndexShortOffAddr arr off = arr ! off
 
237
 
 
238
 
 
239
-- -----------------------------------------------------------------------------
 
240
-- Main lexing routines
 
241
 
 
242
data AlexReturn a
 
243
  = AlexEOF
 
244
  | AlexError  !AlexInput
 
245
  | AlexSkip   !AlexInput !Int
 
246
  | AlexToken  !AlexInput !Int a
 
247
 
 
248
-- alexScan :: AlexInput -> StartCode -> Maybe (AlexInput,Int,act)
 
249
alexScan input (sc)
 
250
  = alexScanUser undefined input (sc)
 
251
 
 
252
alexScanUser user input (sc)
 
253
  = case alex_scan_tkn user input (0) input sc AlexNone of
 
254
        (AlexNone, input') ->
 
255
                case alexGetChar input of
 
256
                        Nothing -> 
 
257
 
 
258
 
 
259
 
 
260
                                   AlexEOF
 
261
                        Just _ ->
 
262
 
 
263
 
 
264
 
 
265
                                   AlexError input
 
266
 
 
267
        (AlexLastSkip input len, _) ->
 
268
 
 
269
 
 
270
 
 
271
                AlexSkip input len
 
272
 
 
273
        (AlexLastAcc k input len, _) ->
 
274
 
 
275
 
 
276
 
 
277
                AlexToken input len k
 
278
 
 
279
 
 
280
-- Push the input through the DFA, remembering the most recent accepting
 
281
-- state it encountered.
 
282
 
 
283
alex_scan_tkn user orig_input len input s last_acc =
 
284
  input `seq` -- strict in the input
 
285
  case s of 
 
286
    (-1) -> (last_acc, input)
 
287
    _ -> alex_scan_tkn' user orig_input len input s last_acc
 
288
 
 
289
alex_scan_tkn' user orig_input len input s last_acc =
 
290
  let 
 
291
        new_acc = check_accs (alex_accept `unsafeAt` (s))
 
292
  in
 
293
  new_acc `seq`
 
294
  case alexGetChar input of
 
295
     Nothing -> (new_acc, input)
 
296
     Just (c, new_input) -> 
 
297
 
 
298
 
 
299
 
 
300
        let
 
301
                base   = alexIndexShortOffAddr alex_base s
 
302
                (ord_c) = ord c
 
303
                offset = (base + ord_c)
 
304
                check  = alexIndexShortOffAddr alex_check offset
 
305
                
 
306
                new_s = if (offset >= (0)) && (check == ord_c)
 
307
                          then alexIndexShortOffAddr alex_table offset
 
308
                          else alexIndexShortOffAddr alex_deflt s
 
309
        in
 
310
        alex_scan_tkn user orig_input (len + (1)) new_input new_s new_acc
 
311
 
 
312
  where
 
313
        check_accs [] = last_acc
 
314
        check_accs (AlexAcc a : _) = AlexLastAcc a input (len)
 
315
        check_accs (AlexAccSkip : _)  = AlexLastSkip  input (len)
 
316
        check_accs (AlexAccPred a pred : rest)
 
317
           | pred user orig_input (len) input
 
318
           = AlexLastAcc a input (len)
 
319
        check_accs (AlexAccSkipPred pred : rest)
 
320
           | pred user orig_input (len) input
 
321
           = AlexLastSkip input (len)
 
322
        check_accs (_ : rest) = check_accs rest
 
323
 
 
324
data AlexLastAcc a
 
325
  = AlexNone
 
326
  | AlexLastAcc a !AlexInput !Int
 
327
  | AlexLastSkip  !AlexInput !Int
 
328
 
 
329
data AlexAcc a user
 
330
  = AlexAcc a
 
331
  | AlexAccSkip
 
332
  | AlexAccPred a (AlexAccPred user)
 
333
  | AlexAccSkipPred (AlexAccPred user)
 
334
 
 
335
type AlexAccPred user = user -> AlexInput -> Int -> AlexInput -> Bool
 
336
 
 
337
-- -----------------------------------------------------------------------------
 
338
-- Predicates on a rule
 
339
 
 
340
alexAndPred p1 p2 user in1 len in2
 
341
  = p1 user in1 len in2 && p2 user in1 len in2
 
342
 
 
343
--alexPrevCharIsPred :: Char -> AlexAccPred _ 
 
344
alexPrevCharIs c _ input _ _ = c == alexInputPrevChar input
 
345
 
 
346
--alexPrevCharIsOneOfPred :: Array Char Bool -> AlexAccPred _ 
 
347
alexPrevCharIsOneOf arr _ input _ _ = arr ! alexInputPrevChar input
 
348
 
 
349
--alexRightContext :: Int -> AlexAccPred _
 
350
alexRightContext (sc) user _ _ input = 
 
351
     case alex_scan_tkn user input (0) input sc AlexNone of
 
352
          (AlexNone, _) -> False
 
353
          _ -> True
 
354
        -- TODO: there's no need to find the longest
 
355
        -- match when checking the right context, just
 
356
        -- the first match will do.
 
357
 
 
358
-- used by wrappers
 
359
iUnbox (i) = i