-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from piknotech/frontend
Create Frontend package
- Loading branch information
Showing
25 changed files
with
214 additions
and
140 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
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,4 +1,5 @@ | ||
packages: | ||
packages/frontend | ||
packages/grammar | ||
packages/tabular | ||
./ |
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 @@ | ||
../../LICENSE |
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,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
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,81 @@ | ||
name: happy-frontend | ||
version: 1.21.0 | ||
license: BSD2 | ||
license-file: LICENSE | ||
copyright: (c) Andy Gill, Simon Marlow | ||
author: Andy Gill and Simon Marlow | ||
maintainer: Simon Marlow <[email protected]> | ||
bug-reports: https://github.com/simonmar/happy/issues | ||
stability: stable | ||
homepage: https://www.haskell.org/happy/ | ||
category: Development | ||
cabal-version: >= 1.10 | ||
build-type: Simple | ||
synopsis: A yacc-like frontend for happy | ||
|
||
Description: | ||
Happy is a parser generator for Haskell. | ||
Happy-Frontend is responsible for parsing .y- and .ly-files | ||
and mangling them into a Grammar datatype. | ||
These .y- and .ly-files work similar to yacc's .y-files, but | ||
have some Haskell-specific features. | ||
|
||
tested-with: | ||
GHC == 7.0.4 | ||
GHC == 7.4.2 | ||
GHC == 7.6.3 | ||
GHC == 7.8.4 | ||
GHC == 7.10.3 | ||
GHC == 8.0.2 | ||
GHC == 8.2.2 | ||
GHC == 8.4.4 | ||
GHC == 8.6.5 | ||
GHC == 8.8.4 | ||
GHC == 8.10.4 | ||
GHC == 9.0.1 | ||
|
||
flag bootstrap | ||
description: Optimize the implementation of happy using a pre-built happy | ||
manual: True | ||
default: True | ||
|
||
library | ||
hs-source-dirs: src | ||
exposed-modules: Happy.Frontend, | ||
Happy.Frontend.AbsSyn, | ||
Happy.Frontend.Mangler, | ||
Happy.Frontend.PrettyGrammar | ||
|
||
build-depends: base < 5, | ||
array, | ||
containers >= 0.4.2, | ||
transformers >= 0.5.6.2, | ||
mtl >= 2.2.2, | ||
happy-grammar == 1.21.0 | ||
|
||
default-language: Haskell98 | ||
default-extensions: CPP, MagicHash, FlexibleContexts | ||
ghc-options: -Wall | ||
other-modules: | ||
Happy.Frontend.ParseMonad | ||
Happy.Frontend.ParseMonad.Class | ||
Happy.Frontend.AttrGrammar | ||
Happy.Frontend.Parser | ||
Happy.Frontend.Lexer | ||
Happy.Frontend.ParamRules | ||
|
||
|
||
if flag(bootstrap) | ||
-- TODO put this back when Cabal can use it's qualified goals to better | ||
-- understand bootstrapping, see | ||
-- https://github.com/haskell/cabal/issues/7189 | ||
--build-tools: happy | ||
cpp-options: -DHAPPY_BOOTSTRAP | ||
other-modules: | ||
Happy.Frontend.ParseMonad.Bootstrapped | ||
Happy.Frontend.Parser.Bootstrapped | ||
Happy.Frontend.AttrGrammar.Parser | ||
else | ||
other-modules: | ||
Happy.Frontend.ParseMonad.Oracle | ||
Happy.Frontend.Parser.Oracle |
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,40 @@ | ||
module Happy.Frontend where | ||
|
||
import Happy.Frontend.AbsSyn | ||
import Happy.Frontend.Parser | ||
import Happy.Frontend.ParseMonad.Class | ||
|
||
parseYFileContents :: String -> ParseResult AbsSyn | ||
parseYFileContents contents = runFromStartP ourParser contents 1 | ||
|
||
data FileType = Y | LY | ||
|
||
fileNameAndType :: String -> Maybe (String, FileType) | ||
fileNameAndType = nameType . reverse where | ||
nameType ('y':'.':f) = Just (reverse f, Y) | ||
nameType ('y':'l':'.':f) = Just (reverse f, LY) | ||
nameType _ = Nothing | ||
|
||
-- Delit, converting an ly file into a y file. | ||
deLitify :: String -> String | ||
deLitify = deLit where | ||
deLit ('>':' ':r) = deLit1 r | ||
deLit ('>':'\t':r) = '\t' : deLit1 r | ||
deLit ('>':'\n':r) = deLit r | ||
deLit ('>':_) = error "Error when de-litify-ing" | ||
deLit ('\n':r) = '\n' : deLit r | ||
deLit r = deLit2 r | ||
deLit1 ('\n':r) = '\n' : deLit r | ||
deLit1 (c:r) = c : deLit1 r | ||
deLit1 [] = [] | ||
deLit2 ('\n':r) = '\n' : deLit r | ||
deLit2 (_:r) = deLit2 r | ||
deLit2 [] = [] | ||
|
||
-- Iff happy is built with bootstrapping, attribute grammars are supported | ||
supportsParsingAttributeGrammars :: Bool | ||
#ifdef HAPPY_BOOTSTRAP | ||
supportsParsingAttributeGrammars = True | ||
#else | ||
supportsParsingAttributeGrammars = False | ||
#endif |
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
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
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
4 changes: 2 additions & 2 deletions
4
src/ParamRules.hs → ...frontend/src/Happy/Frontend/ParamRules.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Happy.Frontend.ParseMonad (module X) where | ||
|
||
-- We use the bootstrapped version if it is available | ||
#ifdef HAPPY_BOOTSTRAP | ||
import Happy.Frontend.ParseMonad.Bootstrapped as X | ||
#else | ||
import Happy.Frontend.ParseMonad.Oracle as X | ||
#endif |
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.