-
Notifications
You must be signed in to change notification settings - Fork 7
[WIP] Add lang: TeX #265
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
Draft
jared-hughes
wants to merge
12
commits into
main
Choose a base branch
from
addlang-tex
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[WIP] Add lang: TeX #265
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d83a8f
Initial TeX support
jared-hughes 349f49b
Cleanups from review
jared-hughes 95e6a1d
Add emit/parse for FunctionDefinition and ScanningMacroCall
jared-hughes 53da72f
Support expressions inside prints
jared-hughes 958ad0d
Revert forRangeToWhile block requirement
jared-hughes 1fdf278
Handle for-range either in block or at root.
jared-hughes a0479df
Support mod, sub, calculation inside comparison
jared-hughes 7aa5dee
merge main
MichalMarsalek 0bb656d
Merge branch 'main' into tex-merge
MichalMarsalek bd54f68
remove tempId func
MichalMarsalek 9e3856d
Merge branch 'main' into addlang-tex
MichalMarsalek ca70120
return block not array of nodes from plugin
MichalMarsalek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { Spine } from "../common/Spine"; | ||
| import { | ||
| type Identifier, | ||
| type BaseNode, | ||
| type Node, | ||
| type IDCastable, | ||
| castID, | ||
| } from "./IR"; | ||
|
|
||
| // This file is for functions and macros. | ||
|
|
||
| /** | ||
| * FunctionDefinition is currently only used for TeX, where the identifiers are | ||
| * emitted as macro symbols: | ||
| * | ||
| * \def\f#1#2{(#1,#2,#1,#2)} | ||
| * | ||
| * While TeX calls these "macros", they happen at runtime. | ||
| * Macros (like #define from C) are compile-time. | ||
| * | ||
| * Note this currently assumes the macros don't do any scanning. | ||
| * E.g. TeX supports | ||
| * \def\f#1,#2;{#1#2#1#2} \f123,456; | ||
| * in lieu of | ||
| * \def\f#1#2{#1#2#1#2} \f{123}{456} | ||
| * For now, we don't allow the former. Allowing it will need a different node type. | ||
| */ | ||
| export interface FunctionDefinition extends BaseNode { | ||
| readonly kind: "FunctionDefinition"; | ||
| readonly name: Identifier; | ||
| readonly args: readonly Identifier[]; | ||
| readonly body: Node; | ||
| /** Does the definition apply to all parent scopes too? | ||
| * In TeX: false = \def or \edef; true = \gdef or \xdef */ | ||
| readonly isGlobal: boolean; | ||
| /** Does the definition expand its argument before defining? | ||
| * In TeX: false = \def or \gdef; true = \edef or \xdef */ | ||
| readonly isExpanded: boolean; | ||
| } | ||
|
|
||
| export function functionDefinition( | ||
| name: IDCastable, | ||
| args: readonly IDCastable[], | ||
| body: Node, | ||
| opts: { isGlobal?: boolean; isExpanded?: boolean } = {}, | ||
| ): FunctionDefinition { | ||
| const isExpanded = opts.isExpanded ?? false; | ||
| if (isExpanded && args.length > 0) { | ||
| throw new Error("Expanded definition cannot have any args."); | ||
| } | ||
| return { | ||
| kind: "FunctionDefinition", | ||
| name: castID(name), | ||
| args: args.map(castID), | ||
| body, | ||
| isGlobal: opts.isGlobal ?? false, | ||
| isExpanded, | ||
| }; | ||
| } | ||
|
|
||
| export function functionDefinitionNestingDepth(s: Spine, d: number = 0) { | ||
| if (s.node.kind === "FunctionDefinition") ++d; | ||
| if (s.parent === null) return d; | ||
| return functionDefinitionNestingDepth(s.parent, d); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.