Permalink
Browse files

Builds and runs tests. Need to make test pass.

  • Loading branch information...
1 parent 1388d58 commit f2115d21c857e5997921fcdf10b201cfe51a6e69 @alanz alanz committed Nov 24, 2010
View
5 .ghci
@@ -0,0 +1,5 @@
+-- Startup commands for the GHC interpreter
+:set -hide-package monads-tf
+:set -hide-package monads-fd
+:set -i./src
+:set -i./dist/build
View
@@ -14,3 +14,5 @@
/src/Language/JavaScript/Parser/Parser.hs~
/src/Language/JavaScript/Parser/Parser/Lexer.x~
/src/Language/JavaScript/Parser/Parser/Parser.y~
+/.ghci~
+/runtests.hs~
View
@@ -1,3 +0,0 @@
-
-cabal build
-
View
@@ -1,3 +1,6 @@
+#!/bin/sh
+
+# do a clean build of all, including the tests
+cabal clean && cabal configure -fbuildtests && cabal build && cabal haddock
-cabal clean && cabal configure && cabal build
View
@@ -10,8 +10,16 @@ Maintainer: alan.zimm@gmail.com
Copyright: (c) 2010 Alan Zimmerman
Category: Language
Build-type: Simple
+homepage: http://github.com/alanz/language-javascript
+bug-reports: http://github.com/alanz//language-javascript/issues
-- Extra-source-files:
-Cabal-version: >=1.2
+--Cabal-version: >=1.2
+Cabal-version: >= 1.6
+
+
+flag buildtests
+ description: Build the executable to run unit tests
+ default: False
Library
Build-depends: base >= 4 && < 5
@@ -22,7 +30,29 @@ Library
Exposed-modules: Language.JavaScript.Parser.Parser
Language.JavaScript.Parser.Parser.Lexer
Language.JavaScript.Parser.Parser.Parser
- -- Other-modules:
+ Language.JavaScript.Parser.AST
+ Other-modules: Language.JavaScript.Parser.LexerUtils
+ Language.JavaScript.Parser.ParseError
+ Language.JavaScript.Parser.ParserMonad
+ -- Language.JavaScript.Parser.ParserUtils
+ Language.JavaScript.Parser.SrcLocation
+ Language.JavaScript.Parser.StringEscape
+ Language.JavaScript.Parser.Token
Build-tools: happy, alex
-
+executable runtests
+ if flag(buildtests)
+ Buildable: True
+ cpp-options: -DTEST
+ build-depends: QuickCheck >= 2 && < 3,
+ HUnit,
+ test-framework-hunit,
+ test-framework
+ hs-source-dirs: . src ./dist/build
+ else
+ Buildable: False
+ main-is: runtests.hs
+
+source-repository head
+ type: git
+ location: git://github.com/alanz/language-javascript.git
View
@@ -0,0 +1,25 @@
+
+import Test.Framework (defaultMain, testGroup, Test)
+import Test.Framework.Providers.HUnit
+import Test.HUnit hiding (Test)
+
+
+import Language.JavaScript.Parser.Parser
+
+main :: IO ()
+main = defaultMain [testSuite]
+
+testSuite :: Test
+testSuite = testGroup "Parser"
+ [
+ testCase "helloWorld" caseHelloWorld
+ ]
+
+--srcHelloWorld = "Hello"
+srcHelloWorld = ";"
+caseHelloWorld =
+ "Done Empty JSFunction (JSIdentifier \"Hello\") [JSIdentifier \"a\"] (JSFunctionBody [])"
+ @=? (show $ parseStmt srcHelloWorld "src")
+
+
+-- EOF
@@ -15,11 +15,13 @@ import Language.JavaScript.Parser.SrcLocation
import Language.JavaScript.Parser.Token
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.
+-- | 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).
- -- -> Either ParseError ([StatementSpan], [Token]) -- ^ An error or maybe the abstract syntax tree (AST) of zero or more python statements, plus comments.
- -> Either ParseError (AST.JSNode, [Token])
+ -> Either ParseError (AST.JSNode, [Token])
+ -- ^ An error or maybe the abstract syntax tree (AST) of zero or more Javascript statements, plus comments.
parseStmt input srcName =
execParserKeepComments parse state
where
@@ -24,18 +24,18 @@ $ident_letter = [a-zA-Z_]
-@reservedid =
- break|case|catch|const|continue|
- debugger|default|delete|do|
- else|enum|
- false|finally|for|function|
- if|in|instanceof|
- new|null|
- return|
- switch|
- this|throw|true|try|typeof|
- var|void|
- while|with
+-- @reservedid =
+-- break|case|catch|const|continue|
+-- debugger|default|delete|do|
+-- else|enum|
+-- false|finally|for|function|
+-- if|in|instanceof|
+-- new|null|
+-- return|
+-- switch|
+-- this|throw|true|try|typeof|
+-- var|void|
+-- while|with
tokens :-
@@ -50,66 +50,64 @@ tokens :-
<0> {
- ";" { symbolToken SemiColonToken}
- "," { symbolToken CommaToken}
- "?" { symbolToken HookToken}
- ":" { symbolToken ColonToken}
- "||" { symbolToken OrToken}
- "&&" { symbolToken AndToken}
- "|" { symbolToken BitwiseOrToken}
-
- -- "^" { symbolToken "BITWISE_XOR"}
- -- "&" { symbolToken "BITWISE_AND"}
- -- "===" { symbolToken "STRICT_EQ"}
- -- "==" { symbolToken "EQ"}
- -- "=" { symbolToken "ASSIGN"}
- -- "!==" { symbolToken "STRICT_NE"}
- -- "!=" { symbolToken "NE"}
- -- "<<" { symbolToken "LSH"}
- -- "<=" { symbolToken "LE"}
- -- "<" { symbolToken "LT"}
- -- ">>>" { symbolToken "URSH"}
- -- ">>" { symbolToken "RSH"}
- -- ">=" { symbolToken "GE"}
- -- ">" { symbolToken "GT"}
- -- "++" { symbolToken "INCREMENT"}
- -- "--" { symbolToken "DECREMENT"}
- -- "+" { symbolToken "PLUS"}
- -- "-" { symbolToken "MINUS"}
- -- "*" { symbolToken "MUL"}
- -- "/" { symbolToken "DIV"}
- -- "%" { symbolToken "MOD"}
- -- "!" { symbolToken "NOT"}
- -- "~" { symbolToken "BITWISE_NOT"}
- -- "." { symbolToken "DOT"}
- -- "[" { symbolToken "LEFT_BRACKET"}
- -- "]" { symbolToken "RIGHT_BRACKET"}
- -- "{" { symbolToken "LEFT_CURLY"}
- -- "}" { symbolToken "RIGHT_CURLY"}
- -- "(" { symbolToken "LEFT_PAREN"}
- -- ")" { symbolToken "RIGHT_PAREN"}
- -- "@*/" { symbolToken "CONDCOMMENT_END"
-
+ ";" { symbolToken SemiColonToken}
+-- "," { symbolToken CommaToken}
+-- "?" { symbolToken HookToken}
+-- ":" { symbolToken ColonToken}
+-- "||" { symbolToken OrToken}
+-- "&&" { symbolToken AndToken}
+-- "|" { symbolToken BitwiseOrToken}
+
+-- -- "^" { symbolToken "BITWISE_XOR"}
+-- -- "&" { symbolToken "BITWISE_AND"}
+-- -- "===" { symbolToken "STRICT_EQ"}
+-- -- "==" { symbolToken "EQ"}
+-- -- "=" { symbolToken "ASSIGN"}
+-- -- "!==" { symbolToken "STRICT_NE"}
+-- -- "!=" { symbolToken "NE"}
+-- -- "<<" { symbolToken "LSH"}
+-- -- "<=" { symbolToken "LE"}
+-- -- "<" { symbolToken "LT"}
+-- -- ">>>" { symbolToken "URSH"}
+-- -- ">>" { symbolToken "RSH"}
+-- -- ">=" { symbolToken "GE"}
+-- -- ">" { symbolToken "GT"}
+-- -- "++" { symbolToken "INCREMENT"}
+-- -- "--" { symbolToken "DECREMENT"}
+-- -- "+" { symbolToken "PLUS"}
+-- -- "-" { symbolToken "MINUS"}
+-- -- "*" { symbolToken "MUL"}
+-- -- "/" { symbolToken "DIV"}
+-- -- "%" { symbolToken "MOD"}
+-- -- "!" { symbolToken "NOT"}
+-- -- "~" { symbolToken "BITWISE_NOT"}
+-- -- "." { symbolToken "DOT"}
+-- -- "[" { symbolToken "LEFT_BRACKET"}
+-- -- "]" { symbolToken "RIGHT_BRACKET"}
+-- -- "{" { symbolToken "LEFT_CURLY"}
+-- -- "}" { symbolToken "RIGHT_CURLY"}
+-- -- "(" { symbolToken "LEFT_PAREN"}
+-- -- ")" { symbolToken "RIGHT_PAREN"}
+-- -- "@*/" { symbolToken "CONDCOMMENT_END"
}
-<0> {
- "let" { symbolToken TokenLet }
-
- "in" { symbolToken TokenIn }
- -- "9" { symbolToken TokenInt } --TODO: use real value\
- $non_zero_digit $digit* { token TokenInt read }
- "var" { symbolToken TokenVar } --TODO: use real value
- "=" {symbolToken TokenEq }
- "+" {symbolToken TokenPlus }
- "-" {symbolToken TokenMinus }
- "*" {symbolToken TokenTimes }
- "/" {symbolToken TokenDiv }
- "(" {symbolToken TokenOB }
- ")" {symbolToken TokenCB }
-}
+-- <0> {
+-- "let" { symbolToken TokenLet }
+-- "in" { symbolToken TokenIn }
+-- -- "9" { symbolToken TokenInt } --TODO: use real value\
+-- $non_zero_digit $digit* { token TokenInt read }
+-- "var" { symbolToken TokenVar } --TODO: use real value
+-- "=" {symbolToken TokenEq }
+-- "+" {symbolToken TokenPlus }
+-- "-" {symbolToken TokenMinus }
+-- "*" {symbolToken TokenTimes }
+-- "/" {symbolToken TokenDiv }
+-- "(" {symbolToken TokenOB }
+-- ")" {symbolToken TokenCB }
+-- }
{
@@ -47,11 +47,12 @@ import qualified Language.JavaScript.Parser.AST as AST
%%
-Id : 'ident' { AST.JSIdentifier (token_literal $1) }
+-- Id : 'ident' { AST.JSIdentifier (token_literal $1) }
+Id : ';' { AST.JSIdentifier ";" }
+{-
Foo : '(' '+' ')' {}
-{-
Exp : let var '=' Exp in Exp { Let $2 $4 $6 }
| Exp1 { Exp1 $1 }

0 comments on commit f2115d2

Please sign in to comment.