Skip to content

Commit

Permalink
feat(lexer): Lexer
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Feb 17, 2024
1 parent fc3c16c commit 21ab584
Show file tree
Hide file tree
Showing 21 changed files with 1,375 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .codecov.yml
Expand Up @@ -88,4 +88,5 @@ ignore:
- src/types/

profiling:
critical_files_paths: []
critical_files_paths:
- src/lexer.ts
2 changes: 2 additions & 0 deletions .eslintignore
Expand Up @@ -8,7 +8,9 @@
**/*config.*.timestamp*
**/.DS_Store
**/.temp/
**/__tests__/benchmark.json
**/__tests__/report.*
**/__tests__/typecheck.json
**/coverage/
**/dist/
**/node_modules/
Expand Down
10 changes: 9 additions & 1 deletion .eslintrc.cjs
Expand Up @@ -10,7 +10,15 @@
*/
const config = {
extends: ['./.eslintrc.base.cjs'],
overrides: [...require('./.eslintrc.base.cjs').overrides],
overrides: [
...require('./.eslintrc.base.cjs').overrides,
{
files: ['__fixtures__/dbl-linear.ts'],
rules: {
'@typescript-eslint/require-await': 0
}
}
],
root: true
}

Expand Down
2 changes: 1 addition & 1 deletion .github/infrastructure.yml
Expand Up @@ -172,7 +172,7 @@ repository:
automated_security_fixes: true
default_branch: main
delete_branch_on_merge: true
description: unified compliant file parser for docast
description: docast utility for parsing docblocks
has_issues: true
has_projects: true
has_wiki: false
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -47,6 +47,7 @@ yarn-error.log*
**/*config.*.timestamp*
**/__tests__/benchmark.json
**/__tests__/report.*
**/__tests__/typecheck.json
**/coverage/
**/tsconfig*temp.json
*.lcov
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

[![github release](https://img.shields.io/github/v/release/flex-development/docast-util-from-docs.svg?include_prereleases&sort=semver)](https://github.com/flex-development/docast-util-from-docs/releases/latest)
[![npm](https://img.shields.io/npm/v/@flex-development/docast-util-from-docs.svg)](https://npmjs.com/package/@flex-development/docast-util-from-docs)
[![codecov](https://codecov.io/gh/flex-development/docast-util-from-docs/branch/main/graph/badge.svg?token=R2TPEBGWXB)](https://codecov.io/gh/flex-development/docast-util-from-docs)
[![codecov](https://codecov.io/gh/flex-development/docast-util-from-docs/graph/badge.svg?token=um87Ekggjn)](https://codecov.io/gh/flex-development/docast-util-from-docs)
[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
[![license](https://img.shields.io/github/license/flex-development/docast-util-from-docs.svg)](LICENSE.md)
[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits&logoColor=ffffff)](https://conventionalcommits.org/)
Expand Down
Empty file removed __fixtures__/.gitkeep
Empty file.
63 changes: 63 additions & 0 deletions __fixtures__/dbl-linear.ts
@@ -0,0 +1,63 @@
/**
* @file Fixtures - dblLinear
* @module fixtures/dblLinear
* @see https://codewars.com/kata/5672682212c8ecf83e000050
*/

/**
* Consider a sequence `u` where `u` is defined as follows:
*
* 1. The number `u(0) = 1` is the first one in `u`
* 2. For each `x` in `u`, `y = 2x + 1` and `z = 3x + 1` must be in `u` too
* 3. There are no other numbers in `u`
*
* Given an index, `n`, the function returns the element at `u(n)`.
*
* @async
*
* @example
* await dblLinear(0) // 1
* @example
* await dblLinear(10) // 22
* @example
* await dblLinear(100) // 447
* @example
* await dblLinear(7687) // 111718
*
* @param {number} n - Index of element to get
* @return {Promise<number>} Element at `u(n)`
*/
async function dblLinear(n: number): Promise<number> {
/** @const {number[]} u - Sequence */
const u: number[] = [1]

/** @var {number} j - Index of x in {@linkcode u} used to calculate y */
let j: number = 0

/** @var {number} k - Index of x in {@linkcode u} used to calculate z */
let k: number = 0

/*
* build sequence up to index n (inclusive)
*/
for (let i = 1; i <= n; i++) {
/** @const {number} y - `y` */
const y: number = 2 * u[j]! + 1

/** @const {number} z - `z` */
const z: number = 3 * u[k]! + 1

/* set sequence value to smallest value in [y, z] */
u[i] = Math.min(y, z)

// increase of index of x used to calculate y by 1
if (u[i] === y) j++

// increase of index of x used to calculate z by 1
if (u[i] === z) k++
}

return u[n]!
}

export default dblLinear
44 changes: 44 additions & 0 deletions __fixtures__/detect-syntax.ts
@@ -0,0 +1,44 @@
/**
* @file Fixtures - detectSyntax
* @module fixtures/detectSyntax
*/

import { hasCJSSyntax, hasESMSyntax } from '@flex-development/mlly'

/**
* Detects if `code` contains CommonJS syntax, ESM syntax, or a mixture of both.
*
* Ignores matches in comments.
*
* @see {@linkcode hasCJSSyntax}
* @see {@linkcode hasESMSyntax}
*
* @example
* import { detectSyntax } from '@flex-development/mlly'
*
* console.debug(detectSyntax('export default {}'))
*
* @param {string} code - Code to evaluate
* @return {{ cjs: boolean; esm: boolean; mixed: boolean }} Detection result
*/
const detectSyntax = (
code: string
): { cjs: boolean; esm: boolean; mixed: boolean } => {
/**
* CommonJS syntax check.
*
* @const {boolean} cjs
*/
const cjs: boolean = hasCJSSyntax(code)

/**
* ESM syntax check.
*
* @const {boolean} esm
*/
const esm: boolean = hasESMSyntax(code)

return { cjs, esm, mixed: cjs && esm }
}

export default detectSyntax
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -63,7 +63,7 @@
"fix:dedupe": "yarn dedupe --strategy=highest",
"fix:format": "dprint fmt",
"fix:lint": "yarn check:lint --cache --fix",
"postinstall": "[ -f ./node_modules/.bin/husky ] && chmod +x .husky/* && husky install || exit 0",
"postinstall": "[ -f ./node_modules/.bin/husky ] && chmod +x .husky/* && husky || exit 0",
"postpack": "toggle-scripts +postinstall",
"postpublish": "toggle-scripts +prepack",
"prepack": "toggle-scripts -postinstall && yarn build",
Expand Down

0 comments on commit 21ab584

Please sign in to comment.