Skip to content

Commit

Permalink
split sql language support into multiple subsets/dialects
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDittrich committed Nov 29, 2020
1 parent 4419718 commit 339ebf8
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

### Version 3.5.0 ###

* Added: dedicated MariaDB/MySQL language support `mariadb`
* Added: dedicated Oracle Database language support `oracledb` (no special rules yet)
* Added: dedicated MSSQL language support `mssql` (no special rules yet)
* Added: `constraints` to `sql`
* Changed: splitted sql language into several types/dialects for further extension
* Changed: removed pound style comments from generic `sql` support
* Changed: removed keywords `bigint` and `unsigned` from generic `sql` support
* Changed: `droide` theme color `#009999` to `#007f7f` for higher contrast (WCAG) - thanks to [aphelionz on GitHub](https://github.com/EnlighterJS/EnlighterJS/pull/117)
* Changed: in case of a tokenizer error, the tokenizer will silently fail (output to console) instead of throwing an error - code will still be displayed but related tokens are missing
* Bugfix: tokenizer loop limit was calculated in total instead of per-rule
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Features

#### Languages ####

* **ABAP** (abap)
* **Apache HTTPD** (apache)
* **Assembly** (assembly, asm)
* **AVR Assembly** (avrassembly, avrasm)
* **C/C++** (c,cpp, c++)
Expand All @@ -67,30 +69,41 @@ Features
* **Java** (java)
* **Javascript** (js, javascript, jquery, mootools, ext.js)
* **JSON** (json)
* **JSX** (jsx)
* **Kotlin** (kotlin)
* **LATEX** (latex)
* **LESS** (less)
* **lighttpd** (lighttpd)
* **LUA** (lua)
* **MariadDB** (mariadb)
* **Markdown** (gfm, md, markdown)
* **Matlab/Octave** (octave, matlab)
* **MSSQL** (mssql)
* **NGINX** (nginx)
* **NSIS** (nsis)
* **Oracle Database** (oracledb)
* **PHP** (php)
* **Powerhsell** (powershell)
* **Prolog** (prolog)
* **Python** (py, python)
* **PureBasic** (purebasic, pb)
* **QML** (qml)
* **R** (r)
* **RAW** (raw) - raw code without highlighting with EnlighterJS container styles!
* **RouterOS/SwitchOS** (routeros)
* **Ruby** (ruby)
* **Rust** (rust)
* **Scala** (scala)
* **SCSS** (scss, sass)
* **Shellscript** (shell, bash)
* **SQL** (sql)
* **Generic SQL** (sql)
* **Squirrel** (squirrel)
* **Swift** (swift)
* **Typescript** (typescript)
* **VHDL** (vhdl)
* **VisualBasic** (visualbasic, vb)
* **Verilog** (verilog)
* **XML** (xml)
* **XML** (xml, html)
* **YAML** (yaml)

#### Themes ####
Expand Down
2 changes: 1 addition & 1 deletion dist/enlighterjs.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/lang/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ export {latex} from './latex';
export {less} from './less';
export {lighttpd} from './lighttpd';
export {lua} from './lua';
export {mariadb} from './mariadb';
export {markdown} from './markdown';
export {matlab} from './matlab';
export {mssql} from './mssql';
export {nginx} from './nginx';
export {nsis} from './nsis';
export {oracledb} from './oracledb';
export {php} from './php';
export {powershell} from './powershell';
export {prolog} from './prolog';
Expand Down
49 changes: 49 additions & 0 deletions src/lang/mariadb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ----------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// Copyright 2016-2020 Andi Dittrich <https://andidittrich.de>
// ----------------------------------------------------------------------

// Generic Rules/Regex
import _language_common_rules from './rulesets/generic';
import {sql} from './sql';

// MariaDB MySQL Syntax
// Author: [Andi Dittrich]
// --
export class mariadb extends sql {

// language aliases
static alias(){
return ['mysql'];
}

setupLanguage(){
// setup css
super.setupLanguage();

// addon rules
const addonRules = [
// single line comments
_language_common_rules.poundComments,

// static numeric types
{
regex: /\b(tinyint|smallint|mediumint|bigint|int|integer|boolean|decimal|number|float|double|bit|double precision|real|dec|numeric|fixed)\b/g,
type: 'k5'
},

// qualifier/modifier
{
regex: /\b(unsigned|signed|zerofill)\b/g,
type: 'k8'
}

];

// push to css rule-set
this.rules = this.rules.concat(addonRules);
}
}
29 changes: 29 additions & 0 deletions src/lang/mssql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ----------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// Copyright 2016-2020 Andi Dittrich <https://andidittrich.com>
// ----------------------------------------------------------------------

// Generic Rules/Regex
//import _language_common_rules from './rulesets/generic';
import {sql} from './sql';

// Oracle Database Syntax
// Author: [Andi Dittrich]
// --
export class mssql extends sql {

setupLanguage(){
// setup css
super.setupLanguage();

// addon rules
const addonRules = [
];

// push to css rule-set
this.rules = this.rules.concat(addonRules);
}
}
34 changes: 34 additions & 0 deletions src/lang/oracledb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ----------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// Copyright 2016-2020 Andi Dittrich <https://andidittrich.com>
// ----------------------------------------------------------------------

// Generic Rules/Regex
//import _language_common_rules from './rulesets/generic';
import {sql} from './sql';

// Oracle Database Syntax
// Author: [Andi Dittrich]
// --
export class oracledb extends sql {

// language aliases
static alias(){
return ['oracle'];
}

setupLanguage(){
// setup css
super.setupLanguage();

// addon rules
const addonRules = [
];

// push to css rule-set
this.rules = this.rules.concat(addonRules);
}
}
23 changes: 8 additions & 15 deletions src/lang/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export class sql extends generic {

this.rules = [

// general comments
_language_common_rules.poundComments,
// multiline comments
_language_common_rules.blockComments,

// -- style comments
Expand All @@ -35,6 +34,12 @@ export class sql extends generic {
// values
_language_common_rules.sqStrings,

// constraints
{
regex: /\b(NOT NULL|UNIQUE|PRIMARY KEY|FOREIGN KEY|CHECK|DEFAULT|INDEX)\b/gi,
type: 'k4'
},

// column name literals
{
regex: /`\S+?`(?:\.`\S+?`)*/g,
Expand All @@ -43,22 +48,10 @@ export class sql extends generic {

// operators
{
regex: /\b(all|and|any|between|exists|in|like|not|or|is null|is not null|unique|=|!=|<>|>|<|>=|<=|!<|!>)\b/gi,
regex: /\b(all|and|any|between|exists|in|like|not|or|is null|is not null|=|!=|<>|>|<|>=|<=|!<|!>)\b/gi,
type: 'k3'
},

// static types
{
regex: /\b(bigint)\b/g,
type: 'k5'
},

// qualifier/modifier
{
regex: /\b(unsigned)\b/g,
type: 'k8'
},

// common keyword set
{
regex: /\b(SELECT|INSERT|UPDATE|DELETE|INTO|FROM|CREATE|TABLE|VIEW|WHERE|TRIGGER|ALTER|ORDER BY|DESC|ASC|AS|BETWEEN|JOIN|LEFT|RIGHT|INNER|OUTER|USING|ON|UNION)\b/gi,
Expand Down

0 comments on commit 339ebf8

Please sign in to comment.