|
| 1 | +// ---------------------------------------------------------------------- |
| 2 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | +// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | +// -- |
| 6 | +// Copyright 2016-2018 Andi Dittrich <https://andidittrich.de> |
| 7 | +// Copyright 2019 Yunhao Tian |
| 8 | +// ---------------------------------------------------------------------- |
| 9 | + |
| 10 | +// Generic Rules/Regex |
| 11 | +import _language_common_rules from '../engine/generic-rules'; |
| 12 | +import {generic} from './generic'; |
| 13 | + |
| 14 | +// Verilog HDL Language |
| 15 | +// Author: [Yunhao Tian] |
| 16 | +// -- |
| 17 | +export class verilog extends generic { |
| 18 | + |
| 19 | + // language aliases |
| 20 | + static alias(){ |
| 21 | + return ['verilog']; |
| 22 | + } |
| 23 | + |
| 24 | + setupLanguage() { |
| 25 | + |
| 26 | + this.rules = [ |
| 27 | + // strings |
| 28 | + _language_common_rules.dqStrings, |
| 29 | + |
| 30 | + // directives |
| 31 | + { |
| 32 | + regex: /`\w*\b/g, |
| 33 | + type: 'k4' |
| 34 | + }, |
| 35 | + |
| 36 | + { |
| 37 | + regex: /\[( *\d+(?: *\: *\d+) *)\]/g, |
| 38 | + type: 'e3' |
| 39 | + }, |
| 40 | + |
| 41 | + { |
| 42 | + regex: /\b(for|generate|if|else|repeat|case|endcase|begin|end|ifnone)\b/g, |
| 43 | + type: 'k1' |
| 44 | + }, |
| 45 | + |
| 46 | + { |
| 47 | + regex: /\b(output|input|inout|reg|wire|assign)\b/g, |
| 48 | + type: 'k5' |
| 49 | + }, |
| 50 | + |
| 51 | + { |
| 52 | + regex: /\b(module|endmodule|always|function|endfunction)\b/g, |
| 53 | + type: 'k2' |
| 54 | + }, |
| 55 | + |
| 56 | + // keywords |
| 57 | + { |
| 58 | + regex: /\b(or|rpmos|tranif1|and|initial|rtran|tri|parameter|rtranif0|tri0|pmos|rtranif1|tri1|buf|endprimitive|integer|posedge|scalared|triand|bufif0|endspecify|join|primitive|small|trior|bufif1|endtable|large|pull0|specify|trireg|endtask|macromodule|pull1|specparam|vectored|casex|event|medium|pullup|strong0|wait|casez|pulldown|strong1|wand|cmos|force|nand|rcmos|supply0|weak0|deassign|forever|negedge|real|supply1|weak1|default|nmos|realtime|table|defparam|nor|task|disable|highz0|not|release|time|wor|edge|highz1|notif0|tran|xnor|notif1|rnmos|tranif0|xor)\b/g, |
| 59 | + type: 'k0' |
| 60 | + }, |
| 61 | + |
| 62 | + // slash style comments |
| 63 | + _language_common_rules.slashComments, |
| 64 | + |
| 65 | + // multi line comments |
| 66 | + _language_common_rules.blockComments, |
| 67 | + |
| 68 | + // numbers |
| 69 | + { |
| 70 | + regex: /-?\d*'s?d[0-9_xz]+\b/gi, |
| 71 | + type: 'n1' |
| 72 | + }, |
| 73 | + { |
| 74 | + regex: /-?\d*'s?h[0-9a-f_xz]+\b/gi, |
| 75 | + type: 'n2' |
| 76 | + }, |
| 77 | + { |
| 78 | + regex: /-?\d*'s?b[01_xz]+\b/gi, |
| 79 | + type: 'n3' |
| 80 | + }, |
| 81 | + { |
| 82 | + regex: /-?\d*'s?o[0-7_xz]+\b/gi, |
| 83 | + type: 'n4' |
| 84 | + }, |
| 85 | + _language_common_rules.int, |
| 86 | + |
| 87 | + _language_common_rules.brackets, |
| 88 | + ] |
| 89 | + } |
| 90 | +} |
0 commit comments