From ea6ad285eba9c4450d299189a17cbf94234c3ed5 Mon Sep 17 00:00:00 2001 From: Julien Bloino <32259693+jbloino@users.noreply.github.com> Date: Sat, 27 Apr 2024 01:41:04 +0200 Subject: [PATCH] Fortran: fixed support of "dotted" keywords/literals (#4043) * 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. --- CHANGES.md | 2 ++ src/languages/fortran.js | 1 + test/markup/fortran/dot_keywords.expect.txt | 8 ++++++++ test/markup/fortran/dot_keywords.txt | 8 ++++++++ 4 files changed, 19 insertions(+) create mode 100644 test/markup/fortran/dot_keywords.expect.txt create mode 100644 test/markup/fortran/dot_keywords.txt diff --git a/CHANGES.md b/CHANGES.md index 7e109ef88a..eb09ba1b6b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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: @@ -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 diff --git a/src/languages/fortran.js b/src/languages/fortran.js index 91b8f46598..aa3d2b4fc0 100644 --- a/src/languages/fortran.js +++ b/src/languages/fortran.js @@ -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 diff --git a/test/markup/fortran/dot_keywords.expect.txt b/test/markup/fortran/dot_keywords.expect.txt new file mode 100644 index 0000000000..e973e13bf0 --- /dev/null +++ b/test/markup/fortran/dot_keywords.expect.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 diff --git a/test/markup/fortran/dot_keywords.txt b/test/markup/fortran/dot_keywords.txt new file mode 100644 index 0000000000..63d0aa4d00 --- /dev/null +++ b/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