• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 4 years ago
  • Updated 11 months ago

Reviews

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

Repository Details

Parse Wolfram Language source code as abstract syntax trees (ASTs) or concrete syntax trees (CSTs)

CodeParser

CodeParser is a package for parsing Wolfram Language source code as abstract syntax trees (ASTs) or concrete syntax trees (CSTs). CodeParser is useful for inspecting code, formatting code, and instrumenting code (for e.g., coverage reporting or profiling), and much more!

CodeParser has many key features:

  • Understands practically entire Wolfram Language syntax.
  • Fast native library implementation.
  • Tested with combination of suite of hand-written tests and fuzz testing.
  • Gracious error handling and recovery
Needs["CodeParser`"]

CodeParse["1+1"]
Out[2]= ContainerNode[String, {CallNode[LeafNode[Symbol, "Plus", <||>], {LeafNode[Integer, "1", <|Source -> {{1, 1}, {1, 2}}|>], LeafNode[Integer, "1", <|Source -> {{1, 3}, {1, 4}}|>]}, <|Source -> {{1, 1}, {1, 4}}|>]}, <||>]

"CodeParser and CodeInspector" on community.wolfram.com

Parsing the Wolfram Language from WTC 2019: Watch Video (youtube)

Parsing the Wolfram Language from WTC 2019: Watch Video (wolfram.com)

Parsing the Wolfram Language from WTC 2019: Download Presentation

Setup

CodeParser is included in Mathematica 12.2 and above.

For older versions, install CodeParser paclet from the public paclet server:

PacletInstall["CodeParser"]

Build and install the CodeParser paclet locally

Using CodeParser

After CodeParser is installed, it can be used.

Needs["CodeParser`"]

CodeParse["1+1"]
Out[2]= ContainerNode[String, {CallNode[LeafNode[Symbol, "Plus", <||>], {LeafNode[Integer, "1", <|Source -> {{1, 1}, {1, 2}}|>], LeafNode[Integer, "1", <|Source -> {{1, 3}, {1, 4}}|>]}, <|Source -> {{1, 1}, {1, 4}}|>]}, <||>]

The input to CodeParse may be a string, a File, or a list of bytes.

Command-line tool (Optional)

An optional codeparser command-line tool is also built and can be used.

cmake -DBUILD_EXE=ON ..
cmake --build . --target codeparser-exe

$cpp/src/exe/codeparser
>>> 1+1
InfixNode[Plus, {LeafNode[Integer, "1", <|Source->{{1, 2}, {1, 2}}|>], LeafNode[Integer, 1, <|Source->{{1, 3}, {1, 4}}|>]}, <|Source->{{1, 1}, {1, 4}}|>]

>>>

Troubleshooting

Make sure that the CodeParser can be found on your system:

Needs["CodeParser`"]

and try a basic example:

CodeParse["1+1"]

You may get LibraryFunction messages:

In[1]:= Needs["CodeParser`"]

In[2]:= CodeParse["1+1"]

During evaluation of In[2]:= LibraryFunction::version: The version number 7 of the library is not consistent with the current or any previous WolframLibraryVersion.

During evaluation of In[2]:= LibraryFunction::initerr: A nonzero error code 7 was returned during the initialization of the library /Users/user/Library/Mathematica/Paclets/Repository/CodeParser-1.6/LibraryResources/MacOSX-x86-64/CodeParser.dylib.

During evaluation of In[2]:= LibraryFunction::libload: The function ConcreteParseBytes_Listable_LibraryLink was not loaded from the file /Users/user/Library/Mathematica/Paclets/Repository/CodeParser-1.6/LibraryResources/MacOSX-x86-64/CodeParser.dylib.

Out[2]= $Failed

This means that CodeParser was built with a newer version of Wolfram System than your system supports.

To fix this, build CodeParser from source with the version of Wolfram System that you will use.

Benchmarks

Some of the benchmarks test large data files. Those files are tracked in this repository to ensure that benchmarks are always run against identical input. Git LFS is used to ensure that a basic checkout of this repository remains small, which is important in CI/CD builds.

To run the benchmarks, first ensure that the large benchmark files have been checked out locally using:

$ git lfs pull --exclude="" --include="*"

This will override the default settings in .lfsconfig.

File Overview

  • Tests/files/large/ contains files managed by Git LFS. The files in this directory are used by the benchmarks. These files should never be modified, to ensure that benchmark comparisions between different revisions of this repository can be meaningfully compared.

More Repositories

1

WolframLanguageForJupyter

Wolfram Language kernel for Jupyter notebooks
Mathematica
983
star
2

Arrival-Movie-Live-Coding

Documents from a live coding session by Christopher Wolfram related to content from the 2016 film Arrival
Mathematica
940
star
3

WolframClientForPython

Call Wolfram Language functions from Python
Python
426
star
4

GitLink

Git integration for the Wolfram Language
C++
112
star
5

vscode-wolfram

Official Visual Studio Code extension for Wolfram Language
CMake
96
star
6

WolframWebEngineForPython

Integrates the Wolfram Language seamlessly with Python AIOHTTP
Python
88
star
7

Chatbook

Wolfram Notebooks + LLMs
Mathematica
78
star
8

codeinspector

Find and report problems in Wolfram Language code
Mathematica
63
star
9

wolfram-notebook-embedder

JavaScript embedder for Wolfram Cloud notebooks
JavaScript
56
star
10

FEMAddOns

Finite Element Method addons for Wolfram Language
Mathematica
52
star
11

wolfram-library-link-rs

Safe, efficient, and ergonomic bindings to Wolfram LibraryLink and the Wolfram Language
Rust
47
star
12

LSPServer

LSPServer is a package that implements the Language Server Protocol for Wolfram Language and allows a Wolfram Language kernel to run as an LSP server.
Mathematica
45
star
13

codeformatter

Format Wolfram Language source code
Mathematica
44
star
14

LibraryLinkUtilities

C++ wrappers for conveniently wrapping Wolfram LibraryLink code.
C++
33
star
15

draw

Vector drawing program with the Wolfram Language
Mathematica
33
star
16

OpenCascadeLink

Open source package for OpenCascadeLink, which is bundled with Wolfram Language products as of version 12.1
C++
31
star
17

RhinoLink

Wolfram Language interface to Rhino3D
C#
25
star
18

AWSLambda-WolframLanguage

Wolfram Language container image runtime for AWS Lambda
Mathematica
25
star
19

WL-FunctionCompile-CI-Template

Compile Wolfram Language functions using GitHub Actions continuous integration
Mathematica
23
star
20

GurobiLink

Wolfram Language interface to the Gurobi numerical optimization library
C++
23
star
21

WAS-Kubernetes

Shell
20
star
22

Sublime-WolframLanguage

Official Sublime Text package for Wolfram Language
Python
20
star
23

GitLink-Talk

Talk introducing GitLink given at the 2015 Wolfram Technology Conference
Mathematica
20
star
24

DistMesh

Mathematica
19
star
25

wstp-rs

Rust bindings to the Wolfram Symbolic Transport Protocol (WSTP)
Rust
18
star
26

CSSTools

A package for importing CSS files into the Wolfram Language
Mathematica
17
star
27

MongoLink

MongoLink is a package for interacting with MongoDB inside the Wolfram Language.
Mathematica
17
star
28

wolfram-expr-rs

Representing Wolfram Language expressions in Rust.
Rust
14
star
29

semantic-math

Mathematica
13
star
30

PacletCICD

Continuous integration and deployment for Wolfram Language Paclets
Mathematica
13
star
31

BioFormatsLink

Package for interacting with Bio-Formats library in the Wolfram Language
Mathematica
13
star
32

wolfram-app-discovery-rs

Locate local installations of the Wolfram Language.
Rust
12
star
33

Data-Curation-Training

Mathematica
12
star
34

build-paclet

Shell
4
star
35

check-paclet

Shell
3
star
36

wolframresearch.github.io

HTML
3
star
37

submit-paclet

Shell
3
star
38

sync-promise-js

TypeScript
2
star
39

test-paclet

Shell
2
star
40

PacletCICD-Examples-AdvancedSample

Mathematica
2
star
41

loggers-js

TypeScript
1
star
42

PacletCICD-Examples-FewIssues

Mathematica
1
star
43

PacletCICD-Examples-MoreIssues

Mathematica
1
star
44

PacletCICD-Examples-CompiledLibrary

Mathematica
1
star
45

reback-js

TypeScript
1
star
46

PacletCICD-Examples-Sample

Mathematica
1
star