Miscellaneous utility functions.

(ns mini-java.util
  (:require [clojure.set :as set]))

Given an ANTLR parser, returns the name of the file it is parsing.

(defn parser-filename
  [parser]
  (-> parser
      .getInputStream
      .getSourceName))

Returns the line and column of the given token in the form [line column].

(defn token-line-and-column
  [token]
  (let [line   (.getLine token)
        column (.getCharPositionInLine token)]
    [line column]))

Converts CamelCase to lisp-case.

(defn camel->lisp
  [s]
  (-> s
      (clojure.string/replace #"([a-z])([A-Z])" "$1-$2")
      clojure.string/lower-case))

Given two sets, returns all of the elements which are only contained in a single set.

This is done by the set operation: (s1 - s2) ∪ (s2 - s1).

(defn symmetric-set-difference
  [s1 s2]
  (set/union (set/difference s1 s2)
             (set/difference s2 s1)))