From 72917bc3e7928f0cc499ae31e9271bc369921166 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 16 May 2018 10:55:58 -0700 Subject: [PATCH] Stub out JavaScript prelude --- preludes/javascript.js | 2 ++ src/Language/Preluded.hs | 4 ++++ src/Parsing/Parser.hs | 2 +- src/Semantic/Util.hs | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 preludes/javascript.js diff --git a/preludes/javascript.js b/preludes/javascript.js new file mode 100644 index 000000000..6c55780d6 --- /dev/null +++ b/preludes/javascript.js @@ -0,0 +1,2 @@ +// can't quite define console.log in a way we can evaluate yet, but... +function log(x) { return __semantic_print(x) } diff --git a/src/Language/Preluded.hs b/src/Language/Preluded.hs index 1a74ebe3a..2400d6887 100644 --- a/src/Language/Preluded.hs +++ b/src/Language/Preluded.hs @@ -7,6 +7,7 @@ module Language.Preluded import GHC.TypeLits import qualified Language.Python.Assignment as Python import qualified Language.Ruby.Assignment as Ruby +import qualified Language.TypeScript.Assignment as TypeScript class Preluded syntax where type PreludePath syntax :: Symbol @@ -16,3 +17,6 @@ instance Preluded Ruby.Term where instance Preluded Python.Term where type PreludePath Python.Term = "preludes/python.py" + +instance Preluded TypeScript.Term where + type PreludePath TypeScript.Term = "preludes/javascript.js" diff --git a/src/Parsing/Parser.hs b/src/Parsing/Parser.hs index 06602cbbd..a21431599 100644 --- a/src/Parsing/Parser.hs +++ b/src/Parsing/Parser.hs @@ -73,7 +73,7 @@ someAnalysisParser :: ( ApplyAll' typeclasses Go.Syntax -> Language -- ^ The 'Language' to select. -> SomeAnalysisParser typeclasses (Record Location) -- ^ A 'SomeAnalysisParser abstracting the syntax type to be produced. someAnalysisParser _ Go = SomeAnalysisParser goParser Nothing -someAnalysisParser _ JavaScript = SomeAnalysisParser typescriptParser Nothing +someAnalysisParser _ JavaScript = SomeAnalysisParser typescriptParser $ Just (File (TypeLevel.symbolVal (Proxy :: Proxy (PreludePath TypeScript.Term))) (Just JavaScript)) someAnalysisParser _ PHP = SomeAnalysisParser phpParser Nothing someAnalysisParser _ Python = SomeAnalysisParser pythonParser $ Just (File (TypeLevel.symbolVal (Proxy :: Proxy (PreludePath Python.Term))) (Just Python)) someAnalysisParser _ Ruby = SomeAnalysisParser rubyParser $ Just (File (TypeLevel.symbolVal (Proxy :: Proxy (PreludePath Ruby.Term))) (Just Ruby)) diff --git a/src/Semantic/Util.hs b/src/Semantic/Util.hs index d7da02ba1..6c0e3cb77 100644 --- a/src/Semantic/Util.hs +++ b/src/Semantic/Util.hs @@ -24,6 +24,7 @@ import Semantic.Task import qualified Language.Python.Assignment as Python import qualified Language.Ruby.Assignment as Ruby +import qualified Language.TypeScript.Assignment as TypeScript justEvaluating = runM @@ -79,7 +80,7 @@ evalGoProject path = justEvaluating =<< evaluateProject goParser Language.Go Not evalRubyProject path = justEvaluating =<< evaluateProject rubyParser Language.Ruby rubyPrelude path evalPHPProject path = justEvaluating =<< evaluateProject phpParser Language.PHP Nothing path evalPythonProject path = justEvaluating =<< evaluateProject pythonParser Language.Python pythonPrelude path -evalJavaScriptProject path = justEvaluating =<< evaluateProject typescriptParser Language.JavaScript Nothing path +evalJavaScriptProject path = justEvaluating =<< evaluateProject typescriptParser Language.JavaScript javaScriptPrelude path evalTypeScriptProjectQuietly path = evaluatingWithHoles =<< evaluateProject typescriptParser Language.TypeScript Nothing path evalTypeScriptProject path = justEvaluating =<< evaluateProject typescriptParser Language.TypeScript Nothing path @@ -87,6 +88,7 @@ typecheckGoFile path = checking =<< evaluateProjectWithCaching goParser Language rubyPrelude = Just $ File (TypeLevel.symbolVal (Proxy :: Proxy (PreludePath Ruby.Term))) (Just Language.Ruby) pythonPrelude = Just $ File (TypeLevel.symbolVal (Proxy :: Proxy (PreludePath Python.Term))) (Just Language.Python) +javaScriptPrelude = Just $ File (TypeLevel.symbolVal (Proxy :: Proxy (PreludePath TypeScript.Term))) (Just Language.JavaScript) -- Evaluate a project, starting at a single entrypoint. evaluateProject parser lang prelude path = evaluatePackageWith id withTermSpans <$> runTask (readProject Nothing path lang [] >>= parsePackage parser prelude)