Skip to content

Instantly share code, notes, and snippets.

module ParserCombinators
State = Struct.new(:string, :offset) do
def peek(n)
string[offset ... offset + n]
end
def read(n)
State.new(string, offset + n)
end
# case (inl 0) of inl x ⇒ (iszero x) inr y ⇒ (if y then false else true)
# ----------------------------------------------------------------------
# Bool
------------------------- T-Ctx1 --------------------------- T-Ctx1
(x : Nat) ∈ (∅ , x : Nat) (y : Bool) ∈ (∅ , y : Bool)
----------- T-Zero ------------------------- T-Var --------------------------- T-Var ----------------------------- T-False ---------------------------- T-True
∅ ⊢ 0 : Nat (∅ , x : Nat) ⊢ x : Nat (∅ , y : Bool) ⊢ y : Bool (∅ , y : Bool) ⊢ false : Bool (∅ , y : Bool) ⊢ true : Bool
-------------------------- T-Inl --------------------------------- T-IsZero -------------------------------------------------------------------------------------------------------- T-If
(((λ x : Bool . (λ y : Bool . (x , y))) true) false) . 2
--------------------------------------------------------
----- S-x-23 -------- S-T-2 ----- S-Γ-0 ----- S-Γ-0 ----- S-x-23 -------- S-T-2 ----- S-Γ-0 ----- S-x-23 -------- S-T-2 ----- S-Γ-0 ----- S-x-23 -------- S-T-2 ----- S-Γ-0 ----- S-x-23 -------- S-T-2
x ← x Bool ← T ∅ ← Γ ∅ ← Γ x ← x Bool ← T ∅ ← Γ x ← x Bool ← T ∅ ← Γ x ← x Bool ← T ∅ ← Γ x ← x Bool ← T
------------------------------------- T-Ctx1 ----- S-x-23 -------- S-T-2 ------------------------------------- S-Γ-1
--------------------------- T-Ctx1
(x : Bool) ∈ (∅ , x : Bool)
---------------------------------------- T-Ctx2 ---------------------------------------- T-Ctx1
(x : Bool) ∈ ((∅ , x : Bool) , y : Bool) (y : Bool) ∈ ((∅ , x : Bool) , y : Bool)
---------------------------------------- T-Var ---------------------------------------- T-Var
((∅ , x : Bool) , y : Bool) ⊢ x : Bool ((∅ , x : Bool) , y : Bool) ⊢ y : Bool
----------------------------------------------------------------------------------------- T-Pair
((∅ , x : Bool) , y : Bool) ⊢ (x , y) : (Bool × Bool)
---------------------------------------------------------------- T-Abs
(∅ , x : Bool) ⊢ (λ y : Bool . (x , y)) : (Bool → (Bool × Bool))
def lit(expected, &action)
-> input {
if input[0 ... expected.size] == expected
node = [:lit, expected]
node = action.call(node) if action
[node, input[expected.size .. -1]]
end
}
end
#!/usr/bin/env ruby
require "set"
class Merger
def initialize(repo)
@repo = repo
end
def merge_base(a, b)

In the files below, a.c is the original version.

Version b.c swaps the order of the functions and makes no other changes.

Version c.c adds a comment to Chunk_copy.

This is what you get if you merge b.c and c.c using Git's default diff algorithm.

int Chunk_bounds_check(Chunk *chunk, size_t start, size_t n)
class Patience
Match = Struct.new(:a_line, :b_line, :text) do
attr_accessor :prev
end
def self.diff(a, b)
new(a, b).diff
end
def initialize(a, b)
const lit = (string) =>
input => {
if (input.indexOf(string) === 0)
return [['lit', string], input.substr(string.length)]
else
return null
}
const seq = (tokens) =>
input => {
[Unit]
Description=Trying to get systemd working
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/vagrant
EnvironmentFile=/vagrant/env
ExecStart=/usr/local/bin/bundle exec puma config.ru -p 9292