Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support embellishments and non-punctuation delimiters #42

Merged
merged 24 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7871a42
feat: support embellishments and non-brace delimiters
theseanl Sep 6, 2023
0f44966
chore: remove some unused functions
theseanl Sep 6, 2023
eb2735d
chore: fix some unformatted codes
theseanl Sep 6, 2023
7e78a9e
chore: remove unused imports
theseanl Sep 6, 2023
7ffe09e
chore: comment formatting, remove duplicate functionality
theseanl Sep 6, 2023
d60b5b1
fix: brace-enclosed embellishment token support
theseanl Sep 6, 2023
047fc2f
chore: pollish comments, apply formatting
theseanl Sep 6, 2023
6bfbfe9
fix: order of embellishments shouldn't matter
theseanl Sep 8, 2023
2501548
feat: support non-punctuation optional tokens
theseanl Sep 8, 2023
58921fe
test: add a few more tests for delimiters
theseanl Sep 8, 2023
201461f
chore: use type assertions instead of type casting for
theseanl Sep 8, 2023
c6450ae
Merge branch 'main' into embellishments-support
theseanl Sep 8, 2023
d9a80bc
feat: make 'until' that requires splitting a string work
theseanl Sep 9, 2023
ee97bad
chore: run prettier
theseanl Sep 13, 2023
5897e7d
chore: add eslint
theseanl Sep 13, 2023
5839b73
test: \xxx^{a_b} in attach-arguments-in-array.test.ts
theseanl Sep 13, 2023
71ccf8c
chore: remove unused function in gobble-single-argument.ts
theseanl Sep 13, 2023
052b4ff
fix: whitespaces between several embellishment arguments should be
theseanl Sep 13, 2023
574d409
chore: move .prettierrc.json to package.json and run prettier
theseanl Sep 14, 2023
0ac4a93
chore: remove no-var rule from eslint
theseanl Sep 14, 2023
815024d
refactor: make gobbleSingleArgument return Ast.Argument | null
theseanl Sep 15, 2023
b718174
chore: remove a loop with constant condition
theseanl Sep 15, 2023
26b1dfb
fix: types in structured-clone
theseanl Sep 16, 2023
3a3b6cc
Merge branch 'main' into embellishments-support
siefkenj Oct 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ directly to the correct folder during development.

### Testing

Tests in a specific workspace can be run via `npx jest` in that workspace. These for the whole project can be run via `npm run tests` in the
Tests in a specific workspace can be run via `npx jest` in that workspace. These for the whole project can be run via `npm run test` in the
root directory.

### Readme Generation and Consistency
Expand Down
Empty file modified package-lock.json
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { arg } from "@unified-latex/unified-latex-builder";
import { Argument, ArgumentParser } from "@unified-latex/unified-latex-types";
import { parse as parseArgspec } from "@unified-latex/unified-latex-util-argspec";
import { Node } from "@unified-latex/unified-latex-util-argspec/libs/argspec-types";
import { gobbleSingleArgument } from "@unified-latex/unified-latex-util-arguments";
import { assertSingleArgument, gobbleSingleArgument } from "@unified-latex/unified-latex-util-arguments";
import { match } from "@unified-latex/unified-latex-util-match";

const argSpecM = parseArgspec("m")[0];
Expand All @@ -17,8 +17,9 @@ const argSpecRDelim: { [delim: string]: Node } = {};
export const argumentParser: ArgumentParser = (nodes, startPos) => {
const { argument: optionalArg, nodesRemoved: optionalArgNodesRemoved } =
gobbleSingleArgument(nodes, argSpecO, startPos);
assertSingleArgument(optionalArg);

let codeArg: Argument | null = null;
let codeArg: Argument | Argument[] | null = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore, right?

let codeArgNodesRemoved: number = 0;
const nextNode = nodes[startPos];
if (match.group(nextNode)) {
Expand All @@ -37,6 +38,7 @@ export const argumentParser: ArgumentParser = (nodes, startPos) => {
codeArg = delimArg.argument;
codeArgNodesRemoved = delimArg.nodesRemoved;
}
assertSingleArgument(codeArg);

return {
args: [optionalArg || arg(null), codeArg || arg(null)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { arg } from "@unified-latex/unified-latex-builder";
import { Argument, ArgumentParser } from "@unified-latex/unified-latex-types";
import { parse as parseArgspec } from "@unified-latex/unified-latex-util-argspec";
import { Node } from "@unified-latex/unified-latex-util-argspec/libs/argspec-types";
import { gobbleSingleArgument } from "@unified-latex/unified-latex-util-arguments";
import { assertSingleArgument, gobbleSingleArgument } from "@unified-latex/unified-latex-util-arguments";
import { match } from "@unified-latex/unified-latex-util-match";

const argSpecM = parseArgspec("m")[0];
Expand All @@ -17,11 +17,13 @@ const argSpecRDelim: { [delim: string]: Node } = {};
export const argumentParser: ArgumentParser = (nodes, startPos) => {
const { argument: optionalArg, nodesRemoved: optionalArgNodesRemoved } =
gobbleSingleArgument(nodes, argSpecO, startPos);
assertSingleArgument(optionalArg);

const { argument: languageArg, nodesRemoved: languageArgNodesRemoved } =
gobbleSingleArgument(nodes, argSpecM, startPos);
assertSingleArgument(languageArg);

let codeArg: Argument | null = null;
let codeArg: Argument | Argument[] | null = null;
let codeArgNodesRemoved: number = 0;
const nextNode = nodes[startPos];
if (match.group(nextNode)) {
Expand All @@ -40,6 +42,7 @@ export const argumentParser: ArgumentParser = (nodes, startPos) => {
codeArg = delimArg.argument;
codeArgNodesRemoved = delimArg.nodesRemoved;
}
assertSingleArgument(codeArg);

return {
args: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ArgSpecAst as ArgSpec,
parse as parseArgspec,
} from "@unified-latex/unified-latex-util-argspec";
import { ArgumentParser } from "@unified-latex/unified-latex-types";
import { Argument, ArgumentParser } from "@unified-latex/unified-latex-types";
import { gobbleSingleArgument } from "@unified-latex/unified-latex-util-arguments";
import { match } from "@unified-latex/unified-latex-util-match";
import { scan } from "@unified-latex/unified-latex-util-scan";
Expand Down Expand Up @@ -44,7 +44,7 @@ export const tikzCommandArgumentParser: ArgumentParser = (nodes, startPos) => {
const {
argument: _optionalArgument,
nodesRemoved: optionalArgumentNodesRemoved,
} = gobbleSingleArgument(nodes, OPTIONAL_ARGUMENT_ARG_SPEC, pos);
} = gobbleSingleArgument(nodes, OPTIONAL_ARGUMENT_ARG_SPEC, pos) as { argument: Argument, nodesRemoved: number };
nodesRemoved += optionalArgumentNodesRemoved;
const optionalArg = _optionalArgument || blankArg();

Expand Down
2 changes: 1 addition & 1 deletion packages/unified-latex-util-argspec/libs/argspec-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function printRaw(node: ArgSpec.Ast, root = false): string {

const decorators = getDecorators(node);
const defaultArg = (node as ArgSpec.DefaultArgument).defaultArg
? printRaw((node as ArgSpec.DefaultArgument).defaultArg)
? printRaw((node as ArgSpec.DefaultArgument).defaultArg!)
: "";
let spec = decorators;

Expand Down
8 changes: 4 additions & 4 deletions packages/unified-latex-util-argspec/libs/argspec-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface LeadingWhitespace {
noLeadingWhitespace: boolean | undefined;
}
export interface DefaultArgument {
defaultArg: Group;
defaultArg?: Group;
}
interface Verbatim extends Arg {
type: "verbatim";
Expand All @@ -34,14 +34,14 @@ interface OptionalToken extends LeadingWhitespace, AstNode {
type: "optionalToken";
token: string;
}
interface Embellishment extends DefaultArgument, AstNode {
export interface Embellishment extends DefaultArgument, AstNode {
type: "embellishment";
embellishmentTokens: string[];
embellishmentTokens: (Group|string)[];
}
interface Mandatory extends LeadingWhitespace, DefaultArgument, Arg {
type: "mandatory";
}
interface Group extends AstNode {
export interface Group extends AstNode {
type: "group";
content: (Group | string)[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export function gobbleArguments(
startPos
);
if (argument) {
args.push(argument);
if (Array.isArray(argument)) {
args.push(...argument)
} else {
args.push(argument);
}
nodesRemoved += removed;
} else {
args.push(arg([], { openMark: "", closeMark: "" }));
Expand Down
Loading