all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jacob Gerlach <jacobgerlach@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: List-of-lists data structure
Date: Sat, 12 Apr 2014 09:46:47 -0400	[thread overview]
Message-ID: <CAA6UvuG=O_sBcY1RvfCohQhMs312R=F5pEyJrAKiG+2ngDD0xg@mail.gmail.com> (raw)

I'm working on implementing fontification in a major mode for an in
house scripting language. The scripts configure any of about 50 different
apps, each of which has different keywords. This looks something like:

--------------------------------
processConfig = pFoo
{
  foo = 1
  bar = true
  baz = normal
}

processConfig = pBar
{
  apples  = foo
  pears   = bar
  oranges = false
}
---------------------------------

Only the names on the left of the equals are keywords, so foo and bar
should receive the appropriate font lock face in the pFoo block, but
not in the pBar block (where apples, pears, and oranges would be
font-locked).

I have managed to make fontification app specific using multiline font
lock matching and regexp's anchored to "processConfig = pFoo" (for
example).

In the interest of long term maintainability, I want to create a data
structure to store all of the app names and associated keywords, which
I then iterate through to generate the entries for the fontification
keyword list.

For one app, I can use:

(setq name-and-keyword-list
      '("pFoo" ("foo" "bar" "baz")))

This gives me the ability to do something like:

(while foo
  (add-to-list 'my-app-names (car foo))
  (add-to-list 'my-keywords (make-font-lock-cons (car foo) (cdr foo)))
  (setq foo (cdr foo)))

Where make-font-lock-cons is a hypothetical function that returns the
appropriate cons cell for my keyword list, which uses the app name
(the car) as the anchor, and uses regexp-opt to generate a regexp for
actually matching using the list of keywords (the cdr).

This works for my one entry list - at least, (car name-and-keyword-list)
and (cdr name-and-keyword-list) give me what I would expect.

However, if I try to expand the list:

(setq name-and-keyword-list
      '("pFoo" ("foo" "bar" "baz"))
      '("pBar" ("apples" "pears" "orange")))

Building the list gives:
Wrong type argument: symbolp, (quote ("pBar" ("apples" "pears"
"orange")))

Is this a simple syntax error, or am I approaching this data structure
in the wrong way?

Any other recommendations on my approach to this problem would be very
welcome.

Thanks,
Jake


             reply	other threads:[~2014-04-12 13:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-12 13:46 Jacob Gerlach [this message]
2014-04-12 20:07 ` List-of-lists data structure Stefan Monnier
2014-04-13  8:13 ` Thien-Thi Nguyen
     [not found] ` <mailman.19545.1397376560.10748.help-gnu-emacs@gnu.org>
2014-04-13 18:47   ` Jacob Gerlach
     [not found] <mailman.19516.1397327481.10748.help-gnu-emacs@gnu.org>
2014-04-13  7:49 ` Joost Kremers
2014-04-13 18:44   ` Jacob Gerlach
2014-04-13 18:59     ` Joost Kremers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA6UvuG=O_sBcY1RvfCohQhMs312R=F5pEyJrAKiG+2ngDD0xg@mail.gmail.com' \
    --to=jacobgerlach@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.