Skip to contentSkip to conversation

Syntax highlighting

PATCH In review Stewart Smith 2 participants 4 messages Oct 28, 2016 – Nov 15, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover Syntax highlighting

Since http://pygments.org/ (what Sphinx uses for syntax highlighting) doesn't do DTS yet, implement DTS syntax highlighting and then use it (and the standard C source highlighting).

I'll be submitting the DTS highlighting upstream too, but having it in tree will ensure it works for people not running a future version of pygments.

Stewart Smith (2):
Enable syntax highlighting of device tree source Syntax highlight C and DTS

 source/conf.py                |  6 +++
 source/devicenodes.rst        | 18 ++++-----
 source/devicetree-basics.rst  | 14 ++++---
 source/extensions/DtsLexer.py | 89 +++++++++++++++++++++++++++++++++++++++++++
 source/flattened-format.rst   |  6 +--
 5 files changed, 115 insertions(+), 18 deletions(-)
 create mode 100644 source/extensions/DtsLexer.py
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): 1477635173-9292-1-git-send-email-stewart-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org

#2 lore raw

PATCH 1/2 Enable syntax highlighting of device tree source

---
 source/conf.py                |  6 +++
 source/extensions/DtsLexer.py | 89 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 source/extensions/DtsLexer.py
source/conf.py +6 -0
index 67edcb8..8f71117 100644
@@ -23,6 +23,12 @@ import time
 
 sys.path.append(os.path.abspath('extensions'))
 
+from DtsLexer import DtsLexer
+
+def setup(app):
+    from sphinx.highlighting import lexers
+    lexers['dts'] = DtsLexer()
+
 
 # -- General configuration ------------------------------------------------
 
source/extensions/DtsLexer.py new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

PATCH 2/2 Syntax highlight C and DTS

In reply to a message not in the archive
---
 source/devicenodes.rst       | 18 +++++++++---------
 source/devicetree-basics.rst | 14 ++++++++------
 source/flattened-format.rst  |  6 +++---
 3 files changed, 20 insertions(+), 18 deletions(-)
source/devicenodes.rst +9 -9
index e12aa95..78b5bdb 100644
@@ -91,12 +91,12 @@ considering a string as a device path, shall detect and use the alias.
 
 **Example**
 
-::
+.. code-block:: dts
 
     aliases {
         serial0 = "/simple-bus@fe000000/serial@llc500";
         ethernet0 = "/simple-bus@fe000000/ethernet@31c000";
-    }
+    };
 
 Given the alias serial0, a client program can look at the aliases node
 and determine the alias refers to the device path
@@ -168,7 +168,7 @@ and ``#size-cells = <2>``.
 
 **Example #1**
 
-::
+.. code-block:: dts
 
     memory@0 {
         device_type = "memory";
@@ -178,7 +178,7 @@ and ``#size-cells = <2>``.
 
 **Example #2**
 
-::
+.. code-block:: dts
 
     memory@0 {
         device_type = "memory";
@@ -234,7 +234,7 @@ time. It shall be a child of the root node.
 
 **Example**
 
-::
+.. code-block:: dts
 
     chosen {
         bootargs = "root=/dev/nfs rw nfsroot=192.168.1.1 console=ttyS0,115200";
@@ -618,7 +618,7 @@ Example
 
 Here is an example of a ``/cpus`` node with one child cpu node:
 
-::
+.. code-block:: dts
 
     cpus {
         #address-cells = <1>;
@@ -680,7 +680,7 @@ Example
 See the following example of a devicetree representation of two CPUs,
 each with their own on-chip L2 and a shared L3.
 
-::
+.. code-block:: dts
 
     cpus {
         #address-cells = <1>;
@@ -709,7 +709,7 @@ each with their own on-chip L2 and a shared L3.
                     cache-unified;
                     cache-size = <0x40000>; // 256 KB
                     cache-sets = <0x400>; // 1024
-                    cache-block-size =
+                    cache-block-size = <32>;
                     cache-level = <3>;
                 };
             };
@@ -730,7 +730,7 @@ each with their own on-chip L2 and a shared L3.
                 cache-unified;
                 cache-size = <0x40000>; // 256 KB
                 cache-sets = <0x400>; // 1024
-                cache-line-size = <32> // 32 bytes
+                cache-line-size = <32>; // 32 bytes
                 next-level-cache = <&L3>; // phandle to L3
             };
         };
source/devicetree-basics.rst +8 -6
index ba5281c..be80af3 100644
@@ -463,7 +463,7 @@ Example:
 
    See the following devicetree excerpt:
 
-   ::
+   .. code-block:: dts
 
       pic@10000000 {
          phandle = <1>;
@@ -473,9 +473,11 @@ Example:
    A *phandle* value of 1 is defined. Another device node could reference
    the pic node with a phandle value of 1:
 
-   ::
+   .. code-block:: dts
 
-      interrupt-parent = <1>;
+      another-device-node {
+        interrupt-parent = <1>;
+      };
 
 .. note:: Older versions of devicetrees may be encountered that contain a
    deprecated form of this property called ``linux,phandle``. For
@@ -557,7 +559,7 @@ Example:
 
    See the following devicetree excerpt:
 
-   ::
+   .. code-block:: dts
 
       soc {
          #address-cells = <1>;
@@ -671,7 +673,7 @@ Description:
 
 Address Translation Example:
 
-   ::
+   .. code-block:: dts
 
        soc {
           compatible = "simple-bus";
@@ -1084,7 +1086,7 @@ interrupt controller.
 
 .. _example-interrupt-mapping:
 
-::
+.. code-block:: dts
 
    soc {
       compatible = "simple-bus";
source/flattened-format.rst +3 -3
index ba68f8a..ccac933 100644
@@ -70,7 +70,7 @@ big-endian format.
 
 **Flattened Devicetree Header Fields**
 
-::
+.. code-block:: c
 
         struct fdt_header {
             uint32_t magic;
@@ -208,7 +208,7 @@ The memory reservation block consists of a list of pairs of 64-bit
 big-endian integers, each pair being represented by the following C
 structure.
 
-::
+.. code-block:: c
 
     struct fdt_reserve_entry {
         uint64_t address;
@@ -273,7 +273,7 @@ The five token types are as follows:
    describing the property. This data consists first of the property’s
    length and name represented as the following C structure:
 
-   ::
+   .. code-block:: c
 
       struct {
           uint32_t len;
Signature · 1 line
2.7.4
#4 lore raw
In reply to a message not in the archive
Quoted 11 lines · Stewart Smith

Since http://pygments.org/ (what Sphinx uses for syntax highlighting) doesn't do DTS yet, implement DTS syntax highlighting and then use it (and the standard C source highlighting).

I'll be submitting the DTS highlighting upstream too, but having it in tree will ensure it works for people not running a future version of pygments.

Stewart Smith (2):
Enable syntax highlighting of device tree source Syntax highlight C and DTS

Sorry for the delay. Looks nice and I've applied both. Thanks.

Rob