Skip to content

Commit

Permalink
Builds and runs tests. Need to make test pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanz committed Nov 24, 2010
1 parent 1388d58 commit f2115d2
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 79 deletions.
5 changes: 5 additions & 0 deletions .ghci
Original file line number Original file line Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
/src/Language/JavaScript/Parser/Parser.hs~ /src/Language/JavaScript/Parser/Parser.hs~
/src/Language/JavaScript/Parser/Parser/Lexer.x~ /src/Language/JavaScript/Parser/Parser/Lexer.x~
/src/Language/JavaScript/Parser/Parser/Parser.y~ /src/Language/JavaScript/Parser/Parser/Parser.y~
/.ghci~
/runtests.hs~
3 changes: 0 additions & 3 deletions build.sh

This file was deleted.

5 changes: 4 additions & 1 deletion buildall.sh
Original file line number Original file line Diff line number Diff line change
@@ -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


36 changes: 33 additions & 3 deletions language-javascript.cabal
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ Maintainer: alan.zimm@gmail.com
Copyright: (c) 2010 Alan Zimmerman Copyright: (c) 2010 Alan Zimmerman
Category: Language Category: Language
Build-type: Simple Build-type: Simple
homepage: http://github.com/alanz/language-javascript
bug-reports: http://github.com/alanz//language-javascript/issues
-- Extra-source-files: -- 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 Library
Build-depends: base >= 4 && < 5 Build-depends: base >= 4 && < 5
Expand All @@ -22,7 +30,29 @@ Library
Exposed-modules: Language.JavaScript.Parser.Parser Exposed-modules: Language.JavaScript.Parser.Parser
Language.JavaScript.Parser.Parser.Lexer Language.JavaScript.Parser.Parser.Lexer
Language.JavaScript.Parser.Parser.Parser 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 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
25 changes: 25 additions & 0 deletions runtests.hs
Original file line number Original file line Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions src/Language/JavaScript/Parser/Parser.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import Language.JavaScript.Parser.SrcLocation
import Language.JavaScript.Parser.Token import Language.JavaScript.Parser.Token
import qualified Language.JavaScript.Parser.AST as AST 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). parseStmt :: String -- ^ The input stream (python statement source code).
-> String -- ^ The name of the python source (filename or input device). -> 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 = parseStmt input srcName =
execParserKeepComments parse state execParserKeepComments parse state
where where
Expand Down
132 changes: 65 additions & 67 deletions src/Language/JavaScript/Parser/Parser/Lexer.x
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ $ident_letter = [a-zA-Z_]






@reservedid = -- @reservedid =
break|case|catch|const|continue| -- break|case|catch|const|continue|
debugger|default|delete|do| -- debugger|default|delete|do|
else|enum| -- else|enum|
false|finally|for|function| -- false|finally|for|function|
if|in|instanceof| -- if|in|instanceof|
new|null| -- new|null|
return| -- return|
switch| -- switch|
this|throw|true|try|typeof| -- this|throw|true|try|typeof|
var|void| -- var|void|
while|with -- while|with


tokens :- tokens :-


Expand All @@ -50,66 +50,64 @@ tokens :-




<0> { <0> {
";" { symbolToken SemiColonToken} ";" { symbolToken SemiColonToken}
"," { symbolToken CommaToken} -- "," { symbolToken CommaToken}
"?" { symbolToken HookToken} -- "?" { symbolToken HookToken}
":" { symbolToken ColonToken} -- ":" { symbolToken ColonToken}
"||" { symbolToken OrToken} -- "||" { symbolToken OrToken}
"&&" { symbolToken AndToken} -- "&&" { symbolToken AndToken}
"|" { symbolToken BitwiseOrToken} -- "|" { symbolToken BitwiseOrToken}


-- "^" { symbolToken "BITWISE_XOR"} -- -- "^" { symbolToken "BITWISE_XOR"}
-- "&" { symbolToken "BITWISE_AND"} -- -- "&" { symbolToken "BITWISE_AND"}
-- "===" { symbolToken "STRICT_EQ"} -- -- "===" { symbolToken "STRICT_EQ"}
-- "==" { symbolToken "EQ"} -- -- "==" { symbolToken "EQ"}
-- "=" { symbolToken "ASSIGN"} -- -- "=" { symbolToken "ASSIGN"}
-- "!==" { symbolToken "STRICT_NE"} -- -- "!==" { symbolToken "STRICT_NE"}
-- "!=" { symbolToken "NE"} -- -- "!=" { symbolToken "NE"}
-- "<<" { symbolToken "LSH"} -- -- "<<" { symbolToken "LSH"}
-- "<=" { symbolToken "LE"} -- -- "<=" { symbolToken "LE"}
-- "<" { symbolToken "LT"} -- -- "<" { symbolToken "LT"}
-- ">>>" { symbolToken "URSH"} -- -- ">>>" { symbolToken "URSH"}
-- ">>" { symbolToken "RSH"} -- -- ">>" { symbolToken "RSH"}
-- ">=" { symbolToken "GE"} -- -- ">=" { symbolToken "GE"}
-- ">" { symbolToken "GT"} -- -- ">" { symbolToken "GT"}
-- "++" { symbolToken "INCREMENT"} -- -- "++" { symbolToken "INCREMENT"}
-- "--" { symbolToken "DECREMENT"} -- -- "--" { symbolToken "DECREMENT"}
-- "+" { symbolToken "PLUS"} -- -- "+" { symbolToken "PLUS"}
-- "-" { symbolToken "MINUS"} -- -- "-" { symbolToken "MINUS"}
-- "*" { symbolToken "MUL"} -- -- "*" { symbolToken "MUL"}
-- "/" { symbolToken "DIV"} -- -- "/" { symbolToken "DIV"}
-- "%" { symbolToken "MOD"} -- -- "%" { symbolToken "MOD"}
-- "!" { symbolToken "NOT"} -- -- "!" { symbolToken "NOT"}
-- "~" { symbolToken "BITWISE_NOT"} -- -- "~" { symbolToken "BITWISE_NOT"}
-- "." { symbolToken "DOT"} -- -- "." { symbolToken "DOT"}
-- "[" { symbolToken "LEFT_BRACKET"} -- -- "[" { symbolToken "LEFT_BRACKET"}
-- "]" { symbolToken "RIGHT_BRACKET"} -- -- "]" { symbolToken "RIGHT_BRACKET"}
-- "{" { symbolToken "LEFT_CURLY"} -- -- "{" { symbolToken "LEFT_CURLY"}
-- "}" { symbolToken "RIGHT_CURLY"} -- -- "}" { symbolToken "RIGHT_CURLY"}
-- "(" { symbolToken "LEFT_PAREN"} -- -- "(" { symbolToken "LEFT_PAREN"}
-- ")" { symbolToken "RIGHT_PAREN"} -- -- ")" { symbolToken "RIGHT_PAREN"}
-- "@*/" { symbolToken "CONDCOMMENT_END" -- -- "@*/" { symbolToken "CONDCOMMENT_END"

} }






<0> { -- <0> {
"let" { symbolToken TokenLet } -- "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 }
}


-- "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 }
-- }




{ {
Expand Down
5 changes: 3 additions & 2 deletions src/Language/JavaScript/Parser/Parser/Parser.y
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 : '(' '+' ')' {} Foo : '(' '+' ')' {}


{-
Exp : let var '=' Exp in Exp { Let $2 $4 $6 } Exp : let var '=' Exp in Exp { Let $2 $4 $6 }
| Exp1 { Exp1 $1 } | Exp1 { Exp1 $1 }


Expand Down

0 comments on commit f2115d2

Please sign in to comment.