diff --git a/src/languages/dts.js b/src/languages/dts.js index 543235fb72..3cdbbce524 100644 --- a/src/languages/dts.js +++ b/src/languages/dts.js @@ -76,72 +76,87 @@ export default function(hljs) { ] }; - const DTS_REFERENCE = { + const REFERENCE = { className: 'variable', begin: /&[a-z\d_]*\b/ }; - const DTS_KEYWORD = { - className: 'meta-keyword', + const KEYWORD = { + className: 'meta', begin: '/[a-z][a-z\\d-]*/' }; - const DTS_LABEL = { + const LABEL = { className: 'symbol', begin: '^\\s*[a-zA-Z_][a-zA-Z\\d_]*:' }; - const DTS_CELL_PROPERTY = { + const CELL_PROPERTY = { className: 'params', + relevance: 0, begin: '<', end: '>', contains: [ NUMBERS, - DTS_REFERENCE + REFERENCE ] }; - const DTS_NODE = { - className: 'class', - begin: /[a-zA-Z_][a-zA-Z\d_@]*\s\{/, - end: /[{;=]/, - returnBegin: true, - excludeEnd: true + const NODE = { + className: 'title.class', + begin: /[a-zA-Z_][a-zA-Z\d_@-]*(?=\s\{)/ }; - const DTS_ROOT_NODE = { - className: 'class', - begin: '/\\s*\\{', - end: /\};/, - relevance: 10, - contains: [ - DTS_REFERENCE, - DTS_KEYWORD, - DTS_LABEL, - DTS_NODE, - DTS_CELL_PROPERTY, - hljs.C_LINE_COMMENT_MODE, - hljs.C_BLOCK_COMMENT_MODE, - NUMBERS, - STRINGS - ] + const ROOT_NODE = { + className: 'title.class', + begin: /^\/(?=\s*\{)/, + relevance: 10 + }; + + // TODO: `attribute` might be the right scope here, unsure + // I'm not sure if all these key names have semantic meaning or not + const ATTR_NO_VALUE = { + match: /[a-z][a-z-,]+(?=;)/, + relevance: 0, + scope: "attr" + }; + const ATTR = { + relevance: 0, + match: [ + /[a-z][a-z-,]+/, + /\s*/, + /=/ + ], + scope: { + 1: "attr", + 3: "operator" + } + }; + + const PUNC = { + scope: "punctuation", + relevance: 0, + // `};` combined is just to avoid tons of useless punctuation nodes + match: /\};|[;{}]/ }; return { name: 'Device Tree', - keywords: "", contains: [ - DTS_ROOT_NODE, - DTS_REFERENCE, - DTS_KEYWORD, - DTS_LABEL, - DTS_NODE, - DTS_CELL_PROPERTY, + ROOT_NODE, + REFERENCE, + KEYWORD, + LABEL, + NODE, + ATTR, + ATTR_NO_VALUE, + CELL_PROPERTY, hljs.C_LINE_COMMENT_MODE, hljs.C_BLOCK_COMMENT_MODE, NUMBERS, STRINGS, PREPROCESSOR, + PUNC, { begin: hljs.IDENT_RE + '::', keywords: "" diff --git a/test/markup/dts/default.expect.txt b/test/markup/dts/default.expect.txt index 58cc15f829..fca2d879d4 100644 --- a/test/markup/dts/default.expect.txt +++ b/test/markup/dts/default.expect.txt @@ -10,62 +10,62 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ -/include/ "skeleton.dtsi" +/include/ "skeleton.dtsi" -/ { - compatible = "xlnx,zynq-7000"; +/ { + compatible = "xlnx,zynq-7000"; - pmu { - compatible = "arm,cortex-a9-pmu"; - interrupts = <0 5 4>, <0 6 4>; - interrupt-parent = <&intc>; - reg = < 0xf8891000 0x1000 0xf8893000 0x1000 >; - }; + pmu { + compatible = "arm,cortex-a9-pmu"; + interrupts = <0 5 4>, <0 6 4>; + interrupt-parent = <&intc>; + reg = < 0xf8891000 0x1000 0xf8893000 0x1000 >; + }; - regulator_vccpint: fixedregulator@0 { - compatible = "regulator-fixed"; - regulator-name = "VCCPINT"; - regulator-min-microvolt = <1000000>; - regulator-max-microvolt = <1000000>; - regulator-boot-on; - regulator-always-on; - }; + regulator_vccpint: fixedregulator@0 { + compatible = "regulator-fixed"; + regulator-name = "VCCPINT"; + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <1000000>; + regulator-boot-on; + regulator-always-on; + }; - amba: amba { - compatible = "simple-bus"; + amba: amba { + compatible = "simple-bus"; #address-cells = <1>; #size-cells = <1>; - interrupt-parent = <&intc>; - ranges; + interrupt-parent = <&intc>; + ranges; - adc: adc@f8007100 { - compatible = "xlnx,zynq-xadc-1.00.a"; - reg = <0xf8007100 0x20>; - interrupts = <0 7 4>; - interrupt-parent = <&intc>; - clocks = <&clkc 12>; - }; + adc: adc@f8007100 { + compatible = "xlnx,zynq-xadc-1.00.a"; + reg = <0xf8007100 0x20>; + interrupts = <0 7 4>; + interrupt-parent = <&intc>; + clocks = <&clkc 12>; + }; - i2c0: i2c@e0004000 { - compatible = "cdns,i2c-r1p10"; - status = "disabled"; - clocks = <&clkc 38>; - interrupt-parent = <&intc>; - interrupts = <0 25 4>; - reg = <0xe0004000 0x1000>; + i2c0: i2c@e0004000 { + compatible = "cdns,i2c-r1p10"; + status = "disabled"; + clocks = <&clkc 38>; + interrupt-parent = <&intc>; + interrupts = <0 25 4>; + reg = <0xe0004000 0x1000>; #address-cells = <1>; #size-cells = <0>; - }; + }; - L2: cache-controller@f8f02000 { - compatible = "arm,pl310-cache"; - reg = <0xF8F02000 0x1000>; - interrupts = <0 2 4>; - arm,data-latency = <3 2 2>; - arm,tag-latency = <2 2 2>; - cache-unified; - cache-level = <2>; - }; + L2: cache-controller@f8f02000 { + compatible = "arm,pl310-cache"; + reg = <0xF8F02000 0x1000>; + interrupts = <0 2 4>; + arm,data-latency = <3 2 2>; + arm,tag-latency = <2 2 2>; + cache-unified; + cache-level = <2>; + }; - }; -}; + }; +};