Skip to content

WebFreak001/libdparse

This branch is 1 commit ahead of, 20 commits behind dlang-community/libdparse:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6c0596f · Jul 8, 2023
May 4, 2023
Jun 13, 2022
Mar 24, 2023
Sep 3, 2014
Jul 8, 2023
Jul 5, 2023
Jul 5, 2023
Jun 13, 2017
Nov 5, 2014
Mar 24, 2023
Jun 13, 2022
Jun 24, 2014
Feb 15, 2018
Jun 13, 2022
Jan 7, 2015
Jun 13, 2022

Repository files navigation

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

About

Library for lexing and parsing D source code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • D 98.5%
  • Shell 1.1%
  • Other 0.4%