libdparse 0.23.1
Library for lexing and parsing D source code
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
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
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
- Class allocators. These are deprecated in D2.
- Class deallocators. These are deprecated in D2.
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);
}
- Registered by Brian Schott
- 0.23.1 released a year ago
- dlang-community/libdparse
- BSL-1.0
- Dependencies:
- none
- Versions:
-
0.24.0 2024-Apr-09 0.23.2 2023-Jul-05 0.23.1 2023-Jun-29 0.23.0 2023-May-04 0.22.0 2023-Feb-14 - Download Stats:
-
-
186 downloads today
-
1555 downloads this week
-
6547 downloads this month
-
1034175 downloads total
-
- Score:
- 4.9
- Short URL:
- libdparse.dub.pm