Next: D Parser Context Interface, Previous: D Location Values, Up: D Parsers [Contents][Index]
The name of the generated parser class defaults to YYParser
. The
YY
prefix may be changed using the ‘%define api.prefix’.
Alternatively, use ‘%define api.parser.class {name}’ to give a
custom name to the class. The interface of this class is detailed below.
By default, the parser class has public visibility. To add modifiers to the
parser class, %define
api.parser.public
,
api.parser.abstract
and/or api.parser.final
.
The superclass and the implemented interfaces of the parser class can be specified with the ‘%define api.parser.extends’ and ‘%define api.parser.implements’ directives.
The parser class defines an interface, Lexer
(see D Scanner Interface). Other than this interface and the members described in the
interface below, all the other members and fields are preceded with a
yy
or YY
prefix to avoid clashes with user code.
The parser class can be extended using the %parse-param
directive. Each occurrence of the directive will add a by default public
field to the parser class, and an argument to its constructor, which
initializes them automatically.
Build a new parser object with embedded ‘%code lexer’. There are no
parameters, unless %param
s and/or %parse-param
s and/or
%lex-param
s are used.
Lexer
lexer, parse_param, …) ¶Build a new parser object using the specified scanner. There are no
additional parameters unless %param
s and/or %parse-param
s are
used.
Run the syntactic analysis, and return true
on success,
false
otherwise.
Get or set the option to produce verbose error messages. These are only available with ‘%define parse.error detailed’, which also turns on verbose error messages.
string
msg) ¶Location
loc, string
msg) ¶Print an error message using the yyerror
method of the scanner
instance in use. The Location
and Position
parameters are
available only if location tracking is active.
During the syntactic analysis, return true
if recovering
from a syntax error.
See Error Recovery.
File
o) ¶Get or set the stream used for tracing the parsing. It defaults to
stderr
.
int
l) ¶Get or set the tracing level. Currently its value is either 0, no trace, or nonzero, full tracing.
Identify the Bison version and skeleton used to generate this parser.
The internationalization in D is very similar to the one in C. The D
parser uses dgettext
for translating Bison messages.
To enable internationalization, compile using ‘-version ENABLE_NLS
-version YYENABLE_NLS’ and import bindtextdomain
and
textdomain
from C:
extern(C) char* bindtextdomain(const char* domainname, const char* dirname); extern(C) char* textdomain(const char* domainname);
The main function should load the translation catalogs, similarly to the c/bistromathic example:
int main() { import core.stdc.locale; // Set up internationalization. setlocale(LC_ALL, ""); // Use Bison's standard translation catalog for error messages // (the generated messages). bindtextdomain("bison-runtime", BISON_LOCALEDIR); // For the translation catalog of your own project, use the // name of your project. bindtextdomain("bison", LOCALEDIR); textdomain("bison"); // usual main content ... }
For user message translations, the user must implement the ‘string
_(const char* msg)’ function. It is recommended to use
gettext
:
%code imports { static if (!is(typeof(_))) { version(ENABLE_NLS) { extern(C) char* gettext(const char*); string _(const char* s) { return to!string(gettext(s)); } } } static if (!is(typeof(_))) { pragma(inline, true) string _(string msg) { return msg; } } }
Next: D Parser Context Interface, Previous: D Location Values, Up: D Parsers [Contents][Index]