This commit is contained in:
Catalin Constantin Mititiuc 2025-05-28 18:10:56 -07:00
parent 57074caae9
commit cd43c8f323
17 changed files with 23 additions and 1417 deletions

View File

@ -1,717 +0,0 @@
{
"custom-styles": {
"Alerts": {
"Region Marker": {
"selected-text-color": "#6db8c7",
"text-color": "#6db8c7"
}
},
"Apache Configuration": {
"Directives": {
"bold": false
}
},
"Bash": {
"Path": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Redirection": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Variable": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
}
},
"C": {
"Prep. Lib": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
}
},
"C++": {
"Qt Macros": {
"bold": false,
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
}
},
"CMake": {
"Builtin Variable": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
}
},
"CSS": {
"Color": {
"bold": false
},
"Property": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Selector Class": {
"italic": true
},
"Selector Id": {
"bold": false,
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Selector Pseudo": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Selector Tag": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Unit": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
}
},
"D": {
"Attribute": {
"bold": false
},
"Declarator": {
"bold": false
},
"Deprecated": {
"bold": false
},
"Expression": {
"bold": false
},
"Module": {
"bold": false
},
"Property": {
"bold": false
},
"Template": {
"bold": false
}
},
"Diff": {
"Added line": {
"selected-text-color": "#5fde38",
"text-color": "#50fa7b"
},
"Changed line (new)": {
"background-color": "#50fa7b",
"selected-text-color": "#5fde38",
"text-color": "#50fa7b"
},
"Changed line (old)": {
"selected-text-color": "#e66eb4",
"text-color": "#ff79c6"
},
"Removed line": {
"selected-text-color": "#e66eb4",
"text-color": "#ff79c6"
}
},
"Doxygen": {
"Custom Tags": {
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"Description": {
"selected-text-color": "#c58e53",
"text-color": "#c58e53"
},
"Entities": {
"bold": false
},
"HTML Tag": {
"bold": false,
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"Region": {
"selected-text-color": "#6db8c7",
"text-color": "#6db8c7"
},
"Tags": {
"bold": false,
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"Word": {
"bold": false,
"selected-text-color": "#c58e53",
"text-color": "#c58e53"
}
},
"GNU Assembler": {
"Label": {
"underline": true
}
},
"Go": {
"Builtin Function": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
}
},
"HTML": {
"Doctype": {
"bold": false,
"italic": false,
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
}
},
"ISO C++": {
"Prep. Lib": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Standard Suffix": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"UDL Numeric Suffix": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"UDL String Suffix": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
}
},
"Intel x86 (NASM)": {
"Label": {
"underline": true
},
"Registers": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
}
},
"JSON": {
"Style_Keyword": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Style_String_Key": {
"italic": false
}
},
"JavaScript": {
"Built-in Objects": {
"italic": true
},
"Function (Built-in)": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Object Member": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
}
},
"JavaScript React (JSX)": {
"Attribute": {
"italic": true
},
"Component Tag": {
"bold": false,
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
}
},
"Makefile": {
"Operator": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Prereq": {
"italic": false,
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Target": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Variable": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
}
},
"Markdown": {
"Blockquote: Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Email": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Emphasis Text": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Header H1": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Header H2": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Header H3": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Header H4": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Header H5": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Header H6": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Inline Image": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
},
"Inline Image: Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"List: Emphasis Text": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"List: Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"List: Strong Text": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
},
"Normal Text: Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Reference Image": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
},
"Reference-Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Reference-Link Name": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6",
"underline": false
},
"Reference-Link Target": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Reference-Link Target: Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Reference-Link: Link": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Strong Text": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
}
},
"Modelines": {
"Variable": {
"selected-text-color": "#c58e53",
"text-color": "#c58e53"
}
},
"PHP/PHP": {
"Backslash Code": {
"bold": false,
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Control Structures": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Library Constant": {
"bold": false,
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Special Variable": {
"bold": false,
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Variable": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
}
},
"Pascal": {
"ISO/Delphi Extended": {
"text-color": "#ff79c6"
}
},
"Odin": {
"Context Variable": {
"italic": true,
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
}
},
"Python": {
"Builtin Function": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Special Variable": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
}
},
"QMake": {
"Backslash Code": {
"bold": false
},
"Predefined Variable": {
"bold": false,
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
}
},
"Ruby": {
"Access Control": {
"bold": false,
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Default globals": {
"bold": false
},
"Definition": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Global Constant": {
"bold": false,
"italic": true,
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Kernel methods": {
"bold": false,
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Message": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Module mixin methods": {
"bold": false
},
"Pseudo variable": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
}
},
"Rust": {
"Attribute": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
},
"CConstant": {
"bold": false
},
"CType": {
"italic": true,
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Constant": {
"bold": false
},
"Definition": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Lifetime": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Macro": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Scope": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
},
"Self": {
"italic": true,
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Trait": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
}
},
"SPDX-Comments": {
"SPDX Deprecated License": {
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"SPDX Deprecated License Exception": {
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"SPDX License": {
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"SPDX License Exception": {
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"SPDX Tag": {
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
},
"SPDX Value": {
"selected-text-color": "#d465a7",
"text-color": "#d465a7"
}
},
"TypeScript": {
"Built-in Objects": {
"italic": true
},
"Function (Built-in)": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Object Member": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
}
},
"TypeScript React (TSX)": {
"Attribute": {
"italic": true
},
"Component Tag": {
"bold": false,
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
}
},
"YAML": {
"Attribute": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Key": {
"bold": false,
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"List": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
}
}
},
"editor-colors": {
"BackgroundColor": "#282a36",
"BracketMatching": "#7c62a5",
"CodeFolding": "#44475a",
"CurrentLine": "#44475a",
"CurrentLineNumber": "#f8f8f2",
"IconBorder": "#282a36",
"IndentationLine": "#6272a4",
"LineNumbers": "#6272a4",
"MarkBookmark": "#8be9fd",
"MarkBreakpointActive": "#ff5555",
"MarkBreakpointDisabled": "#bd93f9",
"MarkBreakpointReached": "#f1fa8c",
"MarkError": "#ff5555",
"MarkExecution": "#44475a",
"MarkWarning": "#ffb86c",
"ModifiedLines": "#ff79c6",
"ReplaceHighlight": "#2c8843",
"SavedLines": "#50fa7b",
"SearchHighlight": "#566591",
"Separator": "#45474e",
"SpellChecking": "#ff5555",
"TabMarker": "#6272a4",
"TemplateBackground": "#282a36",
"TemplateFocusedPlaceholder": "#282a36",
"TemplatePlaceholder": "#282a36",
"TemplateReadOnlyPlaceholder": "#44475a",
"TextSelection": "#44475a",
"WordWrapMarker": "#282a36"
},
"metadata": {
"copyright": [
"SPDX-FileCopyrightText: 2016 Dracula Theme",
"SPDX-FileCopyrightText: 2020 Christoph Cullmann <cullmann@kde.org>"
],
"license": "SPDX-License-Identifier: MIT",
"name": "Dracula",
"revision": 10
},
"text-styles": {
"Alert": {
"bold": true,
"selected-text-color": "#ff5555",
"text-color": "#ff5555"
},
"Annotation": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Attribute": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"BaseN": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"BuiltIn": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Char": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Comment": {
"selected-text-color": "#6272a4",
"text-color": "#6272a4"
},
"CommentVar": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Constant": {
"bold": true,
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"ControlFlow": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"DataType": {
"italic": true,
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"DecVal": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Documentation": {
"selected-text-color": "#ffb86c",
"text-color": "#ffb86c"
},
"Error": {
"selected-text-color": "#ff5555",
"text-color": "#ff5555",
"underline": true
},
"Extension": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"Float": {
"selected-text-color": "#bd93f9",
"text-color": "#bd93f9"
},
"Function": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Import": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Information": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Keyword": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"Normal": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
},
"Operator": {
"selected-text-color": "#f8f8f2",
"text-color": "#f8f8f2"
},
"Others": {
"selected-text-color": "#50fa7b",
"text-color": "#50fa7b"
},
"Preprocessor": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"RegionMarker": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"SpecialChar": {
"selected-text-color": "#ff79c6",
"text-color": "#ff79c6"
},
"SpecialString": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"String": {
"selected-text-color": "#f1fa8c",
"text-color": "#f1fa8c"
},
"Variable": {
"selected-text-color": "#8be9fd",
"text-color": "#8be9fd"
},
"VerbatimString": {
"selected-text-color": "#d7e60a",
"text-color": "#d7e60a"
},
"Warning": {
"selected-text-color": "#ff5555",
"text-color": "#ff5555"
}
}
}

View File

@ -1,634 +0,0 @@
## example.moon
```moonscript
-- transform.moon
-- Leaf Corcoran (leafot@gmail.com) 2011
--
-- This is part of the MoonScript compiler. See <http://moonscript.org>
-- MoonScript is licensed under the MIT License
--
module "moonscript.transform", package.seeall
types = require "moonscript.types"
util = require "moonscript.util"
data = require "moonscript.data"
interp = "welcome to my #{show}!"
import reversed from util
import ntype, build, smart_node, is_slice from types
import insert from table
export Statement, Value, NameProxy, LocalName, Run
-- always declares as local
class LocalName
new: (@name) => self[1] = "temp_name"
get_name: => @name
class NameProxy
new: (@prefix) =>
self[1] = "temp_name"
get_name: (scope) =>
if not @name
@name = scope\free_name @prefix, true
@name
chain: (...) =>
items = {...} -- todo: fix ... propagation
items = for i in *items
if type(i) == "string"
{"dot", i}
else
i
build.chain {
base: self
unpack items
}
index: (key) =>
build.chain {
base: self, {"index", key}
}
__tostring: =>
if @name
("name<%s>")\format @name
else
("name<prefix(%s)>")\format @prefix
class Run
new: (@fn) =>
self[1] = "run"
call: (state) =>
self.fn state
-- transform the last stm is a list of stms
-- will puke on group
apply_to_last = (stms, fn) ->
-- find last (real) exp
last_exp_id = 0
for i = #stms, 1, -1
stm = stms[i]
if stm and util.moon.type(stm) != Run
last_exp_id = i
break
return for i, stm in ipairs stms
if i == last_exp_id
fn stm
else
stm
-- is a body a sindle expression/statement
is_singular = (body) ->
return false if #body != 1
if "group" == ntype body
is_singular body[2]
else
true
constructor_name = "new"
class Transformer
new: (@transformers, @scope) =>
@seen_nodes = {}
transform: (scope, node, ...) =>
-- print scope, node, ...
return node if @seen_nodes[node]
@seen_nodes[node] = true
while true
transformer = @transformers[ntype node]
res = if transformer
transformer(scope, node, ...) or node
else
node
return node if res == node
node = res
__call: (node, ...) =>
@transform @scope, node, ...
instance: (scope) =>
Transformer @transformers, scope
can_transform: (node) =>
@transformers[ntype node] != nil
construct_comprehension = (inner, clauses) ->
current_stms = inner
for _, clause in reversed clauses
t = clause[1]
current_stms = if t == "for"
_, names, iter = unpack clause
{"foreach", names, iter, current_stms}
elseif t == "when"
_, cond = unpack clause
{"if", cond, current_stms}
else
error "Unknown comprehension clause: "..t
current_stms = {current_stms}
current_stms[1]
Statement = Transformer {
assign: (node) =>
_, names, values = unpack node
-- bubble cascading assigns
if #values == 1 and types.cascading[ntype values[1]]
values[1] = @transform.statement values[1], (stm) ->
t = ntype stm
if types.is_value stm
{"assign", names, {stm}}
else
stm
build.group {
{"declare", names}
values[1]
}
else
node
export: (node) =>
-- assign values if they are included
if #node > 2
if node[2] == "class"
cls = smart_node node[3]
build.group {
{"export", {cls.name}}
cls
}
else
build.group {
node
build.assign {
names: node[2]
values: node[3]
}
}
else
nil
update: (node) =>
_, name, op, exp = unpack node
op_final = op\match "^(.+)=$"
error "Unknown op: "..op if not op_final
build.assign_one name, {"exp", name, op_final, exp}
import: (node) =>
_, names, source = unpack node
stubs = for name in *names
if type(name) == "table"
name
else
{"dot", name}
real_names = for name in *names
type(name) == "table" and name[2] or name
if type(source) == "string"
build.assign {
names: real_names
values: [build.chain { base: source, stub} for stub in *stubs]
}
else
source_name = NameProxy "table"
build.group {
{"declare", real_names}
build["do"] {
build.assign_one source_name, source
build.assign {
names: real_names
values: [build.chain { base: source_name, stub} for stub in *stubs]
}
}
}
comprehension: (node, action) =>
_, exp, clauses = unpack node
action = action or (exp) -> {exp}
construct_comprehension action(exp), clauses
-- handle cascading return decorator
if: (node, ret) =>
if ret
smart_node node
-- mutate all the bodies
node['then'] = apply_to_last node['then'], ret
for i = 4, #node
case = node[i]
body_idx = #node[i]
case[body_idx] = apply_to_last case[body_idx], ret
node
with: (node, ret) =>
_, exp, block = unpack node
scope_name = NameProxy "with"
build["do"] {
build.assign_one scope_name, exp
Run => @set "scope_var", scope_name
build.group block
if ret
ret scope_name
}
foreach: (node) =>
smart_node node
if ntype(node.iter) == "unpack"
list = node.iter[2]
index_name = NameProxy "index"
list_name = NameProxy "list"
slice_var = nil
bounds = if is_slice list
slice = list[#list]
table.remove list
table.remove slice, 1
slice[2] = if slice[2] and slice[2] != ""
max_tmp_name = NameProxy "max"
slice_var = build.assign_one max_tmp_name, slice[2]
{"exp", max_tmp_name, "<", 0
"and", {"length", list_name}, "+", max_tmp_name
"or", max_tmp_name }
else
{"length", list_name}
slice
else
{1, {"length", list_name}}
build.group {
build.assign_one list_name, list
slice_var
build["for"] {
name: index_name
bounds: bounds
body: {
{"assign", node.names, {list_name\index index_name}}
build.group node.body
}
}
}
switch: (node, ret) =>
_, exp, conds = unpack node
exp_name = NameProxy "exp"
-- convert switch conds into if statment conds
convert_cond = (cond) ->
t, case_exp, body = unpack cond
out = {}
insert out, t == "case" and "elseif" or "else"
if t != "else"
insert out, {"exp", case_exp, "==", exp_name} if t != "else"
else
body = case_exp
if ret
body = apply_to_last body, ret
insert out, body
out
first = true
if_stm = {"if"}
for cond in *conds
if_cond = convert_cond cond
if first
first = false
insert if_stm, if_cond[2]
insert if_stm, if_cond[3]
else
insert if_stm, if_cond
build.group {
build.assign_one exp_name, exp
if_stm
}
class: (node) =>
_, name, parent_val, body = unpack node
-- split apart properties and statements
statements = {}
properties = {}
for item in *body
switch item[1]
when "stm"
insert statements, item[2]
when "props"
for tuple in *item[2,]
insert properties, tuple
-- find constructor
constructor = nil
properties = for tuple in *properties
if tuple[1] == constructor_name
constructor = tuple[2]
nil
else
tuple
parent_cls_name = NameProxy "parent"
base_name = NameProxy "base"
self_name = NameProxy "self"
cls_name = NameProxy "class"
if not constructor
constructor = build.fndef {
args: {{"..."}}
arrow: "fat"
body: {
build["if"] {
cond: parent_cls_name
then: {
build.chain { base: "super", {"call", {"..."}} }
}
}
}
}
else
smart_node constructor
constructor.arrow = "fat"
cls = build.table {
{"__init", constructor}
{"__base", base_name}
{"__name", {"string", '"', name}} -- "quote the string"
{"__parent", parent_cls_name}
}
-- look up a name in the class object
class_lookup = build["if"] {
cond: {"exp", "val", "==", "nil", "and", parent_cls_name}
then: {
parent_cls_name\index"name"
}
}
insert class_lookup, {"else", {"val"}}
cls_mt = build.table {
{"__index", build.fndef {
args: {{"cls"}, {"name"}}
body: {
build.assign_one LocalName"val", build.chain {
base: "rawget", {"call", {base_name, "name"}}
}
class_lookup
}
}}
{"__call", build.fndef {
args: {{"cls"}, {"..."}}
body: {
build.assign_one self_name, build.chain {
base: "setmetatable"
{"call", {"{}", base_name}}
}
build.chain {
base: "cls.__init"
{"call", {self_name, "..."}}
}
self_name
}
}}
}
cls = build.chain {
base: "setmetatable"
{"call", {cls, cls_mt}}
}
value = nil
with build
value = .block_exp {
Run =>
@set "super", (block, chain) ->
if chain
slice = [item for item in *chain[3,]]
new_chain = {"chain", parent_cls_name}
head = slice[1]
if head == nil
return parent_cls_name
switch head[1]
-- calling super, inject calling name and self into chain
when "call"
calling_name = block\get"current_block"
slice[1] = {"call", {"self", unpack head[2]}}
act = if ntype(calling_name) != "value" then "index" else "dot"
insert new_chain, {act, calling_name}
-- colon call on super, replace class with self as first arg
when "colon"
call = head[3]
insert new_chain, {"dot", head[2]}
slice[1] = { "call", { "self", unpack call[2] } }
insert new_chain, item for item in *slice
new_chain
else
parent_cls_name
.assign_one parent_cls_name, parent_val == "" and "nil" or parent_val
.assign_one base_name, {"table", properties}
.assign_one base_name\chain"__index", base_name
build["if"] {
cond: parent_cls_name
then: {
.chain {
base: "setmetatable"
{"call", {
base_name,
.chain { base: parent_cls_name, {"dot", "__base"}}
}}
}
}
}
.assign_one cls_name, cls
.assign_one base_name\chain"__class", cls_name
.group if #statements > 0 {
.assign_one LocalName"self", cls_name
.group statements
} else {}
cls_name
}
value = .group {
.declare names: {name}
.assign {
names: {name}
values: {value}
}
}
value
}
class Accumulator
body_idx: { for: 4, while: 3, foreach: 4 }
new: =>
@accum_name = NameProxy "accum"
@value_name = NameProxy "value"
@len_name = NameProxy "len"
-- wraps node and mutates body
convert: (node) =>
index = @body_idx[ntype node]
node[index] = @mutate_body node[index]
@wrap node
-- wrap the node into a block_exp
wrap: (node) =>
build.block_exp {
build.assign_one @accum_name, build.table!
build.assign_one @len_name, 0
node
@accum_name
}
-- mutates the body of a loop construct to save last value into accumulator
-- can optionally skip nil results
mutate_body: (body, skip_nil=true) =>
val = if not skip_nil and is_singular body
with body[1]
body = {}
else
body = apply_to_last body, (n) ->
build.assign_one @value_name, n
@value_name
update = {
{"update", @len_name, "+=", 1}
build.assign_one @accum_name\index(@len_name), val
}
if skip_nil
table.insert body, build["if"] {
cond: {"exp", @value_name, "!=", "nil"}
then: update
}
else
table.insert body, build.group update
body
default_accumulator = (node) =>
Accumulator!\convert node
implicitly_return = (scope) ->
fn = (stm) ->
t = ntype stm
if types.manual_return[t] or not types.is_value stm
stm
elseif types.cascading[t]
scope.transform.statement stm, fn
else
if t == "comprehension" and not types.comprehension_has_value stm
stm
else
{"return", stm}
fn
Value = Transformer {
for: default_accumulator
while: default_accumulator
foreach: default_accumulator
comprehension: (node) =>
a = Accumulator!
node = @transform.statement node, (exp) ->
a\mutate_body {exp}, false
a\wrap node
tblcomprehension: (node) =>
_, key_exp, value_exp, clauses = unpack node
accum = NameProxy "tbl"
dest = build.chain { base: accum, {"index", key_exp} }
inner = build.assign_one dest, value_exp
build.block_exp {
build.assign_one accum, build.table!
construct_comprehension {inner}, clauses
accum
}
fndef: (node) =>
smart_node node
node.body = apply_to_last node.body, implicitly_return self
node
if: (node) => build.block_exp { node }
with: (node) => build.block_exp { node }
switch: (node) =>
build.block_exp { node }
-- pull out colon chain
chain: (node) =>
stub = node[#node]
if type(stub) == "table" and stub[1] == "colon_stub"
table.remove node, #node
base_name = NameProxy "base"
fn_name = NameProxy "fn"
is_super = node[2] == "super"
@transform.value build.block_exp {
build.assign {
names: {base_name}
values: {node}
}
build.assign {
names: {fn_name}
values: {
build.chain { base: base_name, {"dot", stub[2]} }
}
}
build.fndef {
args: {{"..."}}
body: {
build.chain {
base: fn_name, {"call", {is_super and "self" or base_name, "..."}}
}
}
}
}
block_exp: (node) =>
_, body = unpack node
fn = nil
arg_list = {}
insert body, Run =>
if @has_varargs
insert arg_list, "..."
insert fn.args, {"..."}
fn = smart_node build.fndef body: body
build.chain { base: {"parens", fn}, {"call", arg_list} }
}
```

12
html/.gitignore vendored
View File

@ -1,8 +1,18 @@
app.css app.css
code.html code.html
example.moon.html
index.html index.html
moonscript.css moonscript.css
pandoc.css pandoc.css
posts/build-a-neovim-qt-appimage-from-source.html
posts/build-static-website-generator-part-1.html
posts/deploy-elixir-generated-html-with-docker-on-digitalocean.html
posts/fix-distortion-introduced-when-transforming-multiview-projections-to-isometric.html
posts/index.html posts/index.html
posts/open-an-iex-shell-from-an-elixir-script.html
posts/publish-markdown-documents-as-static-web-pages-with-pandoc-and-phoenix.html
posts/recursively-list-all-files-in-a-directory-with-elixir.html
posts/resize-a-qemu-disk-image.html
posts/set-up-a-gitweb-server.html
posts/start-erlangs-dialyzer-with-gui-from-a-docker-container.html
posts/test-mix-task-file-modify.html
pygments.css pygments.css

View File

@ -16,6 +16,8 @@ class PandocRenderer extends require "sitegen.renderers.markdown"
unescape_cosmo = @unescape_cosmo unescape_cosmo = @unescape_cosmo
escape_cosmo = @escape_cosmo escape_cosmo = @escape_cosmo
cmd: "pandoc --mathjax --lua-filter pygments.lua >"
pandoc: (md_source) => pandoc: (md_source) =>
fname = os.tmpname! fname = os.tmpname!
with io.popen _prepare_command(@@cmd, fname), "w" with io.popen _prepare_command(@@cmd, fname), "w"
@ -35,8 +37,6 @@ class PandocRenderer extends require "sitegen.renderers.markdown"
-- assert out\match('^<div class="highlight"><pre>(.-)\n?</pre></div>'), -- assert out\match('^<div class="highlight"><pre>(.-)\n?</pre></div>'),
-- "Failed to parse pygmentize result, is pygments installed?" -- "Failed to parse pygmentize result, is pygments installed?"
cmd: "pandoc >"
render: (page, md_source) => render: (page, md_source) =>
md_source = page\pipe "renderer.markdown.pre_render", md_source md_source = page\pipe "renderer.markdown.pre_render", md_source
md_source, escapes = escape_cosmo md_source md_source, escapes = escape_cosmo md_source

View File

@ -17,13 +17,6 @@ Site.config.out_dir = "html/"
-- Compile lua-filter used by Pandoc to highlight MoonScript syntax -- Compile lua-filter used by Pandoc to highlight MoonScript syntax
os.execute "moonc pygments.moon" os.execute "moonc pygments.moon"
-- Configure the command our custom renderer uses to convert markdown to html
rend = "renderers.markdown"
require(rend).cmd = "pandoc --mathjax --lua-filter pygments.lua >"
-- Insert custom renderer in the first position so it will be preferred
table.insert Site.default_renderers, 1, rend
-- Remove Pygments plugin -- Remove Pygments plugin
Site.default_plugins = for v in *Site.default_plugins Site.default_plugins = for v in *Site.default_plugins
if v\find "pygments" then continue else v if v\find "pygments" then continue else v
@ -109,30 +102,26 @@ sitegen.create =>
"—", blurb, a { "Read post →", class: "read-post-link", href: url } "—", blurb, a { "Read post →", class: "read-post-link", href: url }
} }
add_renderer "renderers.markdown"
add_all = (files) -> add_all = (files) ->
for path in *files [add path, {
add path, { target: target path, "/posts"
target: target path, "/posts" template: "post"
template: "post" is_a: "post"
is_a: "post" publish_date: publish_date extract_date path
publish_date: publish_date extract_date path id: extract_id path
id: extract_id path } for path in *files]
}
add "index.html", title: "Catalin Mititiuc" add "index.html", title: "Catalin Mititiuc"
add "blog.html", title: "Posts", target: "posts/index", template: "blog" add "blog.html", title: "Posts", target: "posts/index", template: "blog"
add "example.moon.md",
template: "post"
title: "MoonScript Example"
publish_date: publish_date date true
add "code.md", add "code.md",
template: "post" template: "post"
title: "Code Syntax Highlight Samples" title: "Code Syntax Highlight Samples"
publish_date: publish_date date true publish_date: publish_date date true
add_all files_from "docs" add_all files_from "posts"
copy "app.css" copy "app.css"
copy "pygments.css" copy "pygments.css"

42
test.md
View File

@ -1,42 +0,0 @@
```heex
<.header>
Listing Posts
</.header>
<.table id="posts" rows={@posts} row_click={&JS.navigate(~p"/posts/#{&1}")}>
<:col :let={post} label="id"><%= post.id %></:col>
<:action :let={post}>
<div class="sr-only">
<.link navigate={~p"/posts/#{post}"}>Show</.link>
</div>
</:action>
</.table>
```
```elixir
if config_env() != :prod do
# Configure pandoc (the version is required)
config :pandoc,
version: "3.6.1",
hello: [
args: fn extra_args ->
{_, [input_file], _} = OptionParser.parse(extra_args, switches: [])
~w(--output=../priv/static/posts/#{Path.rootname(input_file)}.html)
end,
cd: Path.expand("../documents", __DIR__)
]
end
```
```moon
class Thing
name: "unknown"
class Person extends Thing
say_name: => print "Hel#lo, I am #{@name}!"
with Person!
.name = "MoonScript"
\say_name!
```