Skip to content

Commit

Permalink
Fortran: fixed support of "dotted" keywords/literals (#4043)
Browse files Browse the repository at this point in the history
* Fortran: fixed support of "dotted" keywords

This patch adds a pattern to correctly match
keywords delimited by dots (.).
The pattern also follows the following rules from
the format:
- keywords names start with a letter (or dot).
- names should only contain latin characters,
  digits or the underscore symbol.
- identifiers starting with a dot must end with a
  dot.
  • Loading branch information
jbloino committed Apr 26, 2024
1 parent 583cb33 commit ea6ad28
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -39,6 +39,7 @@ Core Grammars:
- enh(markdown) add entity support [David Schach][] [TaraLei][]
- enh(css) add `justify-items` and `justify-self` attributes [Vasily Polovnyov][]
- enh(css) add `accent-color`, `appearance`, `color-scheme`, `rotate`, `scale` and `translate` attributes [Carl Räfting][]
- fix(fortran) fixes parsing of keywords delimited by dots [Julien Bloino][]

New Grammars:

Expand Down Expand Up @@ -90,6 +91,7 @@ Themes:
[Rúnar Bjarnason]: https://github.com/runarorama
[Carl Räfting]: https://github.com/carlrafting
[BackupMiles]: https://github.com/BackupMiles
[Julien Bloino]: https://github.com/jbloino



Expand Down
1 change: 1 addition & 0 deletions src/languages/fortran.js
Expand Up @@ -550,6 +550,7 @@ export default function(hljs) {
'f95'
],
keywords: {
$pattern: /\b[a-z][a-z0-9_]+\b|\.[a-z][a-z0-9_]+\./,
keyword: KEYWORDS,
literal: LITERALS,
built_in: BUILT_INS
Expand Down
8 changes: 8 additions & 0 deletions test/markup/fortran/dot_keywords.expect.txt
@@ -0,0 +1,8 @@
<span class="hljs-keyword">logical</span> :: A=<span class="hljs-literal">.true.</span>, B=<span class="hljs-literal">.false.</span>, C=<span class="hljs-literal">.true.</span>, D=<span class="hljs-literal">.false.</span>
<span class="hljs-keyword">logical</span> :: E

E = <span class="hljs-number">3</span> &lt; <span class="hljs-number">4</span> <span class="hljs-keyword">.and.</span> B
E = <span class="hljs-string">&#x27;ij&#x27;</span> &lt;= <span class="hljs-string">&#x27;ijk&#x27;</span> <span class="hljs-keyword">.and.</span> C
E = B <span class="hljs-keyword">.or.</span> A <span class="hljs-keyword">.and.</span> D
E = (B <span class="hljs-keyword">.or.</span> A) <span class="hljs-keyword">.and.</span> C
E = A <span class="hljs-keyword">.and.</span> <span class="hljs-keyword">.not.</span>B
8 changes: 8 additions & 0 deletions test/markup/fortran/dot_keywords.txt
@@ -0,0 +1,8 @@
logical :: A=.true., B=.false., C=.true., D=.false.
logical :: E

E = 3 < 4 .and. B
E = 'ij' <= 'ijk' .and. C
E = B .or. A .and. D
E = (B .or. A) .and. C
E = A .and. .not.B

0 comments on commit ea6ad28

Please sign in to comment.