[Ada] Fix parsing for expressions with attributes and characters
authorPierre-Marie de Rodat <derodat@adacore.com>
Wed, 19 Aug 2015 15:12:48 +0000 (17:12 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 20 Aug 2015 08:12:24 +0000 (10:12 +0200)
commitaf39b3270a1385027b2a5d145b9ba7564bd39f7a
treed8376e96f1f09543651fe48bb625603aa410fc1d
parent9215b98bb27c071386a277f5578dbb17569a1471
[Ada] Fix parsing for expressions with attributes and characters

Before this change, trying to evaluate the following Ada expression
yielded a syntax error, even though it's completely legal:

    (gdb) p s'first = 'a'
    Error in expression, near `'.

The problem lies in the lexer (gdb/ada-lex.l): at the point we reach "'a'",
we're still in the BEFORE_QUAL_QUOTE start condition (the mechanism to
distinguish character literals from other "tick" usages: qualified
expressions and attributes), so we consider that this quote is actually a
separate "tick".

This changes resets the start condition to INITIAL in the
{TICK}[a-zA-Z][a-zA-Z]+ rule (for attributes): attributes activate this
BEFORE_QUAL_QUOTE condition and in this case the above rule is always
executed rather than the <BEFORE_QUAL_QUOTE>"'" one (in flex, it's
always the longest match that is chosen). We now have instead:

    (gdb) p s'first = 'a'
    $1 = true

gdb/ChangeLog:

* ada-lex.l: Reset the start condition to INITIAL in the rule
that matches attributes.

gdb/testsuite/ChangeLog:

* gdb.ada/attr_ref_and_charlit.exp: New testcase.
* gdb.ada/attr_ref_and_charlit/foo.adb: New file.

Tested on x86_64-linux, no regression.
gdb/ChangeLog
gdb/ada-lex.l
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/attr_ref_and_charlit.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/attr_ref_and_charlit/foo.adb [new file with mode: 0644]
This page took 0.037943 seconds and 4 git commands to generate.