• Stars
    star
    113
  • Rank 303,003 (Top 7 %)
  • Language
    D
  • License
    Boost Software Li...
  • Created almost 10 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library for lexing and parsing D source code

libdparse

Library for lexing and parsing D source code.

Documentation

Online documentation is available here.

A HTML version of libdparse's grammar is also automatically generated.

Testing

CI Status

Tests are present in the test directory. To run them execute the run_tests.sh script. Running the tests on Windows is not currently supported.

Differences with the official grammar

  • Static array initialization syntax. Due to ambiguities they are supported when the expression that gives the elements indexes is not an array. In the opposite case they are parsed as associative array literals.

Unsupported Syntax

Example

/+dub.sdl:
dependency "libdparse" version="~>0.7"
+/
import dparse.ast;
import std.stdio, std.range;

class TestVisitor : ASTVisitor
{
    alias visit = ASTVisitor.visit;
    int indentLevel;

    override void visit(const FunctionDeclaration decl)
    {
        writeln(' '.repeat(indentLevel * 4), decl.name.text);
        indentLevel++;
        scope (exit) indentLevel--;
        decl.accept(this);
    }
}

void main()
{
    import dparse.lexer;
    import dparse.parser : parseModule;
    import dparse.rollback_allocator : RollbackAllocator;

    auto sourceCode = q{
        void foo() @safe {
            void bar();
        }
    };
    LexerConfig config;
    auto cache = StringCache(StringCache.defaultBucketCount);
    auto tokens = getTokensForParser(sourceCode, config, &cache);

    RollbackAllocator rba;
    auto m = parseModule(tokens, "test.d", &rba);
    auto visitor = new TestVisitor();
    visitor.visit(m);
}

Open on run.dlang.io

More Repositories

1

awesome-d

A curated list of awesome D documents, frameworks, libraries and software. Inspired by awesome-python.
D
640
star
2

DCD

The D Completion Daemon is an auto-complete program for the D programming language
D
345
star
3

D-Scanner

Swiss-army knife for D source code
D
236
star
4

dfmt

Dfmt is a formatter for D source code
D
202
star
5

SDLang-D

An SDLang (Simple Declarative Language) library for D
D
118
star
6

D-YAML

YAML parser and emitter for the D programming language
D
116
star
7

containers

Containers backed by std.experimental.allocator
D
109
star
8

drepl

A REPL for D
D
76
star
9

d2sqlite3

A small wrapper around SQLite for the D programming language
C
74
star
10

mecca

Weka.IO's userland OS
D
64
star
11

setup-dlang

Github action for dlang compiler setup
TypeScript
45
star
12

dfix

Tool for automatically upgrading D source code
D
44
star
13

std_data_json

Phobos candidate JSON implementation.
D
25
star
14

dmarkdown

Markdown to HTML processor for D
D
24
star
15

d-mans

Collection of D-Man drawings from around the world
HTML
20
star
16

DGrammar

An attempt to completely and correctly document the grammar of the D programming language
HTML
20
star
17

harbored-mod

A documentation generator for D with support for both DDoc and Markdown.
D
18
star
18

dsymbol

Basic symbol lookup/resolution for libdparse (Deprecated, see link)
D
15
star
19

quic-d

Implementation of QUIC in D. See: https://github.com/dlang/projects/issues/84
Nix
14
star
20

experimental.xml

A replacement of Phobos std.xml
D
11
star
21

discussions

Get in touch with the DLang community
11
star
22

stdx-allocator

Extracted std.experimental.allocator for usage via DUB
D
9
star
23

d-money

Handling amounts of money safely and efficiently
D
9
star
24

artwork

Collection of D artwork from around the world
HTML
8
star
25

tinyendian

Lightweight endianness library for D
D
8
star
26

libddoc

D implementation of the DDoc macro system
D
7
star
27

toml

D
4
star
28

configy

An automatic YAML to struct configuration parser for dlang
D
3
star
29

d-apt

Debian APT repository for D tools
2
star
30

gitcompatibledubpackage

An example of a repositery usable both as a DUB package and a git submodule.
D
2
star
31

decimal

1
star