From 94edfbc8c7d62d700dfb59334a0ed3beedd49493 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 5 Aug 2024 17:20:00 +0800 Subject: add macros generating macros feature. --- spec/inputs/macro.yue | 33 +++++++++++++++++++++++++++++++++ spec/inputs/macro_export.yue | 18 ++++++++++++++++++ 2 files changed, 51 insertions(+) (limited to 'spec/inputs') diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue index ae14f53..a2e1046 100644 --- a/spec/inputs/macro.yue +++ b/spec/inputs/macro.yue @@ -5,6 +5,39 @@ import "macro_export" as { import "macro_todo" as $ +macro WindowFlag = $enum( + NoNav + NoDecoration + NoTitleBar + NoResize + NoMove + NoScrollbar + NoScrollWithMouse + NoCollapse + AlwaysAutoResize + NoSavedSettings + NoInputs + MenuBar + HorizontalScrollbar + NoFocusOnAppearing + NoBringToFrontOnFocus + AlwaysVerticalScrollbar + AlwaysHorizontalScrollbar + NoNavInputs + NoNavFocus + UnsavedDocument +) + +print $WindowFlag AlwaysAutoResize +print $WindowFlag( + NoNav + NoDecoration + NoTitleBar + NoResize + NoMove + NoScrollbar +) + $asserts item == nil $myconfig false diff --git a/spec/inputs/macro_export.yue b/spec/inputs/macro_export.yue index eec5848..cc7d459 100644 --- a/spec/inputs/macro_export.yue +++ b/spec/inputs/macro_export.yue @@ -44,6 +44,24 @@ do _dst_.#{field} = _src_.#{field} "}" +export macro enum = (...) -> + items = {...} + items = [item\gsub('"', '') for item in *items] + itemSet = {item, true for item in *items} + (...) -> + count = select "#", ... + if 1 < count + result = "[" + for i = 1, count + item = select i, ... + error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] + result ..= "\"#{item}\"," + result .. "]" + else + item = select 1, ... + error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] + "\"#{item}\"" + $ -> global debugMode = true global debugMacro = true -- cgit v1.2.3-55-g6feb