parse_f95.rb

Path: parsers/parse_f95.rb
Last Update: Sat Nov 11 02:27:26 JST 2006

parse_f95.rb - Fortran 90/95 Parser

Note that Japanese and English are described in parallel.

概要

parse_f95.rb は拡張子が f90, F90, f95, F95 のファイルを構文解析します. ソースコードは Fortran 90 もしくは Fortran 95 規格に沿って記述されていることを前提としています.

Overview

"parse_f95.rb" parses Fortran 90/95 files with suffixes "f90", "F90", "f95" and "F95". These files are expected to conform to Fortran 90 or Fortran 95 standards.

書法

基本的な書法はRuby の書法 と同様ですが, コメント部は ’#’ ではなく ’!’ で始まることに注意してください.

Rules

Fundamental rules are same as that of the Ruby parser. But comment markers are ’!’ not ’#’.

RDoc ドキュメンテーションと Fortran 90/95 プログラムとの対応

parse_f95.rb は Fortran 90/95 規格における言語要素, すなわち, 主プログラム, モジュール, サブルーチン, 関数の他, PUBLIC 属性を持つ変数や定数, そして利用者定義演算子, 利用者定義代入を構文解析します. これらの言語要素は RDoc ドキュメンテーションの各項目に, 以下のように記述されます.

Files :ファイル (Ruby と同様です)
Classes :モジュール, NAMELIST 変数群名リスト
Methods :主プログラム, サブルーチン, 関数, 変数, 定数, 構造データ型, 利用者定義演算子, 利用者定義代入, NAMELIST 変数群名
Required files :参照するモジュールが定義されているファイル, 及び参照する外部関数が定義されているファイルのリスト
Included Modules :参照するモジュールのリスト
Attributes :構造データ型のリスト, 参照し且つその全ての言語要素を公開する モジュールのリスト

‘Methods’ にリストされる言語要素 (サブルーチン, 関数, …) は, モジュール内で定義されているのであれば, ‘Classes’ の項目に記述されます. 主プログラム内で定義されたり, 外部手続きとして定義される場合には ‘Files’ の項目に記述されます. 主プログラム自体も ‘Files’ の項目に記述されます.

Correspondence between RDoc documentation and Fortran 90/95 programs

"parse_f95.rb" parses entities of Fortran 90/95 standards, or main programs, modules, subroutines, functions, derived types, public variables, public constants, defined operators and defined assignments. These entities are described in items of RDoc documentation, as follows.

Files :Files (same as Ruby)
Classes :Modules, list of NAMELIST group names
Methods :Main programs, subroutines, functions, variables, constants, derived types, defined operators, defined assignments, NAMELIST group names
Required files :Files in which imported modules, external subroutines and external functions are defined.
Included Modules :List of imported modules
Attributes :List of derived types, List of imported modules all of whose components are published again

Entities listed in ‘Methods’ (subroutines, functions, …) defined in modules are described in the item of ‘Classes’. On the other hand, defined in main programs or as external procedures are described in the item of ‘Files’. Main programs are described in the item of ‘Files’, too.

構文解析される言語要素

主プログラムおよび, 外部から参照が可能なサブルーチン, 関数, 変数, 定数, 構造データ型, 利用者定義演算子, 利用者定義代入, NAMELIST 変数群名がドキュメントとして出力されます. —all オプションをつけて rdoc を実行する場合には, 外部からの参照が許可されない 言語要素も含め, 全てが出力されます.

Parsed entities

Documentation on public entities (main programs, subroutines, functions, variables, constants, derived types, defined operators, defined assignments, NAMELIST group names) are generated. With "—all" option, documentation on all entities are generated (almost same as the Ruby parser).

構文解析される情報

以下の情報は, 自動的に構文解析されてコメント部として出力されます.

  • サブルーチン, 関数の引数のデータ型, 属性
  • 公開変数, 公開定数のデータ型, 属性
  • 構造データ型の要素のデータ型, 初期値, 属性
  • NAMELIST 文で宣言される変数名並びの変数のデータ型, 初期値, 属性

POINTER, TARGET, ALLOCATE, INTENT, OPTIONAL, SAVE 属性は 型宣言文とは別の行で指定することが可能ですが, それら型宣言文と別に指定される属性は構文解析されません.

INTERFACE 文によって, ある手続きに関して個別名とは別の名前を 宣言する場合, その別名も ‘Methods’ に追加します.

参照した別のモジュール内の公開言語要素 (サブルーチン, 関数, 変数など) を自身の言語要素として改めて公開する場合, その言語要素は自身の言語要素としてモジュールの ‘Methods’ リストに追加されます.

INTERFACE 文によって外部副プログラムを自身の副プログラムとして公開する 場合, その外部副プログラムもモジュールの ‘Methods’ リストに追加します.

Parsed information

The following information is automatically parsed.

  • Data types and attributes of arguments of functions and subprograms
  • Data types and attributes of public variables and public constants
  • Data types, initial values, and attributes of variables in the derived types
  • Data types, initial values, and attributes of variables declared in NAMELIST statement

Only attributes specified in type declaration statements are parsed. Attributes specified in POINTER, TARGET, ALLOCATE, INTENT, OPTIONAL, SAVE statements are not parsed.

Aliases declared by INTERFACE statements are described in the item of ‘Methods’.

Entities which are imported from other modules and published again are described in the item of ‘Methods’.

コメント部の書き方

コメント部は以下のように記述します. 原則的に行末または Fortran の文の下部にコメントを記述します. ’!’ を含まない行が現れた時点で, コメント部は終了したと見なされます. 例ではコメント行もインデントされていますが, インデントすることは 必須ではありません.

     ! (ファイルの行頭)
     !
     ! ファイルに対するコメントはここに記述します
     !
     !--
     ! "!--" と "!++" に囲まれた部分に記述されたコメントは
     ! ドキュメントに反映されません.
     !++
     !
     module hogehoge
       !
       ! モジュール (PROGRAM 文の場合は主プログラム)
       ! に対するコメントはここに記述します
       !

       private

       logical            :: a     ! 非公開変数
       real, public       :: b     ! 公開変数
       integer, parameter :: c = 0 ! 公開定数

       public :: c
       public :: MULTI_ARRAY
       public :: hoge, foo

       type MULTI_ARRAY
         !
         ! 構造データ型に対するコメントはここに記述します.
         !
         real, pointer :: var(:) =>null() ! 変数に対するコメント
         integer       :: num = 0
       end type MULTI_ARRAY

     contains

       subroutine hoge( in,   &   ! 継続行中のコメントは無視されます.
         &              out )
         !
         ! サブルーチンや関数に対するコメントはここに記述します
         !
         character(*),intent(in):: in ! 引数に対するコメント
         character(*),intent(out),allocatable,target  :: in
                                       ! 下の行に記述する
                                       ! ことも可能です.

         character(32) :: file ! NAMELIST 文の変数として構文解析されます
         integer       :: id

         namelist /varinfo_nml/ file, id
                 !
                 ! NAMELIST 文に関する情報はここに記述します. 変数に
                 ! 関する情報は, 変数定義部分を参照します.
                 !

       ....

       end subroutine hoge

       integer function foo( in )
         !
         ! この部分はコメントとして識別されます.

         ! '!' の間隔を空けると以降はコメントとして扱われません.
         ! つまりこの 2 行はコメントとして扱われません.
         !
         integer, intent(in):: inA ! コメントとして識別されます

                                   ! コメントとして識別されません.

       end function foo

       subroutine hide( in,   &
         &              out )      !:nodoc:
         !
         ! 上記のように, SUBROUTINE 文の末尾に
         ! "!:nodoc:" と記述することで, そのサブルーチン
         ! はドキュメントに反映されなくなります.
         ! この指定は, 主プログラム, モジュール, サブルーチン,
         ! 関数, 変数, 定数, 構造データ型, 利用者定義演算子,
         ! 利用者定義代入, 参照するモジュールのリスト (USE 文)
         ! に対して有効です.
         !

       ....

       end subroutine hide

     end module hogehoge

Format of comment blocks

Comment blocks should be written as follows. Comment blocks are considered to be ended when the line without ’!’ appears. The indentation is not necessary.

     ! (Top of file)
     !
     ! Comment blocks for the files.
     !
     !--
     ! The comment described in the part enclosed by
     ! "!--" and "!++" is ignored.
     !++
     !
     module hogehoge
       !
       ! Comment blocks for the modules (or the main programs).
       !

       private

       logical            :: a     ! a private variable
       real, public       :: b     ! a public variable
       integer, parameter :: c = 0 ! a public constant

       public :: c
       public :: MULTI_ARRAY
       public :: hoge, foo

       type MULTI_ARRAY
         !
         ! Comment blocks for the derived types.
         !
         real, pointer :: var(:) =>null() ! Comments block for the variables.
         integer       :: num = 0
       end type MULTI_ARRAY

     contains

       subroutine hoge( in,   &   ! Comment blocks between continuation lines are ignored.
           &            out )
         !
         ! Comment blocks for the subroutines or functions
         !
         character(*),intent(in):: in ! Comment blocks for the arguments.
         character(*),intent(out),allocatable,target  :: in
                                      ! Comment blocks can be
                                      ! written under Fortran statements.

         character(32) :: file ! This comment parsed as a variable in below NAMELIST.
         integer       :: id

         namelist /varinfo_nml/ file, id
                 !
                 ! Comment blocks for the NAMELIST statement.
                 ! Information about variables are described above.
                 !

       ....

       end subroutine hoge

       integer function foo( in )
         !
         ! This part is considered as comment block.

         ! Comment blocks under blank lines are ignored.
         !
         integer, intent(in):: inA ! This part is considered as comment block.

                                   ! This part is ignored.

       end function foo

       subroutine hide( in,   &
         &              out )      !:nodoc:
         !
         ! If "!:nodoc:" is described at end-of-line in SUBROUTINE
         ! statement as above, the subroutine is ignored.
         ! This assignment can be used to main programs, modules,
         ! subroutines, functions, variables, constants, derived types,
         ! defined operators, defined assignments,
         ! list of imported modules (USE statement).
         !

       ....

       end subroutine hide

     end module hogehoge

Required files

rdoc/code_objects  

[Validate]