英語版
このページの英語版を見る

dmd.lexer

ソースコードを()()トークンに変換する()()解析器を実装する。
Authors:

ソースlexer.d

適用範囲 https://codecov.io/gh/dlang/dmd/src/master/src/dmd/lexer.d

struct CompileEnv;
さまざまなマジック識別子に使用する"値"
uint versionNumber;
__VERSION__
const(char)[] date;
__DATE__
const(char)[] time;
__TIME__
const(char)[] vendor;
__VENDOR__
const(char)[] timestamp;
__TIMESTAMP__
bool previewIn;
in [ref] scope const を意味し、"r値"を受け入れる
bool ddocOutput;
組み込みのドキュメントコメントを収集する
bool masm;
MASMインラインasm構文を使用
IdentifierCharLookup cCharLookupTable;
C 識別子テーブル(C パーサーによってレキシコンに設定される)
IdentifierCharLookup dCharLookupTable;
D 識別子テーブル
class Lexer;
Examples:
Unittest
fprintf(stderr, "Lexer.unittest %d\n", __LINE__);

ErrorSink errorSink = new ErrorSinkStderr;

void test(T)(string sequence, T expected, bool Ccompile = false)
{
    auto p = cast(const(char)*)sequence.ptr;
    dchar c2;
    Lexer lexer = new Lexer(errorSink);
    assert(expected == lexer.escapeSequence(Loc.initial, p, Ccompile, c2));
    assert(p == sequence.ptr + sequence.length);
}

test(`'`, '\'');
test(`"`, '"');
test(`?`, '?');
test(`\`, '\\');
test(`0`, '\0');
test(`a`, '\a');
test(`b`, '\b');
test(`f`, '\f');
test(`n`, '\n');
test(`r`, '\r');
test(`t`, '\t');
test(`v`, '\v');

test(`x00`, 0x00);
test(`xff`, 0xff);
test(`xFF`, 0xff);
test(`xa7`, 0xa7);
test(`x3c`, 0x3c);
test(`xe2`, 0xe2);

test(`1`, '\1');
test(`42`, '\42');
test(`357`, '\357');

test(`u1234`, '\u1234');
test(`uf0e4`, '\uf0e4');

test(`U0001f603`, '\U0001f603');

test(`"`, '"');
test(`&lt;`, '<');
test(`&gt;`, '>');
unitestUnitest
IdentifierCharLookup charLookup;
識別子用の文字テーブル
bool Ccompile;
コンパイルする場合は true ImportC
ubyte boolsize;
CのBoolのサイズ、デフォルトは1
ubyte shortsize;
C言語の"short"のサイズ、デフォルトは2
ubyte intsize;
C int のサイズ、デフォルトは 4
ubyte longsize;
C long のサイズ、4 または 8
ubyte long_longsize;
C long long のサイズ、デフォルトは8
ubyte long_doublesize;
C long double のサイズ、8 または D real.sizeof
ubyte wchar_tsize;
C wchar_t のサイズ、2 または 4
ErrorSink eSink;
このインターフェース環境を通じてエラーメッセージを送信する
CompileEnv compileEnv;
環境
nothrow scope this(const(char)* filename, const(char)* base, size_t begoffset, size_t endoffset, bool doDocComment, bool commentToken, ErrorSink errorSink, const CompileEnv* compileEnv);
ソースコードベース[begoffset..endoffset+1]用のレキサーを作成する。 最後の文字base[endoffset]は、null (0) または EOF (0x1A) でなければならない。
Parameters:
const(char)* filename エラーメッセージに使用される
const(char)* base ソースコードでは、null (0) または EOF (0x1A) 文字で終了する必要がある
size_t begoffset base[]への開始オフセット
size_t endoffset base[]に読み込む最後のオフセット
bool doDocComment ハンドル ドキュメントのコメント
bool commentToken コメントはTOK.commentになる
ErrorSink errorSink エラーメッセージを格納する場所、nullであってはならない
CompileEnv* compileEnv バージョン、ベンダー、日付、時刻など。
nothrow this(const(char)* filename, const(char)* base, size_t begoffset, size_t endoffset, bool doDocComment, bool commentToken, bool whitespaceToken, ErrorSink errorSink, const CompileEnv* compileEnv = null);
DMDLIB用の代替エントリーポイント、追加する whitespaceToken
nothrow scope @safe this(ErrorSink errorSink);
モックのLexerのユニットテストに使用される
final nothrow void resetDefineLines(const(char)[] slice);
字句構造をリセットして、字句構造の定義を再設定する
final nothrow void nextDefineLine();
次の #define 行の準備。 p は次の行の最初に来る。
final const pure nothrow @nogc @property @safe bool empty();
範囲インターフェース
pure nothrow @safe Token* allocateToken();
Returns: 新たに割り当てられたxml-ph-0000@deepl.internal。
新たに割り当てられたToken
final nothrow TOK peekNext();
次のトークンの値を先読みする。
final nothrow TOK peekNext2();
2つ先のトークンの値を見る。
final nothrow void scan(Token* t);
バッファ内の次のトークンをトークンに変換する。
Parameters:
Token* t 結果として得られるトークンをtkに設定する
final nothrow Token* peekPastParen(Token* tk);
tkは開始(. 終了を過ぎた先読みと戻りトークン)である。
final nothrow TOK hexStringConstant(Token* t);
字句構造の16進文字列: "0A ae 34FE BD"
nothrow bool parseSpecialTokenSequence();
特殊トークンシーケンスの解析:
Returns:
特別なトークンシーケンスが処理された場合は true

参照 https://dlang.org/spec/lex.html#special-token-sequence

final nothrow void poundLine(ref Token tok, bool linemarker);
行/ファイルプリプロセッサ指令の解析: #line linnum [filespec] linnum には "__LINE__" を、filespec には "__FILE__" を使用する。 linemarker 形式の受け入れ:

linnum [filespec] {flags}

フラグは0個以上指定でき、1~4の数字のいずれかであり、 昇順でなければならない。フラグは無視される。
Parameters:
Token tok トークンは、linenumのlinemarkerである
bool linemarker 行マーカーのフォーマットとレキシコンが有効になっている場合は true、linnum

参考文献 linemarkerhttps://gcc.gnu.org/onlinedocs/gcc-11.1.0/cpp/Preprocessor-Output.html

final nothrow void skipToNextLine(OutBuffer* defines = null);
次の行の先頭までスキャンする。
Parameters:
OutBuffer* defines 文字を送信する defines
static pure nothrow const(char)* combineComments(const(char)[] c1, const(char)[] c2, bool newParagraph);
2つのドキュメントコメントを1つに結合し、 newParagraphがtrueの場合は余分な改行を挿入する。
nothrow void printRestOfTokens();
現在のtoken から末尾までトークンを、 パーサーを進めずに 表示する。デバッグに便利。
emailemail