Yacc/Bison: Fix the $ symbol and update syntax for Bison

Authored by nibags on Feb 24 2018, 8:59 PM.

Description

Yacc/Bison: Fix the $ symbol and update syntax for Bison

Summary:
Hi
The Yacc/Bison file highlights as 'dsError' the '$' symbol (it is used as pseudo-variable). The problem comes from the 'isocpp.xml' file of C++, which highlights it as 'Error' (probably, this was added to the C++ file later).
data/syntax/yacc.xml (lines 131 & 132):

131|      <IncludeRules context="##C++" />
132|      <DetectChar attribute="Directive" context="Dol" char="$" />
133|  </context>

autotests/reference/highlight.y.ref :

35|  […] <Symbol>(</Symbol><Error>$</Error><Deimal>2</Decimal><Symbol>) [...]
40|  <Normal Text> </Normal Text><Error>$$</Error><Normal Text> </Normal Text> […]

That is corrected. Also, this file is outdated for Bison. Therefore, it is updated according to the parser of the latest version of Bison (3.0.4).

Changes/fixes for Bison:

  • Add declarations that contain blocks of code that are not currently highlighted. For example:
%code { C++ code... }
%destructor { C++ code, with symbols $… }
%initial-action { C++ code, with symbols $… }
  • Add the Bison variable '@' (@$, @n, @[name], $@n).
  • Add directives in rules: %?{ expr…}, %empty, %prec, %dprec and %merge.
  • Allow a tag in %union declarations. Ex:
%union tag { code … }
  • Allow grammar declarations in the grammar rules section, such as: %union, %code, %type, etc.
  • Allow declarations in multiple lines. Ex:
%token
         PERCENT_DEBUG           "%debug"
         PERCENT_DEFAULT_PREC    "%default-prec"
;
  • The ';' char is not necessary to finish a rule. Allow ';' followed by ‘|’, within a rule (See line 603 in the “src/parse-gram.y” file, from the Bison 3.0.4 source [2]).
  • Add the mimetypes (text/x-yacc, text/x-bison) and the extensions '.ypp' & '.y++' [3].

I hope these changes are useful.
Any inconvenience (as if it is necessary to contact the original author of the file to approve the changes), do not hesitate to notify.

Source:
[1] https://www.gnu.org/software/bison/manual/html_node/Table-of-Symbols.html
[2] https://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.xz ( ./src/parse-gram.y )
[3] https://www.gnu.org/software/bison/manual/html_node/Invocation.html

Test Plan: I've been testing these changes the last week and I think it's ready.

Reviewers: Framework: Syntax Highlighting, dhaumann

Reviewed By: Framework: Syntax Highlighting, dhaumann

Subscribers: dhaumann, Framework: Syntax Highlighting, Frameworks

Tags: Frameworks, Framework: Syntax Highlighting

Differential Revision: https://phabricator.kde.org/D10783

Details