Skip to content

Commit 1735279

Browse files
authored
Merge pull request #3830 from sopvop/master
Basic cabal lexer for docs
2 parents 01ce086 + 6cb880b commit 1735279

File tree

2 files changed

+49
-21
lines changed

2 files changed

+49
-21
lines changed

Cabal/doc/conf.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def setup(app):
190190
doc_field_types=[
191191
Field('since', label='Introduced in GHC version', names=['since']),
192192
])
193+
app.add_lexer('cabal', CabalLexer())
193194

194195
def increase_python_stack():
195196
# Workaround sphinx-build recursion limit overflow:
@@ -198,3 +199,28 @@ def increase_python_stack():
198199
#
199200
# Default python allows recursion depth of 1000 calls.
200201
sys.setrecursionlimit(10000)
202+
203+
204+
import pygments.lexer as lexer
205+
import pygments.token as token
206+
import re
207+
208+
class CabalLexer(lexer.RegexLexer):
209+
name = 'Cabal'
210+
aliases = ['cabal']
211+
filenames = ['.cabal']
212+
flags = re.MULTILINE# | re.DOTALL
213+
214+
tokens = {
215+
'root' : [
216+
(r'\n', token.Text),
217+
(r'^\s*(--.*)$', token.Comment.Single),
218+
(r'[^\S\n]+', token.Text),
219+
(r'(\n\s*|\t)', token.Whitespace),
220+
(r'&&|\|\||==|<=|>=|<|>|^=', token.Operator),
221+
(r',', token.Punctuation),
222+
(r'^\s*([\w\-_]+:)', token.Keyword),
223+
(r'^\s*([\w\-_]+)(\s+)([\w\-_]+).*$', lexer.bygroups(token.Keyword, token.Whitespace, token.Name)),
224+
(r'.', token.Text)
225+
],
226+
}

Cabal/doc/nix-local-build.rst

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.. highlight:: shell
12

23
Quickstart
34
==========
@@ -27,7 +28,7 @@ directory with a folder per package, e.g., the folders ``Cabal`` and
2728
``cabal-install``. The ``cabal.project`` file specifies each folder as
2829
part of the project:
2930

30-
::
31+
.. code-block:: cabal
3132
3233
packages: Cabal/
3334
cabal-install/
@@ -320,8 +321,9 @@ solver under the current index and flags. A ``cabal.project.freeze``
320321
file has the same syntax as ``cabal.project`` and looks something like
321322
this:
322323

323-
::
324+
.. highlight:: cabal
324325

326+
::
325327
constraints: HTTP ==4000.3.3,
326328
HTTP +warp-tests -warn-as-error -network23 +network-uri -mtl1 -conduit10,
327329
QuickCheck ==2.9.1,
@@ -547,15 +549,15 @@ The following settings control the behavior of the dependency solver:
547549
Version bounds have the same syntax as ``build-depends``. You can
548550
also specify flag assignments:
549551

550-
.. code-block:: yaml
552+
::
551553

552-
# Require bar to be installed with the foo flag turned on and
553-
# the baz flag turned off
554+
-- Require bar to be installed with the foo flag turned on and
555+
-- the baz flag turned off
554556
constraints: bar +foo -baz
555557

556-
# Require that bar NOT be present in the install plan. Note:
557-
# this is just syntax sugar for '> 1 && < 1', and is supported
558-
# by build-depends.
558+
-- Require that bar NOT be present in the install plan. Note:
559+
-- this is just syntax sugar for '> 1 && < 1', and is supported
560+
-- by build-depends.
559561
constraints: bar -none
560562

561563
A package can be specified multiple times in ``constraints``, in
@@ -574,20 +576,20 @@ The following settings control the behavior of the dependency solver:
574576

575577
::
576578

577-
# Require bar to be preinstalled in the global package database
578-
# (this does NOT include the Nix-local build global store.)
579+
-- Require bar to be preinstalled in the global package database
580+
-- (this does NOT include the Nix-local build global store.)
579581
constraints: bar installed
580582

581-
# Require the local source copy of bar to be used
582-
# (Note: By default, if we have a local package we will
583-
# automatically use it, so it generally not be necessary to
584-
# specify this)
583+
-- Require the local source copy of bar to be used
584+
-- (Note: By default, if we have a local package we will
585+
-- automatically use it, so it generally not be necessary to
586+
-- specify this)
585587
constraints: bar source
586588

587-
# Require that bar be solved with test suites and benchmarks enabled
588-
# (Note: By default, new-build configures the solver to make
589-
# a best-effort attempt to enable these stanzas, so this generally
590-
# should not be necessary.)
589+
-- Require that bar be solved with test suites and benchmarks enabled
590+
-- (Note: By default, new-build configures the solver to make
591+
-- a best-effort attempt to enable these stanzas, so this generally
592+
-- should not be necessary.)
591593
constraints: bar test,
592594
bar bench
593595

@@ -643,11 +645,11 @@ The following settings control the behavior of the dependency solver:
643645

644646
::
645647

646-
# Disregard upper bounds involving the dependencies on
647-
# packages bar, baz and quux
648+
-- Disregard upper bounds involving the dependencies on
649+
-- packages bar, baz and quux
648650
allow-newer: bar, baz, quux
649651

650-
# Disregard all upper bounds when dependency solving
652+
-- Disregard all upper bounds when dependency solving
651653
allow-newer: all
652654

653655
``allow-newer`` is often used in conjunction with a constraint (in

0 commit comments

Comments
 (0)