Skip to content

Customize metaprocessor operators for DSL usage #140

Answered by edubart
stefanos82 asked this question in Q&A
Discussion options

You must be logged in to vote

The v1 is possible and is easy to do because you just did some little cosmetic changes (replacing tokens):

First create a test.nelua file, contained the required code to make that work:

##[[
-- Load the language syntax definitions
local syntaxdefs = require 'nelua.syntaxdefs'
-- Load the AST builder/parser
local aster = require 'nelua.aster'
local grammar = syntaxdefs.grammar
-- Patch the grammar with the new syntax
grammar = grammar:gsub(
  "PREPROCESS%s*<%-%-[^\n]+\n",
  "PREPROCESS <-- `<?` 'nl' {(!`?>` .)*} @`?>`\n")
grammar = grammar:gsub(
  "PreprocessExpr%s*<%=%=[^\n]+\n",
  "PreprocessExpr  <== `${` {@expr->0} @`}`\n")
-- Register the compiler
aster.register_syntax({
  extension =…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@stefanos82
Comment options

Answer selected by edubart
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants