fortran.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Language: Fortran
  3. Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
  4. Website: https://en.wikipedia.org/wiki/Fortran
  5. Category: scientific
  6. */
  7. function fortran(hljs) {
  8. const PARAMS = {
  9. className: 'params',
  10. begin: '\\(', end: '\\)'
  11. };
  12. const COMMENT = {
  13. variants: [
  14. hljs.COMMENT('!', '$', {relevance: 0}),
  15. // allow Fortran 77 style comments
  16. hljs.COMMENT('^C', '$', {relevance: 0})
  17. ]
  18. };
  19. const NUMBER = {
  20. className: 'number',
  21. // regex in both fortran and irpf90 should match
  22. begin: '(?=\\b|\\+|\\-|\\.)(?:\\.|\\d+\\.?)\\d*([de][+-]?\\d+)?(_[a-z_\\d]+)?',
  23. relevance: 0
  24. };
  25. const FUNCTION_DEF = {
  26. className: 'function',
  27. beginKeywords: 'subroutine function program',
  28. illegal: '[${=\\n]',
  29. contains: [hljs.UNDERSCORE_TITLE_MODE, PARAMS]
  30. };
  31. const STRING = {
  32. className: 'string',
  33. relevance: 0,
  34. variants: [
  35. hljs.APOS_STRING_MODE,
  36. hljs.QUOTE_STRING_MODE
  37. ]
  38. };
  39. const KEYWORDS = {
  40. literal: '.False. .True.',
  41. keyword: 'kind do concurrent local shared while private call intrinsic where elsewhere ' +
  42. 'type endtype endmodule endselect endinterface end enddo endif if forall endforall only contains default return stop then block endblock endassociate ' +
  43. 'public subroutine|10 function program .and. .or. .not. .le. .eq. .ge. .gt. .lt. ' +
  44. 'goto save else use module select case ' +
  45. 'access blank direct exist file fmt form formatted iostat name named nextrec number opened rec recl sequential status unformatted unit ' +
  46. 'continue format pause cycle exit ' +
  47. 'c_null_char c_alert c_backspace c_form_feed flush wait decimal round iomsg ' +
  48. 'synchronous nopass non_overridable pass protected volatile abstract extends import ' +
  49. 'non_intrinsic value deferred generic final enumerator class associate bind enum ' +
  50. 'c_int c_short c_long c_long_long c_signed_char c_size_t c_int8_t c_int16_t c_int32_t c_int64_t c_int_least8_t c_int_least16_t ' +
  51. 'c_int_least32_t c_int_least64_t c_int_fast8_t c_int_fast16_t c_int_fast32_t c_int_fast64_t c_intmax_t C_intptr_t c_float c_double ' +
  52. 'c_long_double c_float_complex c_double_complex c_long_double_complex c_bool c_char c_null_ptr c_null_funptr ' +
  53. 'c_new_line c_carriage_return c_horizontal_tab c_vertical_tab iso_c_binding c_loc c_funloc c_associated c_f_pointer ' +
  54. 'c_ptr c_funptr iso_fortran_env character_storage_size error_unit file_storage_size input_unit iostat_end iostat_eor ' +
  55. 'numeric_storage_size output_unit c_f_procpointer ieee_arithmetic ieee_support_underflow_control ' +
  56. 'ieee_get_underflow_mode ieee_set_underflow_mode newunit contiguous recursive ' +
  57. 'pad position action delim readwrite eor advance nml interface procedure namelist include sequence elemental pure impure ' +
  58. 'integer real character complex logical codimension dimension allocatable|10 parameter ' +
  59. 'external implicit|10 none double precision assign intent optional pointer ' +
  60. 'target in out common equivalence data',
  61. built_in: 'alog alog10 amax0 amax1 amin0 amin1 amod cabs ccos cexp clog csin csqrt dabs dacos dasin datan datan2 dcos dcosh ddim dexp dint ' +
  62. 'dlog dlog10 dmax1 dmin1 dmod dnint dsign dsin dsinh dsqrt dtan dtanh float iabs idim idint idnint ifix isign max0 max1 min0 min1 sngl ' +
  63. 'algama cdabs cdcos cdexp cdlog cdsin cdsqrt cqabs cqcos cqexp cqlog cqsin cqsqrt dcmplx dconjg derf derfc dfloat dgamma dimag dlgama ' +
  64. 'iqint qabs qacos qasin qatan qatan2 qcmplx qconjg qcos qcosh qdim qerf qerfc qexp qgamma qimag qlgama qlog qlog10 qmax1 qmin1 qmod ' +
  65. 'qnint qsign qsin qsinh qsqrt qtan qtanh abs acos aimag aint anint asin atan atan2 char cmplx conjg cos cosh exp ichar index int log ' +
  66. 'log10 max min nint sign sin sinh sqrt tan tanh print write dim lge lgt lle llt mod nullify allocate deallocate ' +
  67. 'adjustl adjustr all allocated any associated bit_size btest ceiling count cshift date_and_time digits dot_product ' +
  68. 'eoshift epsilon exponent floor fraction huge iand ibclr ibits ibset ieor ior ishft ishftc lbound len_trim matmul ' +
  69. 'maxexponent maxloc maxval merge minexponent minloc minval modulo mvbits nearest pack present product ' +
  70. 'radix random_number random_seed range repeat reshape rrspacing scale scan selected_int_kind selected_real_kind ' +
  71. 'set_exponent shape size spacing spread sum system_clock tiny transpose trim ubound unpack verify achar iachar transfer ' +
  72. 'dble entry dprod cpu_time command_argument_count get_command get_command_argument get_environment_variable is_iostat_end ' +
  73. 'ieee_arithmetic ieee_support_underflow_control ieee_get_underflow_mode ieee_set_underflow_mode ' +
  74. 'is_iostat_eor move_alloc new_line selected_char_kind same_type_as extends_type_of ' +
  75. 'acosh asinh atanh bessel_j0 bessel_j1 bessel_jn bessel_y0 bessel_y1 bessel_yn erf erfc erfc_scaled gamma log_gamma hypot norm2 ' +
  76. 'atomic_define atomic_ref execute_command_line leadz trailz storage_size merge_bits ' +
  77. 'bge bgt ble blt dshiftl dshiftr findloc iall iany iparity image_index lcobound ucobound maskl maskr ' +
  78. 'num_images parity popcnt poppar shifta shiftl shiftr this_image sync change team co_broadcast co_max co_min co_sum co_reduce'
  79. };
  80. return {
  81. name: 'Fortran',
  82. case_insensitive: true,
  83. aliases: ['f90', 'f95'],
  84. keywords: KEYWORDS,
  85. illegal: /\/\*/,
  86. contains: [
  87. STRING,
  88. FUNCTION_DEF,
  89. // allow `C = value` for assignments so they aren't misdetected
  90. // as Fortran 77 style comments
  91. {
  92. begin: /^C\s*=(?!=)/,
  93. relevance: 0,
  94. },
  95. COMMENT,
  96. NUMBER
  97. ]
  98. };
  99. }
  100. module.exports = fortran;