This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/facebook/lex-pass
- Loading branch information
Showing
27 changed files
with
1,749 additions
and
1,337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/src/CodeGen/Transf.hs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,12 @@ | ||
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} | ||
|
||
module Common ( | ||
module Text.ParserCombinators.Parsec, | ||
Oper, Parse(..), Unparse(..)) where | ||
|
||
import Control.Applicative hiding (many, (<|>)) | ||
module Common | ||
( | ||
module Control.Applicative | ||
, module Control.Arrow | ||
, module Control.Monad | ||
, module Text.ParserCombinators.Parsec | ||
) where | ||
|
||
import Control.Applicative hiding ((<|>), many, optional, Const) | ||
import Control.Arrow | ||
import Control.Monad | ||
import Text.ParserCombinators.Parsec hiding (State, parse, choice) | ||
import Text.ParserCombinators.Parsec.Expr | ||
|
||
-- parsec 2 vs 3 stuff | ||
|
||
type Oper a = Operator Char () a | ||
|
||
class Parse a where | ||
parse :: Parser a | ||
|
||
class Unparse a where | ||
unparse :: a -> String | ||
|
||
instance (Parse a) => Parse [a] where | ||
parse = many parse | ||
|
||
instance (Parse a, Parse b) => Parse (Either a b) where | ||
parse = Left <$> parse <|> Right <$> parse | ||
|
||
instance (Unparse a, Unparse b) => Unparse (Either a b) where | ||
unparse (Left a) = unparse a | ||
unparse (Right a) = unparse a | ||
|
||
instance (Unparse a, Unparse b) => Unparse (a, b) where | ||
unparse (a, b) = unparse a ++ unparse b | ||
|
||
instance (Unparse a) => Unparse [a] where | ||
unparse = concatMap unparse | ||
|
||
instance (Unparse a) => Unparse (Maybe a) where | ||
unparse = maybe "" unparse | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{-# LANGUAGE DeriveDataTypeable #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
|
||
module Data.List.NonEmpty where | ||
|
||
import Data.Binary | ||
import Data.Data | ||
import qualified Data.List as L | ||
import Text.PrettyPrint.GenericPretty | ||
|
||
-- | A non-empty list | ||
data NonEmpty a = NonEmpty | ||
{ head :: a | ||
, tail :: [a] | ||
} deriving (Data, Eq, Generic, Show, Typeable) | ||
|
||
toList :: NonEmpty a -> [a] | ||
toList (NonEmpty x xs) = x:xs | ||
|
||
fromList :: [a] -> Maybe (NonEmpty a) | ||
fromList [] = Nothing | ||
fromList (x:xs) = Just $ NonEmpty x xs | ||
|
||
length :: NonEmpty a -> Int | ||
length = L.length . toList | ||
|
||
instance (Out a) => Out (NonEmpty a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.