Make extension-aware parser entrypoint
This commit is contained in:
parent
28e16ca068
commit
ba66f6e8e4
@ -28,13 +28,10 @@ import qualified System.Log as L
|
||||
import Duplo.Error
|
||||
import Duplo.Tree (collect)
|
||||
|
||||
import Parser
|
||||
import ParseTree
|
||||
import Range
|
||||
import Product
|
||||
import AST hiding (def)
|
||||
import qualified AST.Find as Find
|
||||
import AST.Pascaligo.Parser
|
||||
-- import Error
|
||||
|
||||
main :: IO ()
|
||||
@ -219,7 +216,7 @@ loadFromVFS funs uri = do
|
||||
Just vf <- Core.getVirtualFileFunc funs $ J.toNormalizedUri uri
|
||||
let txt = virtualFileText vf
|
||||
let Just fin = J.uriToFilePath uri
|
||||
(tree, _) <- runParserM . recognise =<< mkRawTreePascal (Text fin txt)
|
||||
(tree, _) <- parse (Text fin txt)
|
||||
return $ addLocalScopes tree
|
||||
|
||||
-- loadByURI
|
||||
@ -242,7 +239,7 @@ collectErrors
|
||||
collectErrors funs uri path version = do
|
||||
case path of
|
||||
Just fin -> do
|
||||
(tree, errs) <- runParserM . recognise =<< mkRawTreePascal (Path fin)
|
||||
(tree, errs) <- parse (Path fin)
|
||||
Core.publishDiagnosticsFunc funs 100 uri version
|
||||
$ partitionBySource
|
||||
$ map errorToDiag (errs <> map (getElem *** void) (collect tree))
|
||||
|
@ -5,3 +5,4 @@ import AST.Completion as M
|
||||
import AST.Find as M
|
||||
import AST.Scope as M
|
||||
import AST.Skeleton as M
|
||||
import AST.Parser as M
|
||||
|
27
tools/lsp/squirrel/src/AST/Parser.hs
Normal file
27
tools/lsp/squirrel/src/AST/Parser.hs
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
module AST.Parser
|
||||
( Source(..)
|
||||
, parse
|
||||
) where
|
||||
|
||||
import Control.Monad.Catch
|
||||
|
||||
import System.FilePath
|
||||
|
||||
import qualified AST.Pascaligo.Parser as Pascal
|
||||
import qualified AST.Reasonligo.Parser as Reason
|
||||
import AST.Skeleton
|
||||
|
||||
import ParseTree
|
||||
import Parser
|
||||
|
||||
data UnsupportedExtension = UnsupportedExtension String
|
||||
deriving stock Show
|
||||
deriving anyclass Exception
|
||||
|
||||
parse :: Source -> IO (LIGO Info, [Msg])
|
||||
parse src = do
|
||||
case takeExtension $ srcPath src of
|
||||
"religo" -> mkRawTreeReason src >>= runParserM . Reason.recognise
|
||||
"ligo" -> mkRawTreePascal src >>= runParserM . Pascal.recognise
|
||||
ext -> throwM $ UnsupportedExtension ext
|
Loading…
Reference in New Issue
Block a user