diff --git a/CHANGES.md b/CHANGES.md
index 263ab55bea..61271a7d2f 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -16,6 +16,7 @@ Core Changes:
Language Improvements:
+- enh(fortran) Support Fortran 77 style comments (#2416) [Josh Goebel][]
- (csharp) add support for `@identifier` style identifiers (#2414) [Josh Goebel][]
- fix(elixir) Support function names with a slash (#2406) [Josh Goebel][]
- fix(javascript) comma is allowed in a "value container" (#2403) [Josh Goebel][]
diff --git a/src/languages/fortran.js b/src/languages/fortran.js
index 79de28a675..fc5ebeaa5f 100644
--- a/src/languages/fortran.js
+++ b/src/languages/fortran.js
@@ -6,12 +6,43 @@ Category: scientific
*/
export default function(hljs) {
- var PARAMS = {
+ const PARAMS = {
className: 'params',
begin: '\\(', end: '\\)'
};
- var F_KEYWORDS = {
+ const COMMENT = {
+ variants: [
+ hljs.COMMENT('!', '$', {relevance: 0}),
+ // allow Fortran 77 style comments
+ hljs.COMMENT('^C', '$', {relevance: 0})
+ ]
+ };
+
+ const NUMBER = {
+ className: 'number',
+ // regex in both fortran and irpf90 should match
+ begin: '(?=\\b|\\+|\\-|\\.)(?:\\.|\\d+\\.?)\\d*([de][+-]?\\d+)?(_[a-z_\\d]+)?',
+ relevance: 0
+ };
+
+ const FUNCTION_DEF = {
+ className: 'function',
+ beginKeywords: 'subroutine function program',
+ illegal: '[${=\\n]',
+ contains: [hljs.UNDERSCORE_TITLE_MODE, PARAMS]
+ };
+
+ const STRING = {
+ className: 'string',
+ relevance: 0,
+ variants: [
+ hljs.APOS_STRING_MODE,
+ hljs.QUOTE_STRING_MODE
+ ]
+ };
+
+ const KEYWORDS = {
literal: '.False. .True.',
keyword: 'kind do concurrent local shared while private call intrinsic where elsewhere ' +
'type endtype endmodule endselect endinterface end enddo endif if forall endforall only contains default return stop then block endblock endassociate ' +
@@ -46,7 +77,7 @@ export default function(hljs) {
'set_exponent shape size spacing spread sum system_clock tiny transpose trim ubound unpack verify achar iachar transfer ' +
'dble entry dprod cpu_time command_argument_count get_command get_command_argument get_environment_variable is_iostat_end ' +
'ieee_arithmetic ieee_support_underflow_control ieee_get_underflow_mode ieee_set_underflow_mode ' +
- 'is_iostat_eor move_alloc new_line selected_char_kind same_type_as extends_type_of' +
+ 'is_iostat_eor move_alloc new_line selected_char_kind same_type_as extends_type_of ' +
'acosh asinh atanh bessel_j0 bessel_j1 bessel_jn bessel_y0 bessel_y1 bessel_yn erf erfc erfc_scaled gamma log_gamma hypot norm2 ' +
'atomic_define atomic_ref execute_command_line leadz trailz storage_size merge_bits ' +
'bge bgt ble blt dshiftl dshiftr findloc iall iany iparity image_index lcobound ucobound maskl maskr ' +
@@ -56,24 +87,19 @@ export default function(hljs) {
name: 'Fortran',
case_insensitive: true,
aliases: ['f90', 'f95'],
- keywords: F_KEYWORDS,
+ keywords: KEYWORDS,
illegal: /\/\*/,
contains: [
- hljs.inherit(hljs.APOS_STRING_MODE, {className: 'string', relevance: 0}),
- hljs.inherit(hljs.QUOTE_STRING_MODE, {className: 'string', relevance: 0}),
+ STRING,
+ FUNCTION_DEF,
+ // allow `C = value` for assignments so they aren't misdetected
+ // as Fortran 77 style comments
{
- className: 'function',
- beginKeywords: 'subroutine function program',
- illegal: '[${=\\n]',
- contains: [hljs.UNDERSCORE_TITLE_MODE, PARAMS]
+ begin: /^C\s*=(?!=)/,
+ relevance: 0,
},
- hljs.COMMENT('!', '$', {relevance: 0}),
- {
- className: 'number',
- // regex in both fortran and irpf90 should match
- begin: '(?=\\b|\\+|\\-|\\.)(?:\\.|\\d+\\.?)\\d*([de][+-]?\\d+)?(_[a-z_\\d]+)?',
- relevance: 0
- }
+ COMMENT,
+ NUMBER
]
};
}
diff --git a/test/markup/fortran/comments.expect.txt b/test/markup/fortran/comments.expect.txt
new file mode 100644
index 0000000000..ba78a37f63
--- /dev/null
+++ b/test/markup/fortran/comments.expect.txt
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+C=2
+C = 2
+C ='boo'
diff --git a/test/markup/fortran/comments.txt b/test/markup/fortran/comments.txt
new file mode 100644
index 0000000000..6127dbc32e
--- /dev/null
+++ b/test/markup/fortran/comments.txt
@@ -0,0 +1,13 @@
+C
+C This program in FORTRAN 77 outputs "Hello, World!".
+C ====================================================
+
+ !===============================
+ ! This is a test subroutine
+ !===============================
+
+! another comment
+
+C=2
+C = 2 !correct
+C ='boo'