Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81248 / clex
diff options
context:
space:
mode:
Commitaeb0d4f887a0c18c36b59acc7b5df08e62020c50 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:32:48 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:33:38 +0300
Filesb6abdc6e1810326b587f2a160f39570f1f568f27 /homework/81248/clex
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar.gz
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.zip
Parent154b7cd30f21af1554ca26986ff1643e28857727 (diff)
Removed old homeworks
diff --git a/homework/81248/clex/.gitignore b/homework/81248/clex/.gitignore
deleted file mode 100644
index c0989f9..0000000
--- a/homework/81248/clex/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-.stack-work/
-clex.cabal
-*~
-*.swp
diff --git a/homework/81248/clex/Setup.hs b/homework/81248/clex/Setup.hs
deleted file mode 100644
index 9a994af..0000000
--- a/homework/81248/clex/Setup.hs
+++ /dev/null
@@ -1,2 +0,0 @@
-import Distribution.Simple
-main = defaultMain
diff --git a/homework/81248/clex/keyword-strings.txt b/homework/81248/clex/keyword-strings.txt
deleted file mode 100644
index d6c2157..0000000
--- a/homework/81248/clex/keyword-strings.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-"auto"
-"break"
-"case"
-"char"
-"const"
-"continue"
-"default"
-"do"
-"double"
-"else"
-"enum"
-"extern"
-"float"
-"for"
-"goto"
-"if"
-"int"
-"long"
-"register"
-"return"
-"short"
-"signed"
-"sizeof"
-"static"
-"struct"
-"switch"
-"typedef"
-"union"
-"unsigned"
-"void"
-"volatile"
-"while"
-".."
-"+="
-"-="
-"*="
-"/="
-"%="
-"&="
-"^="
-"|="
-"++"
-"--"
-"->"
-"&&"
-"||"
-"<="
-">="
-"=="
-"!="
-">>"
-"<<"
-"."
-"<"
-">"
-"&"
-"|"
-"~"
-"!"
-";"
-"{"
-"}"
-","
-":"
-"="
-"("
-")"
-"["
-"]"
-"-"
-"+"
-"*"
-"/"
-"%"
-"^"
-"?"
diff --git a/homework/81248/clex/package.yaml b/homework/81248/clex/package.yaml
deleted file mode 100644
index 3bf0dc9..0000000
--- a/homework/81248/clex/package.yaml
+++ /dev/null
@@ -1,33 +0,0 @@
-name: clex
-version: 0.0.0.1
-author: "Georgi Lyubenov"
-maintainer: "godzbanebane@gmail.com"
-
-description: Lex C and keep whitespace so I can print it afterwards.
-
-dependencies:
-- base >= 4.7 && < 5
-- bytestring
-- attoparsec
-- word8
-
-library:
- source-dirs: src
-
-ghc-options:
-- -Wall
-- -Werror
-
-tests:
- clex-test:
- main: Spec.hs
- source-dirs: test
- ghc-options:
- - -threaded
- - -rtsopts
- - -with-rtsopts=-N
- dependencies:
- - clex
- - QuickCheck
- - hspec
- - bytestring-arbitrary
diff --git a/homework/81248/clex/sample.c b/homework/81248/clex/sample.c
deleted file mode 100644
index dad89ad..0000000
--- a/homework/81248/clex/sample.c
+++ /dev/null
@@ -1,95 +0,0 @@
-float xs = 0.5e123213f;
-float xss = .5f;
-
-typedef struct word_struct {
- const char* begin;
- int length;
-} word;
-
-const word get_word(const char* begin){
- const char* current = begin;
- short len = 0;
- while( (*current != ' ') && (*current != 0) && (*current != '\n') ) {
- current++;
- len++;
- }
- word res = {
- .begin = begin,
- .length = len
- };
- return res;
-}
-
-void print_op(const char symb, FILE* file_write) {
- fprintf(file_write, "%c", symb);
-}
-
-const int single_char(char *line, int *count, FILE* file_write) {
- char letter = *(line + *count);
- switch(letter) {
- case ';': print_op(';', file_write); return 1;
- case '{': print_op('{', file_write); return 1;
- case '}': print_op('}', file_write); return 1;
- case ',': print_op(',', file_write); return 1;
- case ':': print_op(':', file_write); return 1;
- case '=': print_op('=', file_write); return 1;
- case '(': print_op('(', file_write); return 1;
- case ')': print_op(')', file_write); return 1;
- case '[': print_op('[', file_write); return 1;
- case ']': print_op(']', file_write); return 1;
- case '.': print_op('.', file_write); return 1;
- case '&': print_op('&', file_write); return 1;
- case '!': print_op('!', file_write); return 1;
- case '~': print_op('~', file_write); return 1;
- case '-': print_op('-', file_write); return 1;
- case '+': print_op('+', file_write); return 1;
- case '*': print_op('*', file_write); return 1;
- case '/': print_op('/', file_write); return 1;
- case '%': print_op('%', file_write); return 1;
- case '<': print_op('<', file_write); return 1;
- case '>': print_op('>', file_write); return 1;
- case '^': print_op('^', file_write); return 1;
- case '|': print_op('|', file_write); return 1;
- case '?': print_op('?', file_write); return 1;
- default: print_op('n', file_write); return 1;
-
- }
-}
-
-const int number(char *line, int *count, FILE* file_write){
-
-}
-
-int main (void) {
-
- FILE *file_read;
- FILE *file_write;
-
- file_read = fopen("example_code.c", "r");
- file_write = fopen("output", "w");
-
- char *line = NULL;
- size_t len = 0;
- ssize_t nread;
- printf("------------------------------\n\tWRITING\n------------------------------\n");
- while((nread = getline(&line, &len, file_read)) != -1) {
- int counter = 0;
- while(*(line + counter) != 0 ) {
- if(*(line+counter) == '\n') {
- print_op('\n', file_write);
- }
- if(single_char(line, &counter, file_write)) {
- counter++;
- continue;
- }
- if(number(line, &counter, file_write)) {
- continue;
- }
-
-
-
- }
- }
-
-
-}
diff --git a/homework/81248/clex/src/Clex/Lex.hs b/homework/81248/clex/src/Clex/Lex.hs
deleted file mode 100644
index ae78c5d..0000000
--- a/homework/81248/clex/src/Clex/Lex.hs
+++ /dev/null
@@ -1,181 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-
-module Clex.Lex
- ( lexC
- ) where
-
-
-import Prelude hiding (takeWhile)
-
-import Data.Foldable (asum)
-import Data.Word8 ( Word8, isHexDigit, isOctDigit, isAlpha
- , _e, _E, _x, _X,_f, _F, _u, _U, _l, _L, _0
- , _plus, _hyphen, _underscore, _quotesingle
- , _quotedbl, _backslash, _period)
-
-import Data.Attoparsec.ByteString
-import Data.Attoparsec.ByteString.Char8 (isDigit_w8, isSpace_w8)
-
-import Data.ByteString (ByteString)
-import qualified Data.ByteString as BS
-
-import Control.Applicative ((<|>))
-
-import Clex.Types
-
-
-lexC :: ByteString -> Either String [Token]
-lexC = parseOnly (cParser <* endOfInput)
-
-cParser :: Parser [Token]
-cParser = many' tokenParser
-
--- Order is important! For example we need to first check for a floating point number
--- with a leading digit, instead of one without, because the second one will always match the first one.
-tokenParser :: Parser Token
-tokenParser = asum $ concat
- [ [whitespaceParser]
- , [ scientificParser, leadingDotParser, dotFloatParser
- , hexNumParser, octNumParser, numParser, charParser, stringParser
- ]
- , map keywordParser allKeyWords
- , map operParser allOpers
- , [identifierParser]]
-
-whitespaceParser :: Parser Token
-whitespaceParser = Whitespace <$> takeWhile1 isSpace_w8
-
-keywordParser :: ByteString -> Parser Token
-keywordParser kw = do
- parsed <- recognize <$> string kw
- -- we need to check if we still have more letters after the keyword
- next <- peekWord8
- let parsed' = pure parsed
- case next of
- Nothing -> parsed'
- (Just x) -> if (not . isAlpha) x then parsed'
- else fail "more input after keyword"
-
-operParser :: ByteString -> Parser Token
-operParser = (recognize <$>) . string
-
-isDigit :: Word8 -> Bool
-isDigit = isDigit_w8
-
-isLetter :: Word8 -> Bool
-isLetter b = isAlpha b
- || b == _underscore
-
-exponentParser :: Parser ByteString
-exponentParser = do
- e <- satisfy (\c -> c == _E || c == _e)
- sign <- option "" plusMinus
- digits <- takeWhile1 isDigit_w8
- pure $ BS.singleton e <> sign <> digits
- where
- plusMinus = BS.singleton <$> satisfy (\c -> c == _plus || c == _hyphen) -- plus or minus
-
-float :: Parser Word8
-float = satisfy $
- \c -> c == _F
- || c == _f
- || c == _L
- || c == _l
-
-unsigned :: Parser ByteString
-unsigned = BS.pack <$> many' (satisfy $
- \c -> c == _U
- || c == _u
- || c == _L
- || c == _l)
-
-isxX :: Word8 -> Bool
-isxX c = c == _X
- || c == _x
-
-singleQuote :: Parser Word8
-singleQuote = word8 _quotesingle
-
-doubleQuote :: Parser Word8
-doubleQuote = word8 _quotedbl
-
-charParser :: Parser Token
-charParser = do
- l <- option "" (BS.singleton <$> word8 _L)
- _ <- singleQuote
- str <- BS.concat <$> many1' ((BS.snoc <$> string "\\" <*> anyWord8) <|> notInWeirdClass)
- sq <- singleQuote
-
- pure $ CharLit ((l <> (sq `BS.cons` str)) `BS.snoc` sq)
- where
- notInWeirdClass = BS.singleton <$>
- satisfy (\c -> c /= _backslash
- && c /= _quotesingle)
-
-stringParser :: Parser Token
-stringParser = do
- l <- option "" (BS.singleton <$> word8 _L)
- _ <- doubleQuote
- str <- BS.concat <$> many' ((BS.snoc <$> string "\\" <*> anyWord8) <|> notInWeirdClass)
- dq <- doubleQuote
-
- pure $ StringLit ((l <> (dq `BS.cons` str)) `BS.snoc` dq)
- where
- notInWeirdClass = BS.singleton <$>
- satisfy (\c -> c /= _backslash
- && c /= _quotedbl)
-
-zero :: Parser Word8
-zero = word8 _0
-
-hexNumParser :: Parser Token
-hexNumParser = do
- z <- zero
- x <- satisfy isxX
- hex <- takeWhile1 isHexDigit
- f <- unsigned
-
- pure $ HexNumber (z `BS.cons` x `BS.cons` hex <> f)
-
-octNumParser :: Parser Token
-octNumParser = do
- z <- zero
- oct <- takeWhile1 isOctDigit
- f <- unsigned
-
- pure $ OctNumber (z `BS.cons` oct <> f)
-
-numParser :: Parser Token
-numParser = do
- num <- takeWhile1 isDigit
- f <- unsigned
-
- pure $ Number (num <> f)
-
-scientificParser :: Parser Token
-scientificParser = do
- digits <- takeWhile1 isDigit
- expon <- exponentParser
- f <- option "" (BS.singleton <$> float)
- pure $ Scientific $ digits <> expon <> f
-
-dotFloatParser :: Parser Token
-dotFloatParser = do
- leadingDigits <- takeWhile isDigit
- d <- BS.singleton <$> word8 _period
- afterDigits <- takeWhile1 isDigit
- expon <- option "" exponentParser
- f <- option "" (BS.singleton <$> float)
- pure $ DotFloat $ leadingDigits <> d <> afterDigits <> expon <> f
-
-leadingDotParser :: Parser Token
-leadingDotParser = do
- leadingDigits <- takeWhile1 isDigit
- d <- BS.singleton <$> word8 _period
- afterDigits <- takeWhile isDigit
- expon <- option "" exponentParser
- f <- option "" (BS.singleton <$> float)
- pure $ LeadingDot $ leadingDigits <> d <> afterDigits <> expon <> f
-
-identifierParser :: Parser Token
-identifierParser = Identifier <$> takeWhile1 isLetter
diff --git a/homework/81248/clex/src/Clex/Types.hs b/homework/81248/clex/src/Clex/Types.hs
deleted file mode 100644
index 9083514..0000000
--- a/homework/81248/clex/src/Clex/Types.hs
+++ /dev/null
@@ -1,377 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-
-module Clex.Types
- ( Token(..)
- , allKeyWords
- , allOpers
- , recognize
- , tokenToBS
- , tokensToBS
- ) where
-
-import Data.ByteString (ByteString)
-import qualified Data.ByteString as BS
-
-data Token =
- Whitespace ByteString
- | Auto
- | Break
- | Case
- | Char
- | Const
- | Continue
- | Default
- | Do
- | Double
- | Else
- | Enum
- | Extern
- | Float
- | For
- | Goto
- | If
- | Int
- | Long
- | Register
- | Return
- | Short
- | Signed
- | Sizeof
- | Static
- | Struct
- | Switch
- | Typedef
- | Union
- | Unsigned
- | Void
- | Volatile
- | While
- | Ellipsis
- | RightShiftAssign
- | LeftShiftAssign
- | AddAssign
- | SubAssign
- | MulAssign
- | DivAssign
- | ModAssign
- | AndAssign
- | XorAssign
- | OrAssign
- | Incr
- | Decr
- | Ptr
- | Dot
- | And
- | Or
- | Not
- | LtEq
- | GtEq
- | Eq
- | NEq
- | Lt
- | Gt
- | Semicolon
- | LeftCurly
- | RightCurly
- | Comma
- | Colon
- | Assign
- | LeftBracket
- | RightBracket
- | LeftSquare
- | RightSquare
- | RightShift
- | LeftShift
- | BitAnd
- | BitOr
- | BitNot
- | Sub
- | Add
- | Mul
- | Div
- | Mod
- | Xor
- | Ternary
- | HexNumber ByteString
- | OctNumber ByteString
- | Number ByteString
- | CharLit ByteString
- | Scientific ByteString
- | DotFloat ByteString
- | LeadingDot ByteString
- | StringLit ByteString
- | Identifier ByteString
- deriving (Show, Eq)
-
--- Mapping from ByteStrings to Tokens
-recognize :: ByteString -> Token
--- keywords
-recognize "auto" = Auto
-recognize "break" = Break
-recognize "case" = Case
-recognize "char" = Char
-recognize "const" = Const
-recognize "continue" = Continue
-recognize "default" = Default
-recognize "do" = Do
-recognize "double" = Double
-recognize "else" = Else
-recognize "enum" = Enum
-recognize "extern" = Extern
-recognize "float" = Float
-recognize "for" = For
-recognize "goto" = Goto
-recognize "if" = If
-recognize "int" = Int
-recognize "long" = Long
-recognize "register" = Register
-recognize "return" = Return
-recognize "short" = Short
-recognize "signed" = Signed
-recognize "sizeof" = Sizeof
-recognize "static" = Static
-recognize "struct" = Struct
-recognize "switch" = Switch
-recognize "typedef" = Typedef
-recognize "union" = Union
-recognize "unsigned" = Unsigned
-recognize "void" = Void
-recognize "volatile" = Volatile
-recognize "while" = While
-
--- operators
---
--- two-byte
-recognize "..." = Ellipsis
-recognize ">>=" = RightShiftAssign
-recognize "<<=" = LeftShiftAssign
-recognize "+=" = AddAssign
-recognize "-=" = SubAssign
-recognize "*=" = MulAssign
-recognize "/=" = DivAssign
-recognize "%=" = ModAssign
-recognize "&=" = AndAssign
-recognize "^=" = XorAssign
-recognize "|=" = OrAssign
-recognize "++" = Incr
-recognize "--" = Decr
-recognize "->" = Ptr
-recognize "&&" = And
-recognize "||" = Or
-recognize "<=" = LtEq
-recognize ">=" = GtEq
-recognize "==" = Eq
-recognize "!=" = NEq
-recognize ">>" = RightShift
-recognize "<<" = LeftShift
-
--- one-byte
-recognize "." = Dot
-recognize "<" = Lt
-recognize ">" = Gt
-recognize "&" = BitAnd
-recognize "|" = BitOr
-recognize "~" = BitNot
-recognize "!" = Not
-recognize ";" = Semicolon
-recognize "{" = LeftCurly
-recognize "}" = RightCurly
-recognize "," = Comma
-recognize ":" = Colon
-recognize "=" = Assign
-recognize "(" = LeftBracket
-recognize ")" = RightBracket
-recognize "[" = LeftSquare
-recognize "]" = RightSquare
-recognize "-" = Sub
-recognize "+" = Add
-recognize "*" = Mul
-recognize "/" = Div
-recognize "%" = Mod
-recognize "^" = Xor
-recognize "?" = Ternary
-
--- if all else fails an identifier
-recognize x = Identifier x
-
-allKeyWords :: [ByteString]
-allKeyWords =
- [ "auto"
- , "break"
- , "case"
- , "char"
- , "const"
- , "continue"
- , "default"
- , "do"
- , "double"
- , "else"
- , "enum"
- , "extern"
- , "float"
- , "for"
- , "goto"
- , "if"
- , "int"
- , "long"
- , "register"
- , "return"
- , "short"
- , "signed"
- , "sizeof"
- , "static"
- , "struct"
- , "switch"
- , "typedef"
- , "union"
- , "unsigned"
- , "void"
- , "volatile"
- , "while"
- ]
-
--- Opers need to be seperate because they have different rules
--- for formation. For example you can have @"()()()"@, but you can't
--- have @"constconstconst"@.
-allOpers :: [ByteString]
-allOpers =
- [ "..."
- , ">>="
- , "<<="
- , "+="
- , "-="
- , "*="
- , "/="
- , "%="
- , "&="
- , "^="
- , "|="
- , "++"
- , "--"
- , "->"
- , "&&"
- , "||"
- , "<="
- , ">="
- , "=="
- , "!="
- , ">>"
- , "<<"
- , "."
- , "<"
- , ">"
- , "&"
- , "|"
- , "~"
- , "!"
- , ";"
- , "{"
- , "}"
- , ","
- , ":"
- , "="
- , "("
- , ")"
- , "["
- , "]"
- , "-"
- , "+"
- , "*"
- , "/"
- , "%"
- , "^"
- , "?"
- ]
-
-tokensToBS :: [Token] -> ByteString
-tokensToBS = BS.concat . map tokenToBS
-
-tokenToBS :: Token -> ByteString
-tokenToBS (Whitespace bs) = bs
-tokenToBS Auto = "auto"
-tokenToBS Break = "break"
-tokenToBS Case = "case"
-tokenToBS Char = "char"
-tokenToBS Const = "const"
-tokenToBS Continue = "continue"
-tokenToBS Default = "default"
-tokenToBS Do = "do"
-tokenToBS Double = "double"
-tokenToBS Else = "else"
-tokenToBS Enum = "enum"
-tokenToBS Extern = "extern"
-tokenToBS Float = "float"
-tokenToBS For = "for"
-tokenToBS Goto = "goto"
-tokenToBS If = "if"
-tokenToBS Int = "int"
-tokenToBS Long = "long"
-tokenToBS Register = "register"
-tokenToBS Return = "return"
-tokenToBS Short = "short"
-tokenToBS Signed = "signed"
-tokenToBS Sizeof = "sizeof"
-tokenToBS Static = "static"
-tokenToBS Struct = "struct"
-tokenToBS Switch = "switch"
-tokenToBS Typedef = "typedef"
-tokenToBS Union = "union"
-tokenToBS Unsigned = "unsigned"
-tokenToBS Void = "void"
-tokenToBS Volatile = "volatile"
-tokenToBS While = "while"
-tokenToBS Ellipsis = "..."
-tokenToBS RightShiftAssign = ">>="
-tokenToBS LeftShiftAssign = "<<="
-tokenToBS AddAssign = "+="
-tokenToBS SubAssign = "-="
-tokenToBS MulAssign = "*="
-tokenToBS DivAssign = "/="
-tokenToBS ModAssign = "%="
-tokenToBS AndAssign = "&="
-tokenToBS XorAssign = "^="
-tokenToBS OrAssign = "|="
-tokenToBS Incr = "++"
-tokenToBS Decr = "--"
-tokenToBS Ptr = "->"
-tokenToBS Dot = "."
-tokenToBS And = "&&"
-tokenToBS Or = "||"
-tokenToBS Not = "!"
-tokenToBS LtEq = "<="
-tokenToBS GtEq = ">="
-tokenToBS Eq = "=="
-tokenToBS NEq = "!="
-tokenToBS Lt = "<"
-tokenToBS Gt = ">"
-tokenToBS Semicolon = ";"
-tokenToBS LeftCurly = "{"
-tokenToBS RightCurly = "}"
-tokenToBS Comma = ","
-tokenToBS Colon = ":"
-tokenToBS Assign = "="
-tokenToBS LeftBracket = "("
-tokenToBS RightBracket = ")"
-tokenToBS LeftSquare = "["
-tokenToBS RightSquare = "]"
-tokenToBS RightShift = ">>"
-tokenToBS LeftShift = "<<"
-tokenToBS BitAnd = "&"
-tokenToBS BitOr = "|"
-tokenToBS BitNot = "~"
-tokenToBS Sub = "-"
-tokenToBS Add = "+"
-tokenToBS Mul = "*"
-tokenToBS Div = "/"
-tokenToBS Mod = "%"
-tokenToBS Xor = "^"
-tokenToBS Ternary = "?"
-tokenToBS (HexNumber bs) = bs
-tokenToBS (OctNumber bs) = bs
-tokenToBS (Number bs) = bs
-tokenToBS (CharLit bs) = bs
-tokenToBS (Scientific bs) = bs
-tokenToBS (DotFloat bs) = bs
-tokenToBS (LeadingDot bs) = bs
-tokenToBS (StringLit bs) = bs
-tokenToBS (Identifier bs) = bs
diff --git a/homework/81248/clex/stack.yaml b/homework/81248/clex/stack.yaml
deleted file mode 100644
index 5512547..0000000
--- a/homework/81248/clex/stack.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-resolver: lts-12.13
-
-packages:
-- .
-
-extra-deps:
-- bytestring-arbitrary-0.1.2
diff --git a/homework/81248/clex/test/Clex/LexSpec.hs b/homework/81248/clex/test/Clex/LexSpec.hs
deleted file mode 100644
index c5fec81..0000000
--- a/homework/81248/clex/test/Clex/LexSpec.hs
+++ /dev/null
@@ -1,58 +0,0 @@
-module Clex.LexSpec
- ( spec
- ) where
-
-import qualified Data.ByteString as BS
-import Data.ByteString (ByteString)
-import Data.ByteString.Char8 (pack)
-
-import Clex.Types
-import Clex.Lex (lexC)
-
-import Test.QuickCheck
-import Test.Hspec
-import Test.Hspec.QuickCheck
-import Clex.TypesSpec ()
-
-spec :: Spec
-spec = describe "lexing" $ do
- prop "tokensToBS after lexC is id" $
- \x -> let x' = unValidC x in
- case lexC x' of
- (Left _) -> False
- (Right x'') -> x' == tokensToBS x''
- prop "lexing after tokensToBS is id" $
- \x -> let x' = unTokenC x in
- case lexC $ tokensToBS x' of
- (Left _) -> False
- (Right x'') -> x' == x''
-
-newtype TokenC = TokenC {unTokenC :: [Token]}
- deriving (Eq, Show)
-
-newtype ValidC = ValidC {unValidC :: ByteString}
- deriving (Eq, Show)
-
-instance Arbitrary TokenC where
- arbitrary = TokenC . packWhitespaceTokens . concat <$>
- listOf1 (do
- x <- arbitrary
- whitespace <- whitespaceGen
- pure [x, whitespace])
- where
- whitespaceGen = Whitespace . pack <$> do listOf1 $ elements ['\t', ' ', '\n']
-
-instance Arbitrary ValidC where
- arbitrary = ValidC . BS.concat . map tokenToBS <$> listOf1 (frequency
- [ (30, arbitrary)
- , (60, whitespaceGen)
- ])
- where
- whitespaceGen = Whitespace . pack <$> do listOf1 $ elements ['\t', ' ', '\n']
-
-packWhitespaceTokens :: [Token] -> [Token]
-packWhitespaceTokens [] = []
-packWhitespaceTokens [x] = [x]
-packWhitespaceTokens (Whitespace x : Whitespace y : xs)
- = packWhitespaceTokens $ Whitespace (x <> y) : xs
-packWhitespaceTokens (x:xs) = x : packWhitespaceTokens xs
diff --git a/homework/81248/clex/test/Clex/TypesSpec.hs b/homework/81248/clex/test/Clex/TypesSpec.hs
deleted file mode 100644
index 805affc..0000000
--- a/homework/81248/clex/test/Clex/TypesSpec.hs
+++ /dev/null
@@ -1,177 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-{-# OPTIONS -fno-warn-orphans #-}
-
-module Clex.TypesSpec
- ( spec
- ) where
-
-import Data.ByteString.Char8 (pack)
-
-import Clex.Types
-
-import Test.QuickCheck
-import Test.Hspec
-import Test.Hspec.QuickCheck
-import Data.ByteString.Arbitrary
-
-spec :: Spec
-spec = describe "types"
- conversionSpec
-
-conversionSpec :: Spec
-conversionSpec = describe "ByteString conversions" $ do
- prop "recognize is inverse to tokenToBS" $
- \x -> (not . isLiteral) x ==> x == recognize (tokenToBS x)
- prop "tokenToBS is inverse to recognize" $
- \x -> let x' = fromABS x in x' == tokenToBS (recognize x')
-
-isLiteral :: Token -> Bool
-isLiteral (HexNumber _) = True
-isLiteral (OctNumber _) = True
-isLiteral (Number _) = True
-isLiteral (CharLit _) = True
-isLiteral (Scientific _) = True
-isLiteral (DotFloat _) = True
-isLiteral (LeadingDot _) = True
-isLiteral (StringLit _) = True
-isLiteral _ = False
-
-instance Arbitrary Token where
- arbitrary = frequency
- [ (30, nullaryGen)
- , (30, identifierGen)
- , (10, literalGen)
- ]
- where
- nullaryGen = elements
- [ Auto
- , Break
- , Case
- , Char
- , Const
- , Continue
- , Default
- , Do
- , Double
- , Else
- , Enum
- , Extern
- , Float
- , For
- , Goto
- , If
- , Int
- , Long
- , Register
- , Return
- , Short
- , Signed
- , Sizeof
- , Static
- , Struct
- , Switch
- , Typedef
- , Union
- , Unsigned
- , Void
- , Volatile
- , While
- , Ellipsis
- , RightShiftAssign
- , LeftShiftAssign
- , AddAssign
- , SubAssign
- , MulAssign
- , DivAssign
- , ModAssign
- , AndAssign
- , XorAssign
- , OrAssign
- , Incr
- , Decr
- , Ptr
- , Dot
- , And
- , Or
- , Not
- , LtEq
- , GtEq
- , Eq
- , NEq
- , Lt
- , Gt
- , Semicolon
- , LeftCurly
- , RightCurly
- , Comma
- , Colon
- , Assign
- , LeftBracket
- , RightBracket
- , LeftSquare
- , RightSquare
- , RightShift
- , LeftShift
- , BitAnd
- , BitOr
- , BitNot
- , Sub
- , Add
- , Mul
- , Div
- , Mod
- , Xor
- , Ternary
- ]
- identifierGen = Identifier <$> (pack <$> do listOf1 $ elements $ '_' : ['a'..'z'] ++ ['A'..'Z'])
- `suchThat` (not . reserved)
- reserved = (`elem` allKeyWords)
- -- don't feel like overdoing this right now
- literalGen = oneof
- [ elements
- [ HexNumber "0xb23abcf4"
- , HexNumber "0x123ab5f4ul"
- , HexNumber "0X123a4cf4"
- , HexNumber "0x1e3ebcf4lull"
-
- , OctNumber "0234"
- , OctNumber "012354ul"
- , OctNumber "012744"
- , OctNumber "0134lull"
-
- , Number "234"
- , Number "12354ul"
- , Number "12744"
- , Number "134lull"
- ]
- , elements
- [ CharLit "'c'"
- , CharLit "L'c'"
- , CharLit "'\n'"
- , CharLit "'\t'"
- , CharLit "'a'"
- ]
- , elements
- [ DotFloat ".213E+10f"
- , DotFloat ".213e-10"
- , DotFloat ".213e-10l"
- , DotFloat ".213e10l"
- , DotFloat ".213l"
- , DotFloat ".213"
- , DotFloat ".213e9L"
-
- , LeadingDot "213.2E+10f"
- , LeadingDot "213.3e-10"
- , LeadingDot "213.e-10l"
- , LeadingDot "213.e10l"
- , LeadingDot "213.e9L"
- , LeadingDot "213.9L"
- , LeadingDot "213.L"
- ]
- , elements
- [ StringLit "\"\""
- , StringLit "L\"asdfwqe\""
- , StringLit "\"asd\nfw\tqe\""
- , StringLit "L\"\""
- ]
- ]
diff --git a/homework/81248/clex/test/Spec.hs b/homework/81248/clex/test/Spec.hs
deleted file mode 100644
index a824f8c..0000000
--- a/homework/81248/clex/test/Spec.hs
+++ /dev/null
@@ -1 +0,0 @@
-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}