Skip to content

Commit

Permalink
Starting cleanup to prepare for initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanz committed Nov 30, 2010
1 parent b1502c3 commit 317b43a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,3 +16,4 @@
/src/Language/JavaScript/Parser/Parser/Parser.y~
/.ghci~
/runtests.hs~
/src/Language/JavaScript/Parser.hs~
3 changes: 2 additions & 1 deletion language-javascript.cabal
Expand Up @@ -27,7 +27,8 @@ Library
, mtl >= 1.1 && < 2
, containers >= 0.2 && < 0.5
hs-source-dirs: src
Exposed-modules: Language.JavaScript.Parser.Parser
Exposed-modules: Language.JavaScript.Parser
Language.JavaScript.Parser.Parser
Language.JavaScript.Parser.Lexer
Language.JavaScript.Parser.Grammar
Language.JavaScript.Parser.AST
Expand Down
4 changes: 2 additions & 2 deletions runtests.hs
Expand Up @@ -196,7 +196,7 @@ testSuite = testGroup "Parser"
srcHelloWorld = "Hello"
caseHelloWorld =
"Right (JSSourceElements [JSExpression [JSIdentifier \"Hello\"]])"
@=? (show $ parseStmt srcHelloWorld "src")
@=? (show $ parse srcHelloWorld "src")


-- ---------------------------------------------------------------------
Expand All @@ -208,7 +208,7 @@ testPE str expected = expected @=? (show $ parseUsing parsePrimaryExpression str

testStmt str expected = expected @=? (show $ parseUsing parseStatement str "src")

testProg str expected = expected @=? (show $ parseUsing parse str "src")
testProg str expected = expected @=? (show $ parseUsing parseProgram str "src")


-- EOF
10 changes: 10 additions & 0 deletions src/Language/JavaScript/Parser.hs
@@ -0,0 +1,10 @@
module Language.JavaScript.Parser
(
parse
) where


import Language.JavaScript.Parser.Parser



4 changes: 2 additions & 2 deletions src/Language/JavaScript/Parser/Grammar.y
@@ -1,5 +1,5 @@
{
module Language.JavaScript.Parser.Grammar (parse, parseLiteral, parsePrimaryExpression,parseStatement) where
module Language.JavaScript.Parser.Grammar (parseProgram, parseLiteral, parsePrimaryExpression,parseStatement) where

import Control.Monad.Error.Class (throwError)
import Data.Char
Expand All @@ -11,7 +11,7 @@ import qualified Language.JavaScript.Parser.AST as AST
}

-- The name of the generated function to be exported from the module
%name parse Program
%name parseProgram Program
%name parseLiteral Literal
%name parsePrimaryExpression PrimaryExpression
%name parseStatement Statement
Expand Down
3 changes: 3 additions & 0 deletions src/Language/JavaScript/Parser/Lexer.x
Expand Up @@ -10,7 +10,10 @@ import qualified Data.Map as Map

}

-- Not using a wrapper, rolling own below.
--%wrapper "basic"
-- %wrapper "monad"
-- %wrapper "monad-bytestring"

-- character sets
$lf = \n -- line feed
Expand Down
32 changes: 15 additions & 17 deletions src/Language/JavaScript/Parser/Parser.hs
@@ -1,10 +1,8 @@
module Language.JavaScript.Parser.Parser (
-- * Parsing modules
-- parseModule,
-- * Parsing statements
parseStmt
-- * Parsing
parse
-- * Parsing expressions
-- parseExpr)
-- parseExpr
, parseUsing
) where

Expand All @@ -19,12 +17,12 @@ import qualified Language.JavaScript.Parser.AST as AST
-- | Parse one compound statement, or a sequence of simple statements.
-- Generally used for interactive input, such as from the command line of an interpreter.
-- Return comments in addition to the parsed statements.
parseStmtKeepComments :: String -- ^ The input stream (python statement source code).
-> String -- ^ The name of the python source (filename or input device).
parseStmtKeepComments :: String -- ^ The input stream (Javascript source code).
-> String -- ^ The name of the Javascript source (filename or input device).
-> Either ParseError (AST.JSNode, [Token])
-- ^ An error or maybe the abstract syntax tree (AST) of zero or more Javascript statements, plus comments.
parseStmtKeepComments input srcName =
execParserKeepComments parse state
execParserKeepComments parseProgram state
where
initLoc = initialSrcLocation srcName
state = initialState initLoc input initStartCodeStack
Expand All @@ -33,12 +31,12 @@ parseStmtKeepComments input srcName =
-- | Parse one compound statement, or a sequence of simple statements.
-- Generally used for interactive input, such as from the command line of an interpreter.
-- Return comments in addition to the parsed statements.
parseStmt :: String -- ^ The input stream (python statement source code).
-> String -- ^ The name of the python source (filename or input device).
parse :: String -- ^ The input stream (Javascript source code).
-> String -- ^ The name of the Javascript source (filename or input device).
-> Either ParseError AST.JSNode
-- ^ An error or maybe the abstract syntax tree (AST) of zero or more Javascript statements, plus comments.
parseStmt input srcName =
execParser parse state
parse input srcName =
execParser parseProgram state
where
initLoc = initialSrcLocation srcName
state = initialState initLoc input initStartCodeStack
Expand All @@ -47,11 +45,11 @@ parseStmt input srcName =
-- | Parse one compound statement, or a sequence of simple statements.
-- Generally used for interactive input, such as from the command line of an interpreter.
-- Return comments in addition to the parsed statements.
-- parseUsing ::
-- P Token
-- -> String -- ^ The input stream (python statement source code).
-- -> String -- ^ The name of the python source (filename or input device).
-- -> Either ParseError AST.JSNode
parseUsing ::
P AST.JSNode
-> String -- ^ The input stream (python statement source code).
-> String -- ^ The name of the python source (filename or input device).
-> Either ParseError AST.JSNode
-- ^ An error or maybe the abstract syntax tree (AST) of zero or more Javascript statements, plus comments.
parseUsing p input srcName =
execParser p state
Expand Down

0 comments on commit 317b43a

Please sign in to comment.