Skip to content

Commit

Permalink
enh(fortran) Add support for FORTRAN 77 style comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Feb 20, 2020
1 parent effa09a commit 1335ccd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/languages/fortran.js
Expand Up @@ -11,6 +11,14 @@ export default function(hljs) {
begin: '\\(', end: '\\)'
};

var COMMENT = {
variants: [
hljs.COMMENT('!', '$', {relevance: 0}),
// allow Fortran 77 style comments
hljs.COMMENT('^C', '$', {relevance: 0})
]
}

var F_KEYWORDS = {
literal: '.False. .True.',
keyword: 'kind do concurrent local shared while private call intrinsic where elsewhere ' +
Expand Down Expand Up @@ -66,7 +74,13 @@ export default function(hljs) {
illegal: '[${=\\n]',
contains: [hljs.UNDERSCORE_TITLE_MODE, PARAMS]
},
hljs.COMMENT('!', '$', {relevance: 0}),
// allow C = value for assignments so they aren't misdetected
// as Fortran 77 style comments
{
begin: /^C\s*=(?!=)/,
relevance:0,
},
COMMENT,
{
className: 'number',
// regex in both fortran and irpf90 should match
Expand Down
13 changes: 13 additions & 0 deletions test/markup/fortran/comments.expect.txt
@@ -0,0 +1,13 @@
<span class="hljs-comment">C</span>
<span class="hljs-comment">C This program in FORTRAN 77 outputs "Hello, World!".</span>
<span class="hljs-comment">C ====================================================</span>

<span class="hljs-comment">!===============================</span>
<span class="hljs-comment">! This is a test subroutine</span>
<span class="hljs-comment">!===============================</span>

<span class="hljs-comment">! another comment</span>

C=<span class="hljs-number">2</span>
C = <span class="hljs-number">2</span> <span class="hljs-comment">!correct</span>
C =<span class="hljs-string">'boo'</span>
13 changes: 13 additions & 0 deletions 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'

0 comments on commit 1335ccd

Please sign in to comment.