csvlang

command module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 3 Imported by: 0

README

Tests Go Report Card Go Reference

csvlang is a dynamic language to interact with CSV files. It is a domain-specific language that allows you to read, filter, modify, and export data from CSV files easily.

Documentation about csvlang commands can be found at godoc.org.

Contents

  1. Features
  2. Usage
  3. Getting Started
  4. Running Tests
  5. Contributing
  6. License

Features

Read all or specific rows or columns

load data.csv

let rows = read row *;
let firstRow = read row 0;
let firstColumn = read row * col 0;
let filteredRows = read row * col * where age > 20;

Fill empty cells with a fallback value

load data.csv

let rows = read row * col amount where age > 20;
let polyfilledRows = fill(rows, "name", "John Doe");

Remove duplicate rows

load data.csv

let rows = read row *;

let uniqueRows = unique(rows);

Built-in statistical functions

To calculate the sum, average, and count of values in a column.

load data.csv

let rows = read row * col amount where age > 20;

let totalAmount = sum(rows);
let averageAmount = avg(rows);
let countAmount = count(rows);

Export to JSON or CSV file

load data.csv

let rows = read row * where age > 20;

save rows as output.csv;
save rows as output.json;

Usage

go install github.com/Rishabh570/csvlang@latest

Option 2: Binary Installation

  1. Download the latest binary for your platform from the releases page.
  2. Extract the archive.
  3. Add the binary to your PATH.

Option 3: Build from Source

git clone https://github.com/Rishabh570/csvlang.git
cd csvlang
go build -o csvlang

Getting Started

  1. Clone the project:
git clone https://github.com/Rishabh570/csvlang
  1. Change to the project directory:
cd csvlang
  1. Install the dependencies:
go mod tidy
  1. Create a CSV file named data.csv in the project directory with the following content:
name,age,amount
John Doe,25,1000
John Doe,25,1000
Jane Smith,30,2000
Bob Brown,28,2500
  1. Create a csvlang script named script.csvlang in the project directory with the following content:
load data.csv
let rows = read row * where age > 20;
let uniqueRows = unique(rows);
save uniqueRows as output.csv;
  1. Run the project with your csvlang script path:
go run main.go --path <path-to-csvlang-script>

or, if you have installed the binary and it is present in your PATH, you can run the following command:

csvlang --path <path-to-csvlang-script>

Running Tests

To run tests, run the following command

go test ./...

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

License

MIT

Documentation

Overview

csvlang is a simple programming language that can be used to manipulate CSV files.

The main.go file is the entry point of the application. It reads the file path from the command line arguments and evaluates the code in the file.

Directories

Path Synopsis
ast package defines the abstract syntax tree (AST) for the language
ast package defines the abstract syntax tree (AST) for the language
evaluator package is responsible for evaluating the AST nodes and returning the result of the evaluation.
evaluator package is responsible for evaluating the AST nodes and returning the result of the evaluation.
lexer package is responsible for tokenizing the input string.
lexer package is responsible for tokenizing the input string.
Environment is a map of string to Object that represents the environment in which an object is evaluated.
Environment is a map of string to Object that represents the environment in which an object is evaluated.
Parser package is responsible for parsing the tokens from the lexer and constructing the AST.
Parser package is responsible for parsing the tokens from the lexer and constructing the AST.
repl package is responsible for handling the file mode (repl mode is not supported) which reads the entire file content and evaluates the entire program at once.
repl package is responsible for handling the file mode (repl mode is not supported) which reads the entire file content and evaluates the entire program at once.
token package is used to define the token types and the Token struct.
token package is used to define the token types and the Token struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL