Skip to content

Commit

Permalink
(chore) Create c-like and c/cpp depend on that now
Browse files Browse the repository at this point in the history
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][]
- chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][]
- chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][]
- This will allow us to clean up C/C++ in the future without another breaking change
  by getting this require change out of the way early.
  (#2146)
  • Loading branch information
joshgoebel committed Jan 31, 2020
1 parent cf1349c commit ff66769
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
6 changes: 6 additions & 0 deletions VERSION_10_BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Incompatibilities:
Renamed Language Files:
- chore(parser): rename `cs.js` to `csharp.js` [Josh Goebel][]
- chore(parser): rename `tex.js` to `latex.js` [Josh Goebel][]
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][]
- chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][]
- chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][]
- This will allow us to clean up C/C++ in the future without another breaking change
by getting this require change out of the way early.
(https://github.com/highlightjs/highlight.js/issues/2146)

Legacy Browser Issues:
- **We're now using ES2015 features in the codebase. Internet Explorer 11 is no longer supported.**
Expand Down
14 changes: 12 additions & 2 deletions src/languages/c-like.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/*
Language: C++
Language: C-like foundation grammar for C/C++ grammars
Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
Contributors: Evgeny Stepanischev <imbolk@gmail.com>, Zaven Muradyan <megalivoithos@gmail.com>, Roel Deckers <admin@codingcat.nl>, Sam Wu <samsam2310@gmail.com>, Jordi Petit <jordi.petit@gmail.com>, Pieter Vantorre <pietervantorre@gmail.com>, Google Inc. (David Benjamin) <davidben@google.com>
Category: common, system
Website: https://isocpp.org
*/

/* In the future the intention is to split out the C/C++ grammars distinctly
since they are separate languages. They will likely share a common foundation
though, and this file sets the groundwork for that - so that we get the breaking
change in v10 and don't have to change the requirements again later.
See: https://github.com/highlightjs/highlight.js/issues/2146
*/

function(hljs) {
Expand Down Expand Up @@ -192,6 +199,9 @@ function(hljs) {
return {
aliases: ['c', 'cc', 'h', 'c++', 'h++', 'hpp', 'hh', 'hxx', 'cxx'],
keywords: CPP_KEYWORDS,
// the base c-like language will NEVER be auto-detected, rather the
// derivitives: c, c++, arduino turn auto-detect back on for themselves
disableAutodetect: true,
illegal: '</',
contains: [].concat(
EXPRESSION_CONTEXT,
Expand Down
20 changes: 20 additions & 0 deletions src/languages/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Language: C
Category: common, system
Website: https://en.wikipedia.org/wiki/C_(programming_language)
Requires: c-like.js
*/

function(hljs) {

var lang = hljs.getLanguage('c-like').rawDefinition();
// Until C is actually different than C++ there is no reason to auto-detect C
// as it's own language since it would just fail auto-detect testing or
// simply match with C++.
//
// See further comments in c-like.js.

// lang.disableAutodetect = false;
return lang;

}
15 changes: 15 additions & 0 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Language: C++
Category: common, system
Website: https://isocpp.org
Requires: c-like.js
*/

function(hljs) {

var lang = hljs.getLanguage('c-like').rawDefinition();
// return auto-detection back on
lang.disableAutodetect = false;
return lang;

}
8 changes: 8 additions & 0 deletions tools/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ tasks.reorderDeps = function(options, blobs, done) {
if(buf.Requires) {
_.each(buf.Requires, function(language) {
object = buffer[language];
// go a second level deep for dependencies
// (new build system will eliminate this)
if (object.Requires) {
_.each(object.Requires, function(language) {
let object = buffer[language];
pushInBlob(object);
});
}
pushInBlob(object);
});
}
Expand Down

0 comments on commit ff66769

Please sign in to comment.