Replies: 3 comments 5 replies
-
|
I see the use for this. Let me think a bit on how to provide this functionality without disrupting the existing syntax. I would probably use a special comment syntax, like Or copy JavaScript's map files... |
Beta Was this translation helpful? Give feedback.
-
|
For your map solution, adding a set of Maybe lines like this?
I'll be interested to see what you come up with. |
Beta Was this translation helpful? Give feedback.
-
|
Cool, just tripped over this in the overview, nice to see this use case is a first-class use case :).
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
Forgive (& clue bat) me if I missed something in the docs about this, thanks!
One of the use cases for embeddable scripting languages like Rhai is to be the intermediate language between a DSL with a custom, possibly pretty alien-to-rhai, syntax. For example, the (a) end user writes a template file, markdown or YAML file (like an OpenAPI spec), or a field in a GUI (say, something like a form or spreadsheet), then (b) some Rust code transpiles that source syntax into Rhai as the intermediate form, and (c) executes it using the Rhai engine.
In this use case, since the user is manipulating something other than the generated Rhai code, when errors happen, it's nice to have them refer to the original position (typically file, line and column, but could be a spreadsheet cell or the path to a node in an OpenAPI spec, for example).
If feasible, could Rhai support something like the
#linedirective (though, perhaps styled more like a Rust macro....) to set the Rhai compiler's idea of source location (string, line and column, say), and then have the errors report that location?C and Perl have
#lineand it makes them really nice targets for transpilers. Last I did this in Python or Lua, etc., they don't support anything like this, which makes it hard for users to understand error messages, hints, debug output, etc., when using them as transpiler targets.One possible example, might be to take a template like this:
and transpile it to something like this using
source_loc!()to tell the Rhai parser the name of the source file andloc!()to tell it where the enclosed tokens occur in that source. They are just one simple syntax (and more powerful than the hoary old#line!), there are probably better.In this case,
loc!(line_num, col_num, <tokens>)is a bit like thequote!()macro we know and love from proc macros...Beta Was this translation helpful? Give feedback.
All reactions