Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d64c137
Fix Fortran77 comment with a preprocessing stage
madgen Jul 22, 2015
b2367a1
Merge remote-tracking branch 'upstream/master'
madgen Jul 23, 2015
2f8546d
added pprint method
dorchard Jul 27, 2015
fe8677e
added default indentor
dorchard Jul 27, 2015
730b4f9
Add support for Double Precision data type
madgen Jul 27, 2015
cc0a543
Handle fixed form Fortran continuation lines
madgen Jul 27, 2015
cd12c76
Separate preprocessor interface from fixed form
madgen Jul 27, 2015
6c5a89f
refactoring outputF/outputG to printMaster/printSlave
dorchard Jul 27, 2015
2af45a8
removed default list behaviours for master/slave, added specific one …
dorchard Jul 27, 2015
10f6087
[InterfaceSpec] instance removed
dorchard Jul 27, 2015
f1e8615
fixed default pretty printing of measure units
dorchard Jul 27, 2015
d836798
removed default char instance + some comments
dorchard Jul 27, 2015
05fba16
cabal updated
dorchard Oct 28, 2015
8128a4b
here is the f90 spec:
Nov 27, 2015
67dd499
you don't need ignore leading white, because there is already a rule …
Nov 27, 2015
1a28689
remove leading space
Nov 29, 2015
0e80966
Merge pull request #1 from ledyba/master
dorchard Dec 7, 2015
da6c2b5
wider format string acceptance
dorchard Jan 27, 2016
626ff62
Merge branch 'master' of github.com:dorchard/language-fortran
dorchard Jan 27, 2016
2bf8497
removed the debug info
dorchard Feb 18, 2016
64347a2
Stack support. You should be able to build this with "stack build" now.
acr31 Mar 6, 2016
a914581
version number change; towards new kind of labels
dorchard Mar 10, 2016
9fd5b0d
Merge branch 'master' of github.com:dorchard/language-fortran
dorchard Mar 10, 2016
eb39073
correct span information for subroutine and function arguments
dorchard Mar 18, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion language-fortran.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: language-fortran
version: 0.3
version: 0.5.1
synopsis: Fortran lexer and parser, language support, and extensions.
description:
Lexer and parser for Fortran roughly supporting standards from
Expand Down
82 changes: 42 additions & 40 deletions src/Language/Fortran.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type ProgName = String
data SubName p = SubName p String
| NullSubName p
deriving (Show, Functor, Typeable, Data, Eq)
data VarName p = VarName p Variable

data VarName p = VarName p Variable
deriving (Show, Functor, Typeable, Data, Eq, Read)

data ArgName p = ArgName p String
Expand All @@ -74,30 +74,33 @@ data ArgList p = ArgList p (Expr p)

type Program p = [ProgUnit p]

-- Prog type (type of result) name args (result) body use's
-- Prog type (type of result) name args (result) body use's
data ProgUnit p = Main p SrcSpan (SubName p) (Arg p) (Block p) [ProgUnit p]
| Sub p SrcSpan (Maybe (BaseType p)) (SubName p) (Arg p) (Block p)
| Function p SrcSpan (Maybe (BaseType p)) (SubName p) (Arg p) (Maybe (VarName p)) (Block p)
| Module p SrcSpan (SubName p) (Uses p) (Implicit p) (Decl p) [ProgUnit p]
| BlockData p SrcSpan (SubName p) (Uses p) (Implicit p) (Decl p)
| PSeq p SrcSpan (ProgUnit p) (ProgUnit p) -- sequence of programs
| Prog p SrcSpan (ProgUnit p) -- useful for {#p: #q : program ... }
| NullProg p SrcSpan -- null
| IncludeProg p SrcSpan (Decl p) (Maybe (Fortran p))
deriving (Show, Functor, Typeable, Data, Eq)

-- | Implicit none or no implicit
data Implicit p = ImplicitNone p | ImplicitNull p
-- | Implicit none or no implicit
data Implicit p = ImplicitNone p | ImplicitNull p
deriving (Show, Functor, Typeable, Data, Eq)

-- | renames for "use"s
-- | renames for "use"s
type Renames = [(Variable, Variable)]

data UseBlock p = UseBlock (Uses p) SrcLoc deriving (Show, Functor, Typeable, Data, Eq)

data Use = Use String Renames
| UseOnly String [(Variable, Maybe Variable)]
deriving (Show, Typeable, Data, Eq)

-- | (second 'p' let's you annotate the 'cons' part of the cell)
data Uses p = Use p (String, Renames) (Uses p) p
| UseNil p deriving (Show, Functor, Typeable, Data, Eq)
data Uses p = Uses p Use (Uses p) p
| UseNil p deriving (Show, Functor, Typeable, Data, Eq)

-- use's implicit decls stmts
data Block p = Block p (UseBlock p) (Implicit p) SrcSpan (Decl p) (Fortran p)
Expand All @@ -107,7 +110,7 @@ data Decl p = Decl p SrcSpan [(Expr p, Expr p, Maybe Int)] (Type p
| Namelist p [(Expr p, [Expr p])] -- namelist declaration
| DataDecl p (DataForm p)
| Equivalence p SrcSpan [(Expr p)]
| AttrStmt p (Attr p) [(Expr p, Expr p, Maybe Int)]
| AttrStmt p (Attr p) [(Expr p, Expr p, Maybe Int)]
| AccessStmt p (Attr p) [GSpec p] -- access stmt
| ExternalStmt p [String] -- external stmt
| Interface p (Maybe (GSpec p)) [InterfaceSpec p] -- interface declaration
Expand All @@ -121,19 +124,20 @@ data Decl p = Decl p SrcSpan [(Expr p, Expr p, Maybe Int)] (Type p
| MeasureUnitDef p SrcSpan [(MeasureUnit, MeasureUnitSpec p)]
deriving (Show, Functor, Typeable, Data, Eq)

-- BaseType dimensions type Attributes kind len
-- BaseType dimensions type Attributes kind len
data Type p = BaseType p (BaseType p) [Attr p] (Expr p) (Expr p)
| ArrayT p [(Expr p, Expr p)] (BaseType p) [Attr p] (Expr p) (Expr p)
deriving (Show, Functor, Typeable, Data, Eq)

data BaseType p = Integer p | Real p | Character p | SomeType p | DerivedType p (SubName p)
data BaseType p = Integer p | Real p | DoublePrecision p | Character p
| SomeType p | DerivedType p (SubName p)
| Recursive p | Pure p | Elemental p | Logical p | Complex p
deriving (Show, Functor, Typeable, Data, Eq)

data Attr p = Parameter p
| Allocatable p
| External p
| Intent p (IntentAttr p)
| Intent p (IntentAttr p)
| Intrinsic p
| Optional p
| Pointer p
Expand All @@ -147,7 +151,7 @@ data Attr p = Parameter p
-- units-of-measure extension
| MeasureUnit p (MeasureUnitSpec p)
deriving (Show, Functor, Typeable, Data, Eq)


{- start: units-of-measure extension -}
type MeasureUnit = String
Expand All @@ -166,20 +170,20 @@ data Fraction p = IntegerConst p String

data GSpec p = GName p (Expr p) | GOper p (BinOp p) | GAssg p
deriving (Show, Functor, Typeable, Data, Eq)

data InterfaceSpec p = FunctionInterface p (SubName p) (Arg p) (Uses p) (Implicit p) (Decl p)
| SubroutineInterface p (SubName p) (Arg p) (Uses p) (Implicit p) (Decl p)
| ModuleProcedure p [(SubName p)]
deriving (Show, Functor, Typeable, Data, Eq)

data DataForm p = Data p [(Expr p, Expr p)] deriving (Show, Functor, Typeable, Data, Eq) -- data declaration

data IntentAttr p = In p
| Out p
| InOut p
deriving (Show, Functor, Typeable, Data, Eq)
data Fortran p = Assg p SrcSpan (Expr p) (Expr p)

data Fortran p = Assg p SrcSpan (Expr p) (Expr p)
| For p SrcSpan (VarName p) (Expr p) (Expr p) (Expr p) (Fortran p)
| DoWhile p SrcSpan (Expr p) (Fortran p)
| FSeq p SrcSpan (Fortran p) (Fortran p)
Expand All @@ -189,7 +193,7 @@ data Fortran p = Assg p SrcSpan (Expr p) (Expr p)
| Call p SrcSpan (Expr p) (ArgList p)
| Open p SrcSpan [Spec p]
| Close p SrcSpan [Spec p]
| Continue p SrcSpan
| Continue p SrcSpan
| Cycle p SrcSpan String
| DataStmt p SrcSpan (DataForm p)
| Deallocate p SrcSpan [(Expr p)] (Expr p)
Expand Down Expand Up @@ -224,7 +228,7 @@ data Expr p = Con p SrcSpan String
| Unary p SrcSpan (UnaryOp p) (Expr p)
| CallExpr p SrcSpan (Expr p) (ArgList p)
| NullExpr p SrcSpan
| Null p SrcSpan
| Null p SrcSpan
| ESeq p SrcSpan (Expr p) (Expr p)
| Bound p SrcSpan (Expr p) (Expr p)
| Sqrt p SrcSpan (Expr p)
Expand Down Expand Up @@ -262,7 +266,7 @@ data Spec p = Access p (Expr p)
| ExFile p (Expr p)
| Exist p (Expr p)
| Eor p (Expr p)
| File p (Expr p)
| File p (Expr p)
| FMT p (Expr p)
| Form p (Expr p)
| Formatted p (Expr p)
Expand All @@ -276,20 +280,20 @@ data Spec p = Access p (Expr p)
| Floating p (Expr p) (Expr p)
| NextRec p (Expr p)
| NML p (Expr p)
| Opened p (Expr p)
| Opened p (Expr p)
| Pad p (Expr p)
| Position p (Expr p)
| Read p (Expr p)
| ReadWrite p (Expr p)
| Rec p (Expr p)
| Recl p (Expr p)
| Rec p (Expr p)
| Recl p (Expr p)
| Sequential p (Expr p)
| Size p (Expr p)
| Status p (Expr p)
| StringLit p String
| StringLit p String
| Unit p (Expr p)
| WriteSp p (Expr p)
| Delimiter p
| Delimiter p
deriving (Show, Functor,Typeable,Data, Eq)

-- Extract span information from the source tree
Expand All @@ -315,7 +319,6 @@ instance Span (ProgUnit a) where
srcSpan (Function x sp _ _ _ _ _) = sp
srcSpan (Module x sp _ _ _ _ _ ) = sp
srcSpan (BlockData x sp _ _ _ _) = sp
srcSpan (PSeq x sp _ _) = sp
srcSpan (Prog x sp _) = sp
srcSpan (NullProg x sp) = sp

Expand Down Expand Up @@ -344,7 +347,7 @@ instance Span (Fortran a) where
srcSpan (Backspace x sp _) = sp
srcSpan (Call x sp e as) = sp
srcSpan (Open x sp s) = sp
srcSpan (Close x sp s) = sp
srcSpan (Close x sp s) = sp
srcSpan (Continue x sp) = sp
srcSpan (Cycle x sp s) = sp
srcSpan (DataStmt x sp _) = sp
Expand All @@ -357,9 +360,9 @@ instance Span (Fortran a) where
srcSpan (Nullify x sp e) = sp
srcSpan (Inquire x sp s e) = sp
srcSpan (Pause x sp _) = sp
srcSpan (Rewind x sp s) = sp
srcSpan (Rewind x sp s) = sp
srcSpan (Stop x sp e) = sp
srcSpan (Where x sp e f _) = sp
srcSpan (Where x sp e f _) = sp
srcSpan (Write x sp s e) = sp
srcSpan (PointerAssg x sp e1 e2) = sp
srcSpan (Return x sp e) = sp
Expand All @@ -369,10 +372,10 @@ instance Span (Fortran a) where
srcSpan (TextStmt x sp s) = sp
srcSpan (NullStmt x sp) = sp

-- Extract the tag
-- Extract the tag

class Tagged d where
tag :: d a -> a
tag :: d a -> a

instance Tagged Attr where
tag (Parameter x) = x
Expand Down Expand Up @@ -413,14 +416,14 @@ instance Tagged Implicit where
tag (ImplicitNone x) = x
tag (ImplicitNull x) = x

instance Tagged Uses where
tag (Use x _ _ _) = x
instance Tagged Uses where
tag (Uses x _ _ _) = x
tag (UseNil x) = x

instance Tagged Arg where
tag (Arg x _ _) = x

instance Tagged ArgList where
instance Tagged ArgList where
tag (ArgList x _) = x

instance Tagged ArgName where
Expand All @@ -434,7 +437,6 @@ instance Tagged ProgUnit where
tag (Function x sp _ _ _ _ _)= x
tag (Module x sp _ _ _ _ _ ) = x
tag (BlockData x sp _ _ _ _) = x
tag (PSeq x sp _ _) = x
tag (Prog x sp _) = x
tag (NullProg x sp) = x

Expand Down Expand Up @@ -468,7 +470,7 @@ instance Tagged Fortran where
tag (Backspace x sp _) = x
tag (Call x sp e as) = x
tag (Open x sp s) = x
tag (Close x sp s) = x
tag (Close x sp s) = x
tag (Continue x sp) = x
tag (Cycle x sp s) = x
tag (DataStmt x sp _) = x
Expand All @@ -481,9 +483,9 @@ instance Tagged Fortran where
tag (Nullify x sp e) = x
tag (Inquire x sp s e) = x
tag (Pause x sp _) = x
tag (Rewind x sp s) = x
tag (Rewind x sp s) = x
tag (Stop x sp e) = x
tag (Where x sp e f _) = x
tag (Where x sp e f _) = x
tag (Write x sp s e) = x
tag (PointerAssg x sp e1 e2) = x
tag (Return x sp e) = x
Expand Down
Loading