Skip to content

Instantly share code, notes, and snippets.

Avatar
🦑

Samuel Chase samebchase

🦑
View GitHub Profile
View realistic.clj
(ns my-amazing.module.core
(:require [another-library.json.module :as json]
[yet-another.http.library :as http]))
View ClojureNamespace.raku
grammar Namespace {
token TOP { <ns-form>
# <clojure-forms>
}
# token clojure-forms { }
token ns-form { <.ws>?
(<.comment-line> <ws>?)*
<.ws>?
View balanced-parens.raku
#!/usr/bin/env raku
use v6.d;
use Grammar::Tracer;
grammar BalancedParens {
token TOP { <balanced-paren> }
token balanced-paren { <lparen> <balanced-paren>* <rparen> }
View simple-ns.raku
#!/usr/bin/env raku
use v6.d;
use Grammar::Tracer;
grammar SimpleNs {
token TOP { <simple-ns> }
token simple-ns { <lparen> <ns-keyword> <.ws> <ns-name> <rparen> }
View trivial.raku
#!/usr/bin/env raku
use v6.d;
use Grammar::Tracer;
grammar EmptyLispForm {
token TOP { <lparen> <rparen> }
token lparen { '(' }
token rparen { ')' }
@samebchase
samebchase / realistic-ns-with-actions.raku
Created Nov 28, 2020
realistic-ns-with-actions.raku
View realistic-ns-with-actions.raku
#!/usr/bin/env raku
use v6.d;
#use Grammar::Tracer;
grammar RealisticNs {
token TOP { <realistic-ns> }
token realistic-ns { <lparen>
<ns-keyword> <.ws> <ns-name> <.ws>
@samebchase
samebchase / raku-grammars.md
Last active Nov 29, 2020
[WIP]: Raku Grammars
View raku-grammars.md

Parsing Clojure namespace forms using Raku grammars

One day, I started wondering if it would be possible to parse Clojure namespace forms and generate a dependency graph of the various namespaces used in a real-world Clojure project. While that was the original motivation, I ended up down the Raku grammar rabbit hole, and had an enjoyable time learning how to use them. I'm glad you're joining me in reliving that journey.

Background

@samebchase
samebchase / Usage.txt
Created Apr 2, 2020
Utility to convert milliseconds since the UNIX Epoch to a readable timestamp. Also, handles timezone offsets.
View Usage.txt
~
❯ timestamp-from-ms 1585725108000
2020-04-01T07:11:48Z
~
❯ timestamp-from-ms 1585725108000 +5:30
2020-04-01T12:41:48+05:30
~
❯ timestamp-from-ms 1585725108000 -5:30
2020-04-01T01:41:48-05:30
~
View length-of-shortest-list.cc
#include <vector>
#include <cassert>
#include <iostream>
#include <forward_list>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
View print_triangle.ml
(* http://www.problemotd.com/problem/party-hat/ *)
open Core.Std;;
open Sequence;;
let print_party_hat height =
let hat_width line_no =
2*line_no + 1 in
let print_char_n char n =
String.make n char