Add magic constants: __FILE__
and __LINE__
#36
Labels
feature-request
Any request for a new feature of the language. Includes both syntax and library features.
good first issue
An issue that provides a good intro to working with the Myst codebase. Be helpful!
syntax
Any issue relating to the syntax of Myst.
Milestone
Magic constants are useful for many things. In particular,
__FILE__
is great for making portable scripts, and__LINE__
can help debug tooling and reporting to end users.A simple description of their behavior:
__FILE__
returns the absolute path to the file that it appears in. For example, in a file~/test.mt
, the constant might resolve to/home/user/test.mt
. The path is always the file containing the constant, not affected byrequire
statements or likewise.__LINE__
returns an integer representing the line number of the current file that the constant appears on, starting from 1. For example, the constant in the following code will evaluate to3
.The implementation of these constants can be easily done using the
location
property that allnode
s already have. A new node type,MagicConstant
can be introduced, that has atype
property indicating what the constant is (probably:line
for__LINE__
, or:file
for__FILE__
).The text was updated successfully, but these errors were encountered: