diff --git a/examples/3sum.janet b/examples/3sum.janet index 21bac9bd..9b3c1d6a 100644 --- a/examples/3sum.janet +++ b/examples/3sum.janet @@ -11,4 +11,4 @@ (def k (get tab (- 0 s@i s@j))) (when (and k (not= k i) (not= k j) (not= i j)) (put solutions {i true j true k true} true)))) - (map keys (keys solution))) + (map keys (keys solution))) \ No newline at end of file diff --git a/grammar/janet.tmLanguage b/grammar/janet.tmLanguage new file mode 100644 index 00000000..77fb9efe --- /dev/null +++ b/grammar/janet.tmLanguage @@ -0,0 +1,330 @@ + + + + + fileTypes + + janet + + foldingStartMarker + \{ + foldingStopMarker + \} + foldingStartMarker + \[ + foldingStopMarker + \] + foldingStartMarker + \( + foldingStopMarker + \) + keyEquivalent + ^~L + name + Janet + patterns + + + include + #all + + + repository + + all + + patterns + + + include + #comment + + + include + #parens + + + include + #brackets + + + include + #braces + + + include + #readermac + + + include + #literal + + + include + #corelib + + + include + #r-number + + + include + #dec-number + + + include + #hex-number + + + include + #keysym + + + include + #symbol + + + include + #string + + + include + #longstring + + + + comment + + captures + + 1 + + name + punctuation.definition.comment.janet + + + match + (#).*$ + name + comment.line.janet + + braces + + begin + (@?{) + captures + + 1 + + name + punctuation.definition.braces.begin.janet + + + end + (}) + captures + + 1 + + name + punctuation.definition.braces.end.janet + + + patterns + + + include + #all + + + + brackets + + begin + (@?\[) + captures + + 1 + + name + punctuation.definition.brackets.begin.janet + + + end + (\]) + captures + + 1 + + name + punctuation.definition.brackets.end.janet + + + patterns + + + include + #all + + + + parens + + begin + (@?\() + captures + + 1 + + name + punctuation.definition.parens.begin.janet + + + end + (\)) + captures + + 1 + + name + punctuation.definition.parens.end.janet + + + patterns + + + include + #all + + + + readermac + + match + [\'\~\;\,] + name + punctuation.other.janet + + + literal + + match + (?<![\.:\w_\-=!@\$%^&?|\\/<>])(true|false|nil)(?![\.:\w_\-=!@\$%^&?|\\/<>]) + name + constant.language.janet + + corelib + + match + (?<![\.:\w_\-=!@\$%^&?|\\/<>])(def|do|fn|if|quasiquote|quote|splice|unquote|while|%|%=|&|&=|\*|\*=|\*doc\-width\*|\*env\*|\+|\+\+|\+=|\-|\-\-|\-=|\->|\->>|/|/=|<|<<|<<=|<=|=|==|>|>=|>>|>>=|>>>|>>>=|\^|\^=|_env|abstract\?|all|all\-symbols|and|apply|array|array/concat|array/ensure|array/insert|array/new|array/peek|array/pop|array/push|array/slice|array\?|asm|bnot|boolean\?|buffer|buffer/clear|buffer/new|buffer/popn|buffer/push\-byte|buffer/push\-integer|buffer/push\-string|buffer/slice|buffer\?|bytes\?|callable\?|case|cfunction\?|comment|comp|compile|complement|cond|coro|count|debug|debug/arg\-stack|debug/break|debug/fbreak|debug/lineage|debug/stack|debug/unbreak|debug/unfbreak|dec|deep\-not=|deep=|def\-|default|defglobal|defmacro|defmacro\-|defn|defn\-|describe|dictionary\?|disasm|distinct|doc|doc\*|doc\-format|drop\-until|drop\-while|each|empty\?|env\-lookup|error|eval|eval\-string|even\?|every\?|extreme|false\?|fiber/current|fiber/maxstack|fiber/new|fiber/setmaxstack|fiber/status|fiber\?|file/close|file/flush|file/open|file/popen|file/read|file/seek|file/write|filter|find|find\-index|first|flatten|flatten\-into|for|frequencies|function\?|gccollect|gcinterval|gcsetinterval|generate|gensym|get|getline|hash|idempotent\?|identity|if\-let|if\-not|import|import\*|inc|indexed\?|int|integer\?|interleave|interpose|invert|janet/build|janet/version|juxt|juxt\*|keep|keys|keyword\?|kvs|last|length|let|loop|macex|macex1|make\-env|map|mapcat|marshal|match|match\-1|math/acos|math/asin|math/atan|math/ceil|math/cos|math/e|math/exp|math/floor|math/inf|math/log|math/log10|math/pi|math/pow|math/random|math/seedrandom|math/sin|math/sqrt|math/tan|max|max\-order|merge|merge\-into|min|min\-order|module/find|module/native\-paths|module/paths|native|neg\?|next|nil\?|not|not=|not==|number\?|odd\?|one\?|or|order<|order<=|order>|order>=|os/clock|os/cwd|os/execute|os/exit|os/getenv|os/setenv|os/shell|os/sleep|os/time|os/which|pairs|parser/byte|parser/consume|parser/error|parser/flush|parser/new|parser/produce|parser/state|parser/status|parser/where|partial|pos\?|print|process/args|product|put|range|real|real\?|reduce|repl|require|resume|reverse|run\-context|scan\-integer|scan\-number|scan\-real|sentinel|seq|some|sort|sorted|status\-pp|stderr|stdin|stdout|string|string/ascii\-lower|string/ascii\-upper|string/bytes|string/check\-set|string/find|string/find\-all|string/from\-bytes|string/join|string/number|string/pretty|string/repeat|string/replace|string/replace\-all|string/reverse|string/slice|string/split|string\?|struct|struct\?|sum|symbol|symbol\?|table|table/getproto|table/new|table/rawget|table/setproto|table/to\-struct|table\?|take\-until|take\-while|true\?|tuple|tuple/append|tuple/prepend|tuple/slice|tuple\?|type|unless|unmarshal|update|values|varglobal|when|when\-let|with\-idemp|yield|zero\?|zipcoll|\||\|=)(?![\.:\w_\-=!@\$%^&?|\\/<>]) + name + keyword.control.janet + + keysym + + match + (?<![\.:\w_\-=!@\$%^&?|\\/<>]):[\.:\w_\-=!@\$%^&?|\\/<>]* + name + constant.keyword.janet + + symbol + + match + (?<![\.:\w_\-=!@\$%^&?|\\/<>])[\.a-zA-Z_\-=!@\$%^&?|\\/<>][\.:\w_\-=!@\$%^&?|\\/<>]* + name + variable.other.janet + + hex-number + + match + (?<![\.:\w_\-=!@\$%^&?|\\/<>])[-+]?0x([_\da-fA-F]+|[_\da-fA-F]+\.[_\da-fA-F]*|\.[_\da-fA-F]+)(&[+-]?[\da-fA-F]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>]) + name + constant.numeric.hex.janet + + dec-number + + match + (?<![\.:\w_\-=!@\$%^&?|\\/<>])[-+]?([_\d]+|[_\d]+\.[_\d]*|\.[_\d]+)([eE&][+-]?[\d]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>]) + name + constant.numeric.decimal.janet + + r-number + + match + (?<![\.:\w_\-=!@\$%^&?|\\/<>])[-+]?\d\d?r([_\w]+|[_\w]+\.[_\w]*|\.[_\w]+)(&[+-]?[\w]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>]) + name + constant.numeric.decimal.janet + + string + + begin + (@?") + beginCaptures + + 0 + + name + punctuation.definition.string.begin.janet + + + end + (") + endCaptures + + 0 + + name + punctuation.definition.string.end.janet + + + name + string.quoted.double.janet + patterns + + + match + (\\[ne0zft"\\']|\\x[0-9a-fA-F][0-9a-fA-f]) + name + constant.character.escape.janet + + + + longstring + + begin + @?(`+) + beginCaptures + + 0 + + name + punctuation.definition.string.begin.janet + + + end + \1 + endCaptures + + 0 + + name + punctuation.definition.string.end.janet + + + name + string.quoted.triple.janet + + nomatch + + match + \S+ + name + invalid.illegal.janet + + + scopeName + source.janet + uuid + 3743190f-20c4-44d0-8640-6611a983296b + + diff --git a/grammar/tmcorelib.janet b/grammar/tmcorelib.janet new file mode 100644 index 00000000..3255d602 --- /dev/null +++ b/grammar/tmcorelib.janet @@ -0,0 +1,30 @@ +# Helper to generate core library mappings for janet + +(def allsyms (all-symbols)) + +(def- escapes + {(get "|" 0) `\|` + (get "-" 0) `\-` + (get "+" 0) `\+` + (get "*" 0) `\*` + (get "^" 0) `\^` + (get "$" 0) `\$` + (get "?" 0) `\?` + 38 "&" + 60 "<" + 62 ">" + 34 """ + 39 "'" + 47 "/"}) + +(defn- escape + "Escape special characters for HTML encoding." + [str] + (def buf @"") + (loop [byte :in str] + (if-let [rep escapes.byte] + (buffer/push-string buf rep) + (buffer/push-byte buf byte))) + buf) + +(print (string/join (map escape allsyms)) "|"))