[commit: ghc] master: Adding more parser exports and some documentation. (00dd05e)

git at git.haskell.org git at git.haskell.org
Sun Jul 20 21:57:59 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/00dd05e44e4a9c7e7ddd7d99fffd1d937eeb26ad/ghc

>---------------------------------------------------------------

commit 00dd05e44e4a9c7e7ddd7d99fffd1d937eeb26ad
Author: Andrew Gibiansky <andrew.gibiansky at gmail.com>
Date:   Fri Jul 18 23:54:26 2014 -0500

    Adding more parser exports and some documentation.
    
    Summary: Add a few exports to be generated by the Happy parser module. Add documentation showing how to use the Happy parser.
    
    Test Plan: Validate
    
    Reviewers: carter, austin
    
    Reviewed By: austin
    
    Subscribers: phaskell, simonmar, relrod, carter
    
    Differential Revision: https://phabricator.haskell.org/D71


>---------------------------------------------------------------

00dd05e44e4a9c7e7ddd7d99fffd1d937eeb26ad
 compiler/parser/Parser.y.pp | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp
index a3c68c3..d592510 100644
--- a/compiler/parser/Parser.y.pp
+++ b/compiler/parser/Parser.y.pp
@@ -16,8 +16,25 @@
 --     http://ghc.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
 -- for details
 
-module Parser ( parseModule, parseStmt, parseIdentifier, parseType,
-                parseHeader ) where
+-- | This module provides the generated Happy parser for Haskell. It exports
+-- a number of parsers which may be used in any library that uses the GHC API.
+-- A common usage pattern is to initialize the parser state with a given string
+-- and then parse that string:
+--
+-- @
+--     runParser :: DynFlags -> String -> P a -> ParseResult a
+--     runParser flags str parser = unP parser parseState
+--     where
+--       filename = "\<interactive\>"
+--       location = mkRealSrcLoc (mkFastString filename) 1 1
+--       buffer = stringToStringBuffer str
+--       parseState = mkPState flags buffer location in
+-- @
+module Parser (parseModule, parseImport, parseStatement,
+               parseDeclaration, parseExpression, parseTypeSignature,
+               parseFullStmt, parseStmt, parseIdentifier,
+               parseType, parseHeader) where
+
 
 import HsSyn
 import RdrHsSyn
@@ -363,12 +380,20 @@ TH_QQUASIQUOTE  { L _ (ITqQuasiQuote _) }
 
 %monad { P } { >>= } { return }
 %lexer { lexer } { L _ ITeof }
+%tokentype { (Located Token) }
+
+-- Exported parsers
 %name parseModule module
+%name parseImport importdecl
+%name parseStatement stmt
+%name parseDeclaration topdecl
+%name parseExpression exp
+%name parseTypeSignature sigdecl
+%name parseFullStmt   stmt
 %name parseStmt   maybe_stmt
 %name parseIdentifier  identifier
 %name parseType ctype
 %partial parseHeader header
-%tokentype { (Located Token) }
 %%
 
 -----------------------------------------------------------------------------



More information about the ghc-commits mailing list