From ab40fc8a3480adf5c43858c7593ed0b23e54fc80 Mon Sep 17 00:00:00 2001 From: wes Date: Thu, 23 Mar 2017 20:02:46 -0400 Subject: [PATCH] skeleton structure and initial python grammar for imports (for reference) --- src/Analyze.hs | 9 +++++++++ src/IndexCode.hs | 6 +++--- src/Parse/Python.hs | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/Analyze.hs create mode 100644 src/Parse/Python.hs diff --git a/src/Analyze.hs b/src/Analyze.hs new file mode 100644 index 0000000..6b041ec --- /dev/null +++ b/src/Analyze.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Analyze () where + +import qualified Filesystem.Path.CurrentOS as FP +import Parse.Python + +getDependencies :: FP.FilePath -> [FP.FilePath] +getDependencies = undefined diff --git a/src/IndexCode.hs b/src/IndexCode.hs index 4d774d4..fb3824a 100644 --- a/src/IndexCode.hs +++ b/src/IndexCode.hs @@ -15,9 +15,6 @@ import qualified Filesystem.Path.CurrentOS as FP import qualified Control.Concurrent.Async as CA import qualified Data.Text as T -notHidden :: FP.FilePath -> Bool -notHidden fname = (T.head $ decodeFile $ FP.filename fname) /= '.' - decodeFile :: FP.FilePath -> T.Text decodeFile fname = case FP.toText fname of @@ -31,6 +28,9 @@ recurse files subdirs subs <- CA.mapConcurrently lsRecursive subdirs return $ files >< (join subs) +notHidden :: FP.FilePath -> Bool +notHidden fname = (T.head $ decodeFile $ FP.filename fname) /= '.' + getUnhidden :: S.Seq FP.FilePath -> S.Seq FP.FilePath getUnhidden = S.filter notHidden diff --git a/src/Parse/Python.hs b/src/Parse/Python.hs new file mode 100644 index 0000000..4c950c7 --- /dev/null +++ b/src/Parse/Python.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Parse.Python () where + +-- Responsible for parsing python import statements + +{- + - import_stmt: import_name | import_from + - import_name: 'import' dotted_as_names + - note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS + - import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+) + - 'import' ('*' | '(' import_as_names ')' | import_as_names)) + - import_as_name: NAME ['as' NAME] + - dotted_as_name: dotted_name ['as' NAME] + - import_as_names: import_as_name (',' import_as_name)* [','] + - dotted_as_names: dotted_as_name (',' dotted_as_name)* + - dotted_name: NAME ('.' NAME)* + -}