-
Notifications
You must be signed in to change notification settings - Fork 51
Add Text.Parsing.Parser.Language and Token modules. #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4187411
Add Text.Parsing.Parser.Language and Token modules.
cdepillabout 115989c
Make exports explicit.
cdepillabout 072ef28
Change documentation to be Markdown.
cdepillabout 930e594
Added parsec's license to the LICENSE file.
cdepillabout 6c2745c
Add simple tests for haskellStyle and javaStyle LanguageDefs.
cdepillabout cc562ab
In bower.json, change purescript-unicode dependency to actual version…
cdepillabout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,125 @@ | ||
|
||
module Text.Parsing.Parser.Language | ||
-- ( haskellDef, haskell | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have explicit exports. |
||
-- , mondrianDef, mondrian | ||
-- , emptyDef | ||
-- , haskellStyle | ||
-- , javaStyle | ||
-- ) | ||
where | ||
|
||
import Prelude | ||
|
||
import Control.Alt | ||
|
||
import Text.Parsing.Parser | ||
import Text.Parsing.Parser.String | ||
import Text.Parsing.Parser.Token | ||
|
||
----------------------------------------------------------- | ||
-- Styles: haskellStyle, javaStyle | ||
----------------------------------------------------------- | ||
|
||
-- | This is a minimal token definition for Haskell style languages. It | ||
-- defines the style of comments, valid identifiers and case | ||
-- sensitivity. It does not define any reserved words or operators. | ||
|
||
haskellStyle :: LanguageDef | ||
haskellStyle = LanguageDef (unGenLanguageDef emptyDef) | ||
{ commentStart = "{-" | ||
, commentEnd = "-}" | ||
, commentLine = "--" | ||
, nestedComments = true | ||
, identStart = letter | ||
, identLetter = alphaNum <|> oneOf ['_', '\''] | ||
, opStart = op' | ||
, opLetter = op' | ||
, reservedOpNames = [] | ||
, reservedNames = [] | ||
, caseSensitive = true | ||
} | ||
where | ||
op' :: forall m . (Monad m) => ParserT String m Char | ||
op' = oneOf [':', '!', '#', '$', '%', '&', '*', '+', '.', '/', '<', '=', '>', '?', '@', '\\', '^', '|', '-', '~'] | ||
|
||
-- | This is a minimal token definition for Java style languages. It | ||
-- defines the style of comments, valid identifiers and case | ||
-- sensitivity. It does not define any reserved words or operators. | ||
|
||
javaStyle :: LanguageDef | ||
javaStyle = LanguageDef (unGenLanguageDef emptyDef) | ||
{ commentStart = "/*" | ||
, commentEnd = "*/" | ||
, commentLine = "//" | ||
, nestedComments = true | ||
, identStart = letter | ||
, identLetter = alphaNum <|> oneOf ['_', '\''] | ||
, reservedNames = [] | ||
, reservedOpNames = [] | ||
, caseSensitive = false | ||
} | ||
|
||
----------------------------------------------------------- | ||
-- minimal language definition | ||
-------------------------------------------------------- | ||
|
||
-- | This is the most minimal token definition. It is recommended to use | ||
-- this definition as the basis for other definitions. `emptyDef` has | ||
-- no reserved names or operators, is case sensitive and doesn't accept | ||
-- comments, identifiers or operators. | ||
|
||
emptyDef :: LanguageDef | ||
emptyDef = LanguageDef | ||
{ commentStart: "" | ||
, commentEnd: "" | ||
, commentLine: "" | ||
, nestedComments: true | ||
, identStart: letter <|> char '_' | ||
, identLetter: alphaNum <|> oneOf ['_', '\''] | ||
, opStart: op' | ||
, opLetter: op' | ||
, reservedOpNames: [] | ||
, reservedNames: [] | ||
, caseSensitive: true | ||
} | ||
where | ||
op' :: forall m . (Monad m) => ParserT String m Char | ||
op' = oneOf [':', '!', '#', '$', '%', '&', '*', '+', '.', '/', '<', '=', '>', '?', '@', '\\', '^', '|', '-', '~'] | ||
|
||
-- ----------------------------------------------------------- | ||
-- -- Haskell | ||
-- ----------------------------------------------------------- | ||
|
||
-- -- | A lexer for the haskell language. | ||
|
||
haskell :: TokenParser | ||
haskell = makeTokenParser haskellDef | ||
|
||
-- -- | The language definition for the Haskell language. | ||
|
||
haskellDef :: LanguageDef | ||
haskellDef = | ||
case haskell98Def of | ||
(LanguageDef def) -> LanguageDef def | ||
{ identLetter = def.identLetter <|> char '#' | ||
, reservedNames = def.reservedNames <> | ||
["foreign","import","export","primitive" | ||
,"_ccall_","_casm_" | ||
,"forall" | ||
] | ||
} | ||
|
||
-- -- | The language definition for the language Haskell98. | ||
|
||
haskell98Def :: LanguageDef | ||
haskell98Def = LanguageDef (unGenLanguageDef haskellStyle) | ||
{ reservedOpNames = ["::","..","=","\\","|","<-","->","@","~","=>"] | ||
, reservedNames = [ "let","in","case","of","if","then","else" | ||
, "data","type" | ||
, "class","default","deriving","do","import" | ||
, "infix","infixl","infixr","instance","module" | ||
, "newtype","where" | ||
, "primitive" | ||
-- "as","qualified","hiding" | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should publish this to bower. Never actually commit git dependencies, especially when it's not a SHA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelficarra Thanks for taking a look at this PR.
I am planning to publish purescript-unicode to bower, but I am waiting for this PR to get reviewed.
I don't think I explained it well enough in the PR comments, but this PR shouldn't be merged until purescript-unicode is released. (Or if we decide not to use the purescript-unicode dependency, then it doesn't matter.)