Skip to content

Instantly share code, notes, and snippets.

View dannymcgee's full-sized avatar

Danny McGee dannymcgee

View GitHub Profile
@dannymcgee
dannymcgee / vscode-grammar-tips.md
Last active February 19, 2024 04:08
VS Code Grammar Tips

Hey, would you mind giving me tips/information on improving the syntax highlighting for my programming language? Ive been working on the language pretty seriously for months but the vscode highlighting isnt that good still.

Sure! It's kind of a lot for a Reddit comment, but here are some resources that should get the ball rolling:

  • VS Code Grammar Bootstrap

    This is a template repo (not an actual GitHub template, so you have to do a manual find-and-replace after cloning/forking) with tooling to generate the *.tmLanguage.json files from TypeScript objects. This is a huge help because you can use regex literals to define the patterns (better syntax highlighting, and no more double-escaping everything!), split the grammar into multiple files, write helper functions to remove some boilerplate, etc. There's also a regex function there that you can invoke like a tagged template to combine multiple regular expressions, like:

@dannymcgee
dannymcgee / lib.rs
Last active November 3, 2021 06:46
Evaluate Reverse Polish Notation (leetcode #150)
pub fn eval_rpn(tokens: &[&str]) -> i32 {
tokens
.iter()
.fold(vec![], |mut stack, token| match *token {
op @ ("+" | "-" | "*" | "/") => {
let rhs = stack.pop().unwrap();
let lhs = stack.pop().unwrap();
stack.push(match op {
"+" => lhs + rhs,
@dannymcgee
dannymcgee / summer-vacation.css
Created September 3, 2020 03:15
GitHub Summer Vacation theme
.pl-k, .pl-c {
font-style: italic;
}
.tab-size {
tab-size: 4;
}
code, pre, tt, .blob-code-inner {
font-family: 'Operator Mono SSm Lig';
@dannymcgee
dannymcgee / extra-github-highlighting.tampermonkey.js
Last active September 3, 2020 03:29
Extra GitHub syntax highlighting
// ==UserScript==
// @name Extra GitHub syntax highlighting
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Add extra classes to TypeScript/JavaScript tokens for more granular syntax highlighting. Combine with something like StyleBot for fun and profit.
// @author https://github.com/dannymcgee
// @include /^https?:\/\/(.*)?\.github\.com\/?.*$/
// @require https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)
// @grant none
// ==/UserScript==