<feed xmlns='http://www.w3.org/2005/Atom'>
<title>qemu/qemu.git/qobject/json-lexer.c, branch master</title>
<subtitle>QEMU main repository</subtitle>
<id>https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/atom?h=master</id>
<link rel='self' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/'/>
<updated>2026-07-02T11:56:35+00:00</updated>
<entry>
<title>json-parser: add location to JSON parsing errors</title>
<updated>2026-07-02T11:56:35+00:00</updated>
<author>
<name>Paolo Bonzini</name>
<email>pbonzini@redhat.com</email>
</author>
<published>2026-06-26T10:17:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=b6368e7c77aad190f44570f589ccaa4b5cb4818d'/>
<id>urn:sha1:b6368e7c77aad190f44570f589ccaa4b5cb4818d</id>
<content type='text'>
Now that all calls to parse_error have a token, add the line and column
to the message.  As far as I can see the two important TODOs (better
errors and better EOI handling) are done, and the others (token range
information and "parsed size"?) do not really matter or are handled
better by json-streamer.c.  So remove the list, which had sat unchanged
since 2009.

This needs some adjustments to provide a good x and y for error messages.
First of all, they switch from zero-based to one-based, which is safe
because they were both sitting unused.  Second, right now the x and y
are those of the *last* character in the token.  Modify json-lexer.c to
freeze tok-&gt;x and tok-&gt;y at the first character added to the GString.

Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Message-ID: &lt;20260626101727.1727389-7-pbonzini@redhat.com&gt;
Reviewed-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
</content>
</entry>
<entry>
<title>docs/interop: Convert qmp-spec.txt to rST</title>
<updated>2023-05-22T08:21:01+00:00</updated>
<author>
<name>Peter Maydell</name>
<email>peter.maydell@linaro.org</email>
</author>
<published>2023-05-15T16:22:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=d56572584d9a5414c6a55c3f6b7ecce4b098926b'/>
<id>urn:sha1:d56572584d9a5414c6a55c3f6b7ecce4b098926b</id>
<content type='text'>
Convert the qmp-spec.txt document to restructuredText.
Notable points about the conversion:
 * numbers at the start of section headings are removed, to match
   the style of the rest of the manual
 * cross-references to other sections or documents are hyperlinked
 * various formatting tweaks (notably the examples, which need the
   -&gt; and &lt;- prefixed so the QMP code-block lexer will accept them)
 * English prose fixed in a few places

Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Signed-off-by: Peter Maydell &lt;peter.maydell@linaro.org&gt;
Message-Id: &lt;20230515162245.3964307-2-peter.maydell@linaro.org&gt;
Reviewed-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
[.. code-block:: dumbed down to :: to work around CI failure]
</content>
</entry>
<entry>
<title>json: Fix off-by-one assert check in next_state()</title>
<updated>2019-03-26T07:10:11+00:00</updated>
<author>
<name>Liam Merwick</name>
<email>liam.merwick@oracle.com</email>
</author>
<published>2019-03-21T11:57:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=19e8ff485a25001f48d7cbfaed24663dae001df7'/>
<id>urn:sha1:19e8ff485a25001f48d7cbfaed24663dae001df7</id>
<content type='text'>
The assert checking if the value of lexer-&gt;state in next_state(),
which is used as an index to the 'json_lexer' array, incorrectly
checks for an index value less than or equal to ARRAY_SIZE(json_lexer).
Fix assert so that it just checks for an index less than the array size.

Signed-off-by: Liam Merwick &lt;liam.merwick@oracle.com&gt;
Message-Id: &lt;1553169472-25325-1-git-send-email-liam.merwick@oracle.com&gt;
Reviewed-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Li Qiang &lt;liq3ea@gmail.com&gt;
Reviewed-by: Stefano Garzarella &lt;sgarzare@redhat.com&gt;
Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
</content>
</entry>
<entry>
<title>json: Eliminate lexer state IN_WHITESPACE, pseudo-token JSON_SKIP</title>
<updated>2018-09-24T16:08:07+00:00</updated>
<author>
<name>Markus Armbruster</name>
<email>armbru@redhat.com</email>
</author>
<published>2018-08-31T07:58:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=1e960b46024d468e76d2f42ddcfa5a9d521db492'/>
<id>urn:sha1:1e960b46024d468e76d2f42ddcfa5a9d521db492</id>
<content type='text'>
The lexer ignores whitespace like this:

         on whitespace      on non-ws   spontaneously
    IN_START --&gt; IN_WHITESPACE --&gt; JSON_SKIP --&gt; IN_START
                    ^    |
                     \__/  on whitespace

This accumulates a whitespace token in state IN_WHITESPACE, only to
throw it away on the transition via JSON_SKIP to the start state.
Wasteful.  Go from IN_START to IN_START on whitespace directly,
dropping the whitespace character.

Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Message-Id: &lt;20180831075841.13363-7-armbru@redhat.com&gt;
</content>
</entry>
<entry>
<title>json: Eliminate lexer state IN_ERROR</title>
<updated>2018-09-24T16:08:07+00:00</updated>
<author>
<name>Markus Armbruster</name>
<email>armbru@redhat.com</email>
</author>
<published>2018-08-31T07:58:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=2ce4ee64c4fe0463c53a99955a3acdaa8a451136'/>
<id>urn:sha1:2ce4ee64c4fe0463c53a99955a3acdaa8a451136</id>
<content type='text'>
Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Message-Id: &lt;20180831075841.13363-6-armbru@redhat.com&gt;
</content>
</entry>
<entry>
<title>json: Nicer recovery from lexical errors</title>
<updated>2018-09-24T16:08:07+00:00</updated>
<author>
<name>Markus Armbruster</name>
<email>armbru@redhat.com</email>
</author>
<published>2018-08-31T07:58:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=0f07a5d5f1f484c9c334d52193617e89442da7c9'/>
<id>urn:sha1:0f07a5d5f1f484c9c334d52193617e89442da7c9</id>
<content type='text'>
When the lexer chokes on an input character, it consumes the
character, emits a JSON error token, and enters its start state.  This
can lead to suboptimal error recovery.  For instance, input

    0123 ,

produces the tokens

    JSON_ERROR    01
    JSON_INTEGER  23
    JSON_COMMA    ,

Make the lexer skip characters after a lexical error until a
structural character ('[', ']', '{', '}', ':', ','), an ASCII control
character, or '\xFE', or '\xFF'.

Note that we must not skip ASCII control characters, '\xFE', '\xFF',
because those are documented to force the JSON parser into known-good
state, by docs/interop/qmp-spec.txt.

The lexer now produces

    JSON_ERROR    01
    JSON_COMMA    ,

Update qmp-test for the nicer error recovery: QMP now reports just one
error for input %p instead of two.  Also drop the newline after %p; it
was needed to tease out the second error.

Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Message-Id: &lt;20180831075841.13363-5-armbru@redhat.com&gt;
[Conflict with commit ebb4d82d888 resolved]
</content>
</entry>
<entry>
<title>json: Make lexer's "character consumed" logic less confusing</title>
<updated>2018-09-24T16:06:09+00:00</updated>
<author>
<name>Markus Armbruster</name>
<email>armbru@redhat.com</email>
</author>
<published>2018-08-31T07:58:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=c0ee3afa7fa2547b5766dd25e52ced292c204d4e'/>
<id>urn:sha1:c0ee3afa7fa2547b5766dd25e52ced292c204d4e</id>
<content type='text'>
The lexer uses macro TERMINAL_NEEDED_LOOKAHEAD() to decide whether a
state transition consumes the input character.  It returns true when
the state transition is defined with the TERMINAL() macro.  To detect
that, it checks whether input '\0' would have resulted in the same
state transition, and the new state is not IN_ERROR.

Why does that even work?  For all states, the new state on input '\0'
is either IN_ERROR or defined with TERMINAL().  If the state
transition equals the one we'd get for input '\0', it goes to IN_ERROR
or to the argument of TERMINAL().  We never use TERMINAL(IN_ERROR),
because it makes no sense.  Thus, if it doesn't go to IN_ERROR, it
must be defined with TERMINAL().

Since this isn't quite confusing enough, we negate the result to get
@char_consumed, and ignore it when @flush is true.

Instead of deriving the lookahead bit from the state transition, make
it explicit.  This is easier to understand, and a bit more flexible,
too.

Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Message-Id: &lt;20180831075841.13363-4-armbru@redhat.com&gt;
</content>
</entry>
<entry>
<title>json: Clean up how lexer consumes "end of input"</title>
<updated>2018-09-24T16:06:09+00:00</updated>
<author>
<name>Markus Armbruster</name>
<email>armbru@redhat.com</email>
</author>
<published>2018-08-31T07:58:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=852dfa76b85c5d23541377809aa4bcfb4fc037db'/>
<id>urn:sha1:852dfa76b85c5d23541377809aa4bcfb4fc037db</id>
<content type='text'>
When the lexer isn't in its start state at the end of input, it's
working on a token.  To flush it out, it needs to transit to its start
state on "end of input" lookahead.

There are two ways to the start state, depending on the current state:

* If the lexer is in a TERMINAL(JSON_FOO) state, it can emit a
  JSON_FOO token.

* Else, it can go to IN_ERROR state, and emit a JSON_ERROR token.

There are complications, however:

* The transition to IN_ERROR state consumes the input character and
  adds it to the JSON_ERROR token.  The latter is inappropriate for
  the "end of input" character, so we suppress that.  See also recent
  commit a2ec6be72b8 "json: Fix lexer to include the bad character in
  JSON_ERROR token".

* The transition to a TERMINAL(JSON_FOO) state doesn't consume the
  input character.  In that case, the lexer normally loops until it is
  consumed.  We have to suppress that for the "end of input" input
  character.  If we didn't, the lexer would consume it by entering
  IN_ERROR state, emitting a bogus JSON_ERROR token.  We fixed that in
  commit bd3924a33a6.

However, simply breaking the loop this way assumes that the lexer
needs exactly one state transition to reach its start state.  That
assumption is correct now, but it's unclean, and I'll soon break it.
Clean up: instead of breaking the loop after one iteration, break it
after it reached the start state.

Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Message-Id: &lt;20180831075841.13363-3-armbru@redhat.com&gt;
</content>
</entry>
<entry>
<title>json: Fix lexer for lookahead character beyond '\x7F'</title>
<updated>2018-09-24T16:06:09+00:00</updated>
<author>
<name>Markus Armbruster</name>
<email>armbru@redhat.com</email>
</author>
<published>2018-08-31T07:58:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=2a96042a8da60b625cc9dbbdab3b03cd7586e34f'/>
<id>urn:sha1:2a96042a8da60b625cc9dbbdab3b03cd7586e34f</id>
<content type='text'>
The lexer fails to end a valid token when the lookahead character is
beyond '\x7F'.  For instance, input

    true\xC2\xA2

produces the tokens

    JSON_ERROR     true\xC2
    JSON_ERROR     \xA2

This should be

    JSON_KEYWORD   true
    JSON_ERROR     \xC2
    JSON_ERROR     \xA2

instead.

The culprit is

    #define TERMINAL(state) [0 ... 0x7F] = (state)

It leaves [0x80..0xFF] zero, i.e. IN_ERROR.  Has always been broken.
Fix it to initialize the complete array.

Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Message-Id: &lt;20180831075841.13363-2-armbru@redhat.com&gt;
</content>
</entry>
<entry>
<title>json: Clean up headers</title>
<updated>2018-08-24T18:26:37+00:00</updated>
<author>
<name>Markus Armbruster</name>
<email>armbru@redhat.com</email>
</author>
<published>2018-08-23T16:40:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=86cdf9ec8dec2763702cc52fa412d108a5dc9608'/>
<id>urn:sha1:86cdf9ec8dec2763702cc52fa412d108a5dc9608</id>
<content type='text'>
The JSON parser has three public headers, json-lexer.h, json-parser.h,
json-streamer.h.  They all contain stuff that is of no interest
outside qobject/json-*.c.

Collect the public interface in include/qapi/qmp/json-parser.h, and
everything else in qobject/json-parser-int.h.

Signed-off-by: Markus Armbruster &lt;armbru@redhat.com&gt;
Reviewed-by: Eric Blake &lt;eblake@redhat.com&gt;
Message-Id: &lt;20180823164025.12553-54-armbru@redhat.com&gt;
</content>
</entry>
</feed>
