mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-03 19:39:44 +01:00
Haskell highligth test
This commit is contained in:
parent
aebc30447f
commit
9897c99190
86
tests/syntax-tests/highlighted/Haskell/test.hs
Normal file
86
tests/syntax-tests/highlighted/Haskell/test.hs
Normal file
@ -0,0 +1,86 @@
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mLANGUAGE[0m[38;2;190;132;255m OverloadedStrings #-}[0m
|
||||
|
||||
[38;2;117;113;94m--[0m[38;2;117;113;94m simple parser for a Lisp-like syntax I wrote some time ago[0m
|
||||
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mData.Void[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[3;38;2;102;217;239mVoid[0m[38;2;248;248;242m)[0m
|
||||
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mData.Text[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[3;38;2;102;217;239mText[0m[38;2;248;248;242m)[0m
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;249;38;114mqualified[0m[38;2;248;248;242m [0m[38;2;248;248;242mData.Text[0m[38;2;248;248;242m [0m[38;2;249;38;114mas[0m[38;2;248;248;242m [0m[38;2;248;248;242mT[0m
|
||||
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mText.Megaparsec.Char[0m
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mText.Megaparsec.Error[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[38;2;166;226;46merrorBundlePretty[0m[38;2;248;248;242m)[0m
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mText.Megaparsec[0m[38;2;248;248;242m [0m[38;2;249;38;114mhiding[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[3;38;2;102;217;239mState[0m[38;2;248;248;242m)[0m
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;249;38;114mqualified[0m[38;2;248;248;242m [0m[38;2;248;248;242mText.Megaparsec.Char.Lexer[0m[38;2;248;248;242m [0m[38;2;249;38;114mas[0m[38;2;248;248;242m [0m[38;2;248;248;242mL[0m
|
||||
|
||||
[38;2;249;38;114mdata[0m[38;2;248;248;242m [0m[38;2;190;132;255mLispVal[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mSymbol[0m[38;2;248;248;242m [0m[38;2;190;132;255mText[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255mList[0m[38;2;248;248;242m [[0m[38;2;190;132;255mLispVal[0m[38;2;248;248;242m][0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255mNumber[0m[38;2;248;248;242m [0m[38;2;190;132;255mInteger[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255mString[0m[38;2;248;248;242m [0m[38;2;190;132;255mText[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255mLispTrue[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255mLispFalse[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255mNil[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mderiving[0m[38;2;248;248;242m ([0m[3;4;38;2;166;226;46mShow[0m[38;2;248;248;242m, [0m[3;4;38;2;166;226;46mEq[0m[38;2;248;248;242m)[0m
|
||||
|
||||
[38;2;249;38;114mtype[0m[38;2;248;248;242m [0m[38;2;190;132;255mParser[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mParsec[0m[38;2;248;248;242m [0m[38;2;190;132;255mVoid[0m[38;2;248;248;242m [0m[38;2;190;132;255mText[0m
|
||||
|
||||
[38;2;166;226;46mreadStr[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mText[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mEither[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mString[0m[38;2;248;248;242m [[0m[3;38;2;102;217;239mLispVal[0m[38;2;248;248;242m][0m
|
||||
[38;2;248;248;242mreadStr t [0m[38;2;249;38;114m=[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mcase[0m[38;2;248;248;242m parse pLisp [0m[38;2;230;219;116m"[0m[38;2;230;219;116mf[0m[38;2;230;219;116m"[0m[38;2;248;248;242m t [0m[38;2;249;38;114mof[0m
|
||||
[38;2;248;248;242m [0m[38;2;190;132;255mRight[0m[38;2;248;248;242m parsed [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;190;132;255mRight[0m[38;2;248;248;242m parsed[0m
|
||||
[38;2;248;248;242m [0m[38;2;190;132;255mLeft[0m[38;2;248;248;242m err [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;190;132;255mLeft[0m[38;2;248;248;242m [0m[38;2;249;38;114m$[0m[38;2;248;248;242m errorBundlePretty err[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINABLE[0m[38;2;190;132;255m readStr #-}[0m
|
||||
|
||||
[38;2;166;226;46msc[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[38;2;102;217;239m()[0m
|
||||
[38;2;248;248;242msc [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mL[0m[38;2;249;38;114m.[0m[38;2;248;248;242mspace space1 ([0m[38;2;190;132;255mL[0m[38;2;249;38;114m.[0m[38;2;248;248;242mskipLineComment [0m[38;2;230;219;116m"[0m[38;2;230;219;116m;[0m[38;2;230;219;116m"[0m[38;2;248;248;242m) empty[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINABLE[0m[38;2;190;132;255m sc #-}[0m
|
||||
|
||||
[38;2;166;226;46mlexeme[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[38;2;255;255;255ma[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[38;2;255;255;255ma[0m
|
||||
[38;2;248;248;242mlexeme [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mL[0m[38;2;249;38;114m.[0m[38;2;248;248;242mlexeme sc[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m lexeme #-}[0m
|
||||
|
||||
[38;2;166;226;46msymbol[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mText[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mText[0m
|
||||
[38;2;248;248;242msymbol [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mL[0m[38;2;249;38;114m.[0m[38;2;248;248;242msymbol sc[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m symbol #-}[0m
|
||||
|
||||
[38;2;166;226;46msymbol'[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mText[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mText[0m
|
||||
[38;2;248;248;242msymbol' [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mL[0m[38;2;249;38;114m.[0m[38;2;248;248;242msymbol' sc[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m symbol' #-}[0m
|
||||
|
||||
[38;2;166;226;46mpNil[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mLispVal[0m
|
||||
[38;2;248;248;242mpNil [0m[38;2;249;38;114m=[0m[38;2;248;248;242m symbol' [0m[38;2;230;219;116m"[0m[38;2;230;219;116mnil[0m[38;2;230;219;116m"[0m[38;2;248;248;242m [0m[38;2;249;38;114m>>[0m[38;2;248;248;242m return [0m[38;2;190;132;255mNil[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m pNil #-}[0m
|
||||
|
||||
[38;2;166;226;46minteger[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mInteger[0m
|
||||
[38;2;248;248;242minteger [0m[38;2;249;38;114m=[0m[38;2;248;248;242m lexeme [0m[38;2;190;132;255mL[0m[38;2;249;38;114m.[0m[38;2;248;248;242mdecimal[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m integer #-}[0m
|
||||
|
||||
[38;2;166;226;46mlispSymbols[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mChar[0m
|
||||
[38;2;248;248;242mlispSymbols [0m[38;2;249;38;114m=[0m[38;2;248;248;242m oneOf ([0m[38;2;230;219;116m"[0m[38;2;230;219;116m#$%&|*+-/:<=>?@[0m[38;2;190;132;255m^_[0m[38;2;230;219;116m~[0m[38;2;230;219;116m"[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[38;2;190;132;255mString[0m[38;2;248;248;242m)[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m lispSymbols #-}[0m
|
||||
|
||||
[38;2;166;226;46mpLispVal[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mLispVal[0m
|
||||
[38;2;248;248;242mpLispVal [0m[38;2;249;38;114m=[0m[38;2;248;248;242m choice [pList[0m[38;2;248;248;242m,[0m[38;2;248;248;242m pNumber[0m[38;2;248;248;242m,[0m[38;2;248;248;242m pSymbol[0m[38;2;248;248;242m,[0m[38;2;248;248;242m pNil[0m[38;2;248;248;242m,[0m[38;2;248;248;242m pString][0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m pLispVal #-}[0m
|
||||
|
||||
[38;2;166;226;46mpSymbol[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mLispVal[0m
|
||||
[38;2;248;248;242mpSymbol [0m[38;2;249;38;114m=[0m[38;2;248;248;242m ([0m[38;2;190;132;255mSymbol[0m[38;2;248;248;242m [0m[38;2;249;38;114m.[0m[38;2;248;248;242m [0m[38;2;190;132;255mT[0m[38;2;249;38;114m.[0m[38;2;248;248;242mpack [0m[38;2;249;38;114m<$>[0m[38;2;248;248;242m lexeme (some (letterChar [0m[38;2;249;38;114m<|>[0m[38;2;248;248;242m lispSymbols)))[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINABLE[0m[38;2;190;132;255m pSymbol #-}[0m
|
||||
|
||||
[38;2;166;226;46mpList[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mLispVal[0m
|
||||
[38;2;248;248;242mpList [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mList[0m[38;2;248;248;242m [0m[38;2;249;38;114m<$>[0m[38;2;248;248;242m between (symbol [0m[38;2;230;219;116m"[0m[38;2;230;219;116m([0m[38;2;230;219;116m"[0m[38;2;248;248;242m) (symbol [0m[38;2;230;219;116m"[0m[38;2;230;219;116m)[0m[38;2;230;219;116m"[0m[38;2;248;248;242m) (many pLispVal)[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINABLE[0m[38;2;190;132;255m pList #-}[0m
|
||||
|
||||
[38;2;166;226;46mpLisp[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [[0m[3;38;2;102;217;239mLispVal[0m[38;2;248;248;242m][0m
|
||||
[38;2;248;248;242mpLisp [0m[38;2;249;38;114m=[0m[38;2;248;248;242m some pLispVal[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m pLisp #-}[0m
|
||||
|
||||
[38;2;166;226;46mpNumber[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mLispVal[0m
|
||||
[38;2;248;248;242mpNumber [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mNumber[0m[38;2;248;248;242m [0m[38;2;249;38;114m<$>[0m[38;2;248;248;242m integer[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINE[0m[38;2;190;132;255m pNumber #-}[0m
|
||||
|
||||
[38;2;166;226;46mpString[0m[38;2;248;248;242m [0m[38;2;249;38;114m::[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mParser[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mLispVal[0m
|
||||
[38;2;248;248;242mpString [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mdo[0m
|
||||
[38;2;248;248;242m str [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m char [0m[38;2;230;219;116m'[0m[38;2;190;132;255m\"[0m[38;2;230;219;116m'[0m[38;2;248;248;242m *[0m[38;2;249;38;114m>[0m[38;2;248;248;242m manyTill [0m[38;2;190;132;255mL[0m[38;2;249;38;114m.[0m[38;2;248;248;242mcharLiteral (char [0m[38;2;230;219;116m'[0m[38;2;190;132;255m\"[0m[38;2;230;219;116m'[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m return [0m[38;2;249;38;114m$[0m[38;2;248;248;242m [0m[38;2;190;132;255mString[0m[38;2;248;248;242m ([0m[38;2;190;132;255mT[0m[38;2;249;38;114m.[0m[38;2;248;248;242mpack str)[0m
|
||||
[38;2;190;132;255m{-# [0m[38;2;249;38;114mINLINABLE[0m[38;2;190;132;255m pString #-}[0m
|
86
tests/syntax-tests/source/Haskell/test.hs
Normal file
86
tests/syntax-tests/source/Haskell/test.hs
Normal file
@ -0,0 +1,86 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
-- simple parser for a Lisp-like syntax I wrote some time ago
|
||||
|
||||
import Data.Void (Void)
|
||||
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
|
||||
import Text.Megaparsec.Char
|
||||
import Text.Megaparsec.Error (errorBundlePretty)
|
||||
import Text.Megaparsec hiding (State)
|
||||
import qualified Text.Megaparsec.Char.Lexer as L
|
||||
|
||||
data LispVal
|
||||
= Symbol Text
|
||||
| List [LispVal]
|
||||
| Number Integer
|
||||
| String Text
|
||||
| LispTrue
|
||||
| LispFalse
|
||||
| Nil
|
||||
deriving (Show, Eq)
|
||||
|
||||
type Parser = Parsec Void Text
|
||||
|
||||
readStr :: Text -> Either String [LispVal]
|
||||
readStr t =
|
||||
case parse pLisp "f" t of
|
||||
Right parsed -> Right parsed
|
||||
Left err -> Left $ errorBundlePretty err
|
||||
{-# INLINABLE readStr #-}
|
||||
|
||||
sc :: Parser ()
|
||||
sc = L.space space1 (L.skipLineComment ";") empty
|
||||
{-# INLINABLE sc #-}
|
||||
|
||||
lexeme :: Parser a -> Parser a
|
||||
lexeme = L.lexeme sc
|
||||
{-# INLINE lexeme #-}
|
||||
|
||||
symbol :: Text -> Parser Text
|
||||
symbol = L.symbol sc
|
||||
{-# INLINE symbol #-}
|
||||
|
||||
symbol' :: Text -> Parser Text
|
||||
symbol' = L.symbol' sc
|
||||
{-# INLINE symbol' #-}
|
||||
|
||||
pNil :: Parser LispVal
|
||||
pNil = symbol' "nil" >> return Nil
|
||||
{-# INLINE pNil #-}
|
||||
|
||||
integer :: Parser Integer
|
||||
integer = lexeme L.decimal
|
||||
{-# INLINE integer #-}
|
||||
|
||||
lispSymbols :: Parser Char
|
||||
lispSymbols = oneOf ("#$%&|*+-/:<=>?@^_~" :: String)
|
||||
{-# INLINE lispSymbols #-}
|
||||
|
||||
pLispVal :: Parser LispVal
|
||||
pLispVal = choice [pList, pNumber, pSymbol, pNil, pString]
|
||||
{-# INLINE pLispVal #-}
|
||||
|
||||
pSymbol :: Parser LispVal
|
||||
pSymbol = (Symbol . T.pack <$> lexeme (some (letterChar <|> lispSymbols)))
|
||||
{-# INLINABLE pSymbol #-}
|
||||
|
||||
pList :: Parser LispVal
|
||||
pList = List <$> between (symbol "(") (symbol ")") (many pLispVal)
|
||||
{-# INLINABLE pList #-}
|
||||
|
||||
pLisp :: Parser [LispVal]
|
||||
pLisp = some pLispVal
|
||||
{-# INLINE pLisp #-}
|
||||
|
||||
pNumber :: Parser LispVal
|
||||
pNumber = Number <$> integer
|
||||
{-# INLINE pNumber #-}
|
||||
|
||||
pString :: Parser LispVal
|
||||
pString = do
|
||||
str <- char '\"' *> manyTill L.charLiteral (char '\"')
|
||||
return $ String (T.pack str)
|
||||
{-# INLINABLE pString #-}
|
Loading…
Reference in New Issue
Block a user