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

Parse setting macros like lineskip #111

Open
rrrnld opened this issue Aug 15, 2024 · 1 comment
Open

Parse setting macros like lineskip #111

rrrnld opened this issue Aug 15, 2024 · 1 comment

Comments

@rrrnld
Copy link
Contributor

rrrnld commented Aug 15, 2024

How would I parse macros like this?

\topskip=40pt
\parskip=10pt
\parindent=0pt
\baselineskip=15pt

I have tried this:

const macrosWithSetting: {
  signature?: string
  argumentParser: ArgumentParser
} = {
  argumentParser: (nodes, startPos) => {
    // parses things like `\lineskip=-\baselineskip`
    // nodes[startPos] is the equality sign
    const value = nodes[startPos + 1]
    const args = [
      value, // value or "-"
      ...(value.type === 'string' && value.content === '-' // actual value if value === '-'
        ? [nodes[startPos + 2]]
        : []),
    ].map((n) => arg(n))
    return {
      args,
      nodesRemoved: args.length,
    }
  },
}

But it doesn't to collect the arguments / remove them from the AST.

@siefkenj
Copy link
Owner

In your function you should actually mutate the array by using .splice on nodes. That is why nodesRemoved is important, so that the caller knows how the array changed.

If you check in the linters, there should be some code that detects = followed by units that you could use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants