irpf90.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * @param {string} value
  3. * @returns {RegExp}
  4. * */
  5. /**
  6. * @param {RegExp | string } re
  7. * @returns {string}
  8. */
  9. function source(re) {
  10. if (!re) return null;
  11. if (typeof re === "string") return re;
  12. return re.source;
  13. }
  14. /**
  15. * @param {...(RegExp | string) } args
  16. * @returns {string}
  17. */
  18. function concat(...args) {
  19. const joined = args.map((x) => source(x)).join("");
  20. return joined;
  21. }
  22. /*
  23. Language: IRPF90
  24. Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
  25. Description: IRPF90 is an open-source Fortran code generator
  26. Website: http://irpf90.ups-tlse.fr
  27. Category: scientific
  28. */
  29. /** @type LanguageFn */
  30. function irpf90(hljs) {
  31. const PARAMS = {
  32. className: 'params',
  33. begin: '\\(',
  34. end: '\\)'
  35. };
  36. // regex in both fortran and irpf90 should match
  37. const OPTIONAL_NUMBER_SUFFIX = /(_[a-z_\d]+)?/;
  38. const OPTIONAL_NUMBER_EXP = /([de][+-]?\d+)?/;
  39. const NUMBER = {
  40. className: 'number',
  41. variants: [
  42. {
  43. begin: concat(/\b\d+/, /\.(\d*)/, OPTIONAL_NUMBER_EXP, OPTIONAL_NUMBER_SUFFIX)
  44. },
  45. {
  46. begin: concat(/\b\d+/, OPTIONAL_NUMBER_EXP, OPTIONAL_NUMBER_SUFFIX)
  47. },
  48. {
  49. begin: concat(/\.\d+/, OPTIONAL_NUMBER_EXP, OPTIONAL_NUMBER_SUFFIX)
  50. }
  51. ],
  52. relevance: 0
  53. };
  54. const F_KEYWORDS = {
  55. literal: '.False. .True.',
  56. keyword: 'kind do while private call intrinsic where elsewhere ' +
  57. 'type endtype endmodule endselect endinterface end enddo endif if forall endforall only contains default return stop then ' +
  58. 'public subroutine|10 function program .and. .or. .not. .le. .eq. .ge. .gt. .lt. ' +
  59. 'goto save else use module select case ' +
  60. 'access blank direct exist file fmt form formatted iostat name named nextrec number opened rec recl sequential status unformatted unit ' +
  61. 'continue format pause cycle exit ' +
  62. 'c_null_char c_alert c_backspace c_form_feed flush wait decimal round iomsg ' +
  63. 'synchronous nopass non_overridable pass protected volatile abstract extends import ' +
  64. 'non_intrinsic value deferred generic final enumerator class associate bind enum ' +
  65. '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 ' +
  66. '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 ' +
  67. 'c_long_double c_float_complex c_double_complex c_long_double_complex c_bool c_char c_null_ptr c_null_funptr ' +
  68. 'c_new_line c_carriage_return c_horizontal_tab c_vertical_tab iso_c_binding c_loc c_funloc c_associated c_f_pointer ' +
  69. 'c_ptr c_funptr iso_fortran_env character_storage_size error_unit file_storage_size input_unit iostat_end iostat_eor ' +
  70. 'numeric_storage_size output_unit c_f_procpointer ieee_arithmetic ieee_support_underflow_control ' +
  71. 'ieee_get_underflow_mode ieee_set_underflow_mode newunit contiguous recursive ' +
  72. 'pad position action delim readwrite eor advance nml interface procedure namelist include sequence elemental pure ' +
  73. 'integer real character complex logical dimension allocatable|10 parameter ' +
  74. 'external implicit|10 none double precision assign intent optional pointer ' +
  75. 'target in out common equivalence data ' +
  76. // IRPF90 special keywords
  77. 'begin_provider &begin_provider end_provider begin_shell end_shell begin_template end_template subst assert touch ' +
  78. 'soft_touch provide no_dep free irp_if irp_else irp_endif irp_write irp_read',
  79. 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 ' +
  80. 'dlog dlog10 dmax1 dmin1 dmod dnint dsign dsin dsinh dsqrt dtan dtanh float iabs idim idint idnint ifix isign max0 max1 min0 min1 sngl ' +
  81. 'algama cdabs cdcos cdexp cdlog cdsin cdsqrt cqabs cqcos cqexp cqlog cqsin cqsqrt dcmplx dconjg derf derfc dfloat dgamma dimag dlgama ' +
  82. 'iqint qabs qacos qasin qatan qatan2 qcmplx qconjg qcos qcosh qdim qerf qerfc qexp qgamma qimag qlgama qlog qlog10 qmax1 qmin1 qmod ' +
  83. '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 ' +
  84. 'log10 max min nint sign sin sinh sqrt tan tanh print write dim lge lgt lle llt mod nullify allocate deallocate ' +
  85. 'adjustl adjustr all allocated any associated bit_size btest ceiling count cshift date_and_time digits dot_product ' +
  86. 'eoshift epsilon exponent floor fraction huge iand ibclr ibits ibset ieor ior ishft ishftc lbound len_trim matmul ' +
  87. 'maxexponent maxloc maxval merge minexponent minloc minval modulo mvbits nearest pack present product ' +
  88. 'radix random_number random_seed range repeat reshape rrspacing scale scan selected_int_kind selected_real_kind ' +
  89. 'set_exponent shape size spacing spread sum system_clock tiny transpose trim ubound unpack verify achar iachar transfer ' +
  90. 'dble entry dprod cpu_time command_argument_count get_command get_command_argument get_environment_variable is_iostat_end ' +
  91. 'ieee_arithmetic ieee_support_underflow_control ieee_get_underflow_mode ieee_set_underflow_mode ' +
  92. 'is_iostat_eor move_alloc new_line selected_char_kind same_type_as extends_type_of ' +
  93. 'acosh asinh atanh bessel_j0 bessel_j1 bessel_jn bessel_y0 bessel_y1 bessel_yn erf erfc erfc_scaled gamma log_gamma hypot norm2 ' +
  94. 'atomic_define atomic_ref execute_command_line leadz trailz storage_size merge_bits ' +
  95. 'bge bgt ble blt dshiftl dshiftr findloc iall iany iparity image_index lcobound ucobound maskl maskr ' +
  96. 'num_images parity popcnt poppar shifta shiftl shiftr this_image ' +
  97. // IRPF90 special built_ins
  98. 'IRP_ALIGN irp_here'
  99. };
  100. return {
  101. name: 'IRPF90',
  102. case_insensitive: true,
  103. keywords: F_KEYWORDS,
  104. illegal: /\/\*/,
  105. contains: [
  106. hljs.inherit(hljs.APOS_STRING_MODE, {
  107. className: 'string',
  108. relevance: 0
  109. }),
  110. hljs.inherit(hljs.QUOTE_STRING_MODE, {
  111. className: 'string',
  112. relevance: 0
  113. }),
  114. {
  115. className: 'function',
  116. beginKeywords: 'subroutine function program',
  117. illegal: '[${=\\n]',
  118. contains: [
  119. hljs.UNDERSCORE_TITLE_MODE,
  120. PARAMS
  121. ]
  122. },
  123. hljs.COMMENT('!', '$', {
  124. relevance: 0
  125. }),
  126. hljs.COMMENT('begin_doc', 'end_doc', {
  127. relevance: 10
  128. }),
  129. NUMBER
  130. ]
  131. };
  132. }
  133. module.exports = irpf90;