Permalink
Browse files

move the posn-bytestring test to tokens_posn_bytestring.x, add a

basic-bytestring test as tokens_bytestring.x
  • Loading branch information...
1 parent 6fc49e0 commit aaf38ac8eb939227bb105b49719fe240e5c29f41 @simonmar committed Aug 10, 2011
Showing with 62 additions and 20 deletions.
  1. +1 −1 tests/Makefile
  2. +15 −19 tests/tokens_bytestring.x
  3. +46 −0 tests/tokens_posn_bytestring.x
View
@@ -9,7 +9,7 @@ else
HS_PROG_EXT = .bin
endif
-TESTS = unicode.x simple.x tokens.x tokens_posn.x tokens_gscan.x tokens_bytestring.x
+TESTS = unicode.x simple.x tokens.x tokens_posn.x tokens_gscan.x tokens_bytestring.x tokens_posn_bytestring.x
TEST_ALEX_OPTS = --template=..
View
@@ -5,7 +5,7 @@ import System.Exit
import Data.ByteString.Lazy.Char8 (unpack)
}
-%wrapper "posn-bytestring"
+%wrapper "basic-bytestring"
$digit = 0-9 -- digits
$alpha = [a-zA-Z] -- alphabetic characters
@@ -14,33 +14,29 @@ tokens :-
$white+ ;
"--".* ;
- let { tok (\p s -> Let p) }
- in { tok (\p s -> In p) }
- $digit+ { tok (\p s -> Int p (read (unpack s))) }
- [\=\+\-\*\/\(\)] { tok (\p s -> Sym p (head (unpack s))) }
- $alpha [$alpha $digit \_ \']* { tok (\p s -> Var p (unpack s)) }
+ let { \s -> Let }
+ in { \s -> In }
+ $digit+ { \s -> Int (read (unpack s)) }
+ [\=\+\-\*\/\(\)] { \s -> Sym (head (unpack s)) }
+ $alpha [$alpha $digit \_ \']* { \s -> Var (unpack s) }
{
--- Each right-hand side has type :: AlexPosn -> String -> Token
-
--- Some action helpers:
-tok f p s = f p s
+-- Each right-hand side has type :: ByteString -> Token
-- The token type:
data Token =
- Let AlexPosn |
- In AlexPosn |
- Sym AlexPosn Char |
- Var AlexPosn String |
- Int AlexPosn Int |
- Err AlexPosn
+ Let |
+ In |
+ Sym Char |
+ Var String |
+ Int Int |
+ Err
deriving (Eq,Show)
main = if test1 /= result1 then exitFailure
- else exitWith ExitSuccess
+ else exitWith ExitSuccess
test1 = alexScanTokens " let in 012334\n=+*foo bar__'"
-result1 = [Let (AlexPn 2 1 3),In (AlexPn 6 1 7),Int (AlexPn 9 1 10) 12334,Sym (AlexPn 16 2 1) '=',Sym (AlexPn 17 2 2) '+',Sym (AlexPn 18 2 3) '*',Var (AlexPn 19 2 4) "foo",Var (AlexPn 23 2 8) "bar__'"]
-
+result1 = [Let,In,Int 12334,Sym '=',Sym '+',Sym '*',Var "foo",Var "bar__'"]
}
@@ -0,0 +1,46 @@
+{
+{-# LANGUAGE OverloadedStrings #-}
+module Main (main) where
+import System.Exit
+import Data.ByteString.Lazy.Char8 (unpack)
+}
+
+%wrapper "posn-bytestring"
+
+$digit = 0-9 -- digits
+$alpha = [a-zA-Z] -- alphabetic characters
+
+tokens :-
+
+ $white+ ;
+ "--".* ;
+ let { tok (\p s -> Let p) }
+ in { tok (\p s -> In p) }
+ $digit+ { tok (\p s -> Int p (read (unpack s))) }
+ [\=\+\-\*\/\(\)] { tok (\p s -> Sym p (head (unpack s))) }
+ $alpha [$alpha $digit \_ \']* { tok (\p s -> Var p (unpack s)) }
+
+{
+-- Each right-hand side has type :: AlexPosn -> String -> Token
+
+-- Some action helpers:
+tok f p s = f p s
+
+-- The token type:
+data Token =
+ Let AlexPosn |
+ In AlexPosn |
+ Sym AlexPosn Char |
+ Var AlexPosn String |
+ Int AlexPosn Int |
+ Err AlexPosn
+ deriving (Eq,Show)
+
+main = if test1 /= result1 then exitFailure
+ else exitWith ExitSuccess
+
+test1 = alexScanTokens " let in 012334\n=+*foo bar__'"
+result1 = [Let (AlexPn 2 1 3),In (AlexPn 6 1 7),Int (AlexPn 9 1 10) 12334,Sym (AlexPn 16 2 1) '=',Sym (AlexPn 17 2 2) '+',Sym (AlexPn 18 2 3) '*',Var (AlexPn 19 2 4) "foo",Var (AlexPn 23 2 8) "bar__'"]
+
+
+}

0 comments on commit aaf38ac

Please sign in to comment.