Issues, comments, and pull requests are always welcome!
A few general rules:
- Write unit tests.
- Strongly type everything (except what is trivially inferred).
- Document as much as possible but nothing obvious. (No
i++; // increase variable
) - Use an IDE that supports ESLint. This will take care of formatting and give warnings and errors.
- Casing
- Lower camelCase for variables, functions, and parameters.
- Private methods and variables in a class must have one leading underscore (
_
). - Unused function parameters may have a leading underscore (
_
).
- Private methods and variables in a class must have one leading underscore (
- PascalCase for classes, interfaces, types, and type parameters.
- UPPER_CASE for compile-time constants.
- Lower camelCase for variables, functions, and parameters.
- Maximum and minimum
- When referring to a maximum of something, call it
maxSomething
instead ofmaximumSomething
. Same for "minimum" and "min". - When referring to a maximum and minimum to describe a range, call it
max
andmin
. - When referring to a maximum (without corresponding minimum), call it
maximum
. Same for "minimum".
- When referring to a maximum of something, call it
- Assertion vs. Lookaround
- Always use "assertion" when referring to a lookaround (= lookbehind inclusive or lookahead).
- Use "lookbehind" and "lookahead" only when referring to either specifically, excluding the other.
npm run test
Run all tests.npm run test:fast
Run all tests except for the regex stress test that takes from 5s to 20s.npm run build
Compiles the whole project and creates the finalindex.{js,d.ts}
files in the project's root directory.npm run scripts:debug
This will execute thescripts/debug.ts
file. This is a quick way to test new or existing features with access to all files in the library.
refa/
|-- scripts/
| `-- ...
|-- src/
| |-- ast/
| | `-- ...
| |-- iter/
| | `-- ...
| |-- js/
| | `-- ...
| |-- transformers/
| | `-- ...
| `-- ...
|-- tests/
| `-- ...
|-- CONTRIBUTING.md // this file
|-- index.{ts,d.ts} // generated by `npm run build`
|-- package.json
`-- ...
This folder contains useful scripts when working on refa. Any script can be executed via npm run scripts:<script-name>
.
The debug
script is particularly useful. It's purpose is to be way to quickly try out things. It as access to all of refa's source files and can be run via npm run scripts:debug
. Do not commit changes to this file.
This is folder for all files which will be in the compiled build of the library.
The most important files are:
char{set,map}.ts
defines the most important classes of refa:CharSet
- a sorted interval set used to represent characters - andCharMap
- a sorted interval map.finite-automaton.ts
defines interfaces all concrete FA implementations use.{dfa,nfa}.ts
define the concrete implementations of an NFA and DFA.words.ts
includes function to convert from JS strings to number arrays and vise versa among others.
This directory includes the definition of refa's RE AST format and simple functions/interfaces for traversal and modification.
This directory contains functions that consume and produce graph iterators. Graph iterators are one of refa's core concepts and allow us to implement different algorithms independently from one specific graph representation.
When importing those functions from outside src/iter
, it must be done via src/iter/index.ts
. It's recommended to import all functions like this:
import * as Iter from "./iter";
From inside src/iter
, functions MUST be imported directly from the file they are defined in.
This is where all JavaScript RegExp-specific logic lives. This is mainly includes a parser to convert RegExp to refa's RE AST format and a function to convert RE AST to JS RegExp.
Files from src/*
(except index.ts
) are not allowed to import files from src/js
. The rest of the library is supposed to be independent from this part of it because it may later be moved to its own package.
This directory contains RE AST transformers. These tools can be used to simplify and change existing RE ASTs.
This folder has a similar layout to src
. It's supposed to somewhat mirror the file structure of src
, so it's easy to find where tests for specific files form src
live.
You can run all tests using npm run test
(or just npm test
).
If you want to run the tests quicker, you can use npm run test:fast
. This will run all tests except the stress test which is executed for thousands of regexes.
The helper
folder contains functions used to implement tests. This includes useful constant, conversions function, and sets of test regexes.