Path: | parsers/parse_f95.rb |
Last Update: | Mon Nov 28 15:17:47 JST 2005 |
parse_f95.rb は拡張子が f90, F90, f95, F95 のファイルを構文分析します. ソースコードは Fortran 95 規格で推奨される書法で記述されることを 前提としています.
"parse_f95.rb" parses Fortran95 files with suffixes "f90", "F90", "f95" and "F95". Fortran95 files are expected to be conformed to Fortran95 standards.
基本的な書法はRuby の書法 と同様ですが, コメント部は ’#’ ではなく ’!’ で始まることに注意してください.
Fundamental rules are same as that of the Ruby parser. But comment markers are ’!’ not ’#’.
parse_f95.rb はメインプログラム, モジュール, サブルーチン, 関数の他, public 指定によって公開される変数や定数, そして利用者定義演算子, 利用者定義代入を構文分析します. これらの要素は RDOC ドキュメンテーションの各項目に, 以下のように記述されます.
Files : | ファイル (Ruby と同様です) |
Classes : | モジュール |
Methods : | サブルーチン, 関数, 変数, 定数, 構造体, 利用者定義演算子, 利用者定義代入 |
Required files : | 参照するモジュールが定義されているファイル, 及び参照する外部関数が定義されているファイルのリスト |
Included Modules : | 参照するモジュールのリスト |
Attributes : | 構造体のリスト, 参照し且つその全ての要素を公開するモジュールのリスト |
‘Methods’ にリストされる要素 (サブルーチン, 関数, …) は, モジュール内で定義されているのであれば, ‘Classes’ の項目に記述されます. メインプログラム内で定義されたり, 外部手続きとして定義される場合には ‘Files’ の項目に記述されます.
"parse_f95.rb" parses main programs, modules, subroutines, functions, derived-types, public variables, public constants, defined operators and defined assignments. These components are described in items of RDoc documentation, as follows.
Files : | Files (same as Ruby) |
Classes : | Modules |
Methods : | Subroutines, functions, variables, constants, derived-types, defined operators, defined assignments |
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 |
Components listed in ‘Methods’ (subroutines, functions, …) defined in modules are described in the item of ‘Classes’. On the other hand, components defined in main programs or as external procedures are described in the item of ‘Files’.
デフォルトでは, public 属性を持ち, 外部から参照が可能なサブルーチン, 関数, 変数, 定数, 構造体, 利用者定義演算子, 利用者定義代入のみドキュメントとして出力されます. —all オプションをつけて rdoc を実行する場合には private 属性を 明示的に指定されるものも含め, 全てが出力されます.
By default, documentation on public components (subroutines, functions, variables, constants, derived-types, defined operators, defined assignments) are generated. With "—all" option, documentation on all components are generated (almost same as the Ruby parser).
以下の情報は, 自動的に構文分析されてコメント部として出力されます.
interface によって別名を指定する場合, その別名も ‘Methods’ に 追加します.
参照した別のモジュール内の公開要素 (サブルーチン, 関数, …) を自身の要素として改めて公開する場合, その要素は自身の要素としてモジュールの ‘Methods’ リストに追加されます.
interface によって外部副プログラムを自身の副プログラムとして公開する 場合, その外部副プログラムもモジュールの ‘Methods’ リストに追加します.
The following information is automatically parsed.
Aliases by interface statement are described in the item of ‘Methods’.
Components 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
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. ! module hogehoge ! ! Comment blocks for the modules (or the 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 NAMELISTs. ! 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 modules, subroutines, ! functions, variables, constants, derived-types, ! defined operators, defined assignments, ! list of imported modules ("use" statement). ! .... end subroutine hide end module hogehoge