|
From: Vampire <Va...@jE...> - 2010-12-18 13:24:46
|
Hi Eric,
while I don't have an instant solution for you without thinking
thoroughly about it, but two other thoughts.
IIRC, your mark previous is even for non-quoted keys not working fully
as before the ":" you can put any amount of whitespace and I think the
mark previous only works if there is no whitespace.
Besides that the second point, according to the RFC 4627, the "key" has
to be a string and a string always has to be quoted. So unquoted keys
are officially not really valid. If there are parsers out there that
allow them, maybe we should also show them as labels, but strictly
spoken it is invalid JSON I think. The RFC also explicitly states that
"No other literal names are allowed." besides false, null and true and
without the quotes it would be a literal. :-)
Regards
Vampire
Eric Berry schrieb:
> Need some help from the mode gurus. I'm updating the json mode to show
> field names/keys as labels, eg:
> {
> "label": "value"
> }
>
> I've got it mostly working, except when there are multiple keys per
> line eg:
> {
> "label1": "value", "label2": "value2"
> }
>
> Label 1 shows up as a label, but label2 appears as a string literal.
>
> It also doesn't work if the label is between the braces eg:
> { "label1": "value1" }
>
> It works fine if I don't quote the key, eg:
> {
> label1: "value1", label2: "value2"
> }
>
> But I'd like it to work properly all around.
>
> Here's my test JSON:
> [code]
> {
> "id": 1234567890,
> text: "Choose your favorite South Park kid:",
> "visible": true,
> "choices": [
> { "id": 123, "text": "Kenny", "default": true },
> { "id": 456, "text": "Kyle" },
> { id: 789, text: "Stan" },
> { id: 321, text: "Eric" }
> ]
> }
> [/code]
>
> And here's the mode file:
> [code src="json.xml"]
> <?xml version="1.0"?>
> <!DOCTYPE MODE SYSTEM "xmode.dtd">
> <MODE>
> <PROPS>
> <!-- auto indent -->
> <PROPERTY NAME="indentOpenBrackets" VALUE="[{" />
> <PROPERTY NAME="indentCloseBrackets" VALUE="}]" />
> </PROPS>
>
> <RULES>
> <!-- mark numbers as DIGIT -->
> <SEQ_REGEXP HASH_CHARS="-0123456789."
> TYPE="DIGIT">[-]?\d+([.]\d*)?([eE][+-]?\d+)?</SEQ_REGEXP>
>
>
> _ <SPAN TYPE="LABEL" AT_WHITESPACE_END="TRUE"
> AT_WORD_START="TRUE" ESCAPE="\" NO_LINE_BREAK="TRUE">
> <BEGIN>"</BEGIN>
> <END>"</END>
> </SPAN>
> <MARK_PREVIOUS MATCH_TYPE="OPERATOR"
> TYPE="LABEL">:</MARK_PREVIOUS>_
> <!-- mark strings as LITERAL1 -->
> <SPAN TYPE="LITERAL1" ESCAPE="\" NO_LINE_BREAK="TRUE">
> <BEGIN>"</BEGIN>
> <END>"</END>
> </SPAN>
> <!-- mark pair separator as OPERATOR -->
> <SEQ TYPE="OPERATOR">:</SEQ>
> <!-- mark these special values as LITERAL2 -->
> <SEQ TYPE="LITERAL2">true</SEQ>
> <SEQ TYPE="LITERAL2">false</SEQ>
> <SEQ TYPE="LITERAL2">null</SEQ>
> </RULES>
> </MODE>
> [/code]
>
> The underlined sections differ from the original json.xml, and those
> are the only ones I've added.
>
> Any help would be greatly appreciated.
>
> Thanks,
> Eric
>
> --
> Learn from the past. Live in the present. Plan for the future.
> Blog: http://www.townsfolkdesigns.com/blogs/elberry
> jEdit <http://www.jedit.org> - Programmer's Text Editor
> Bazaar <http://bazaar.canonical.com> - Version Control for Humans
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Lotusphere 2011
> Register now for Lotusphere 2011 and learn how
> to connect the dots, take your collaborative environment
> to the next level, and enter the era of Social Business.
> http://p.sf.net/sfu/lotusphere-d2d
|