Skip to content

Instantly share code, notes, and snippets.

View pgoodman's full-sized avatar
🦥

Peter Goodman pgoodman

🦥
View GitHub Profile
;;;; Recursive Descent Parser Generator
;;;; Copyright 2008 Peter Goodman, all rights reserved
(defun concatenate* (type &rest lst)
"Concatenate all cars within a tree."
(setf lst (remove nil lst))
(if (null lst)
"" ; nothing to concatenate, return
(let ((a (car lst)) (d (cdr lst)))
(defun-parser :html-attr
(no-capture (repeat 0 nil " "))
(and (concat (repeat 0 nil (range #\a #\z))
(and ":" (repeat 0 nil (concat (range #\a #\z)))))
(no-capture #\= #\")
(find-next #\")
(no-capture #\")))
(defun-parser :html-attrs
(repeat 0 nil :html-attr))
(print (parse ':html "prefix text<div class=\"post\"><a name=\"comment-{$comment.comment_ID}\" id=\"comment-{$comment.comment_ID}\"></a>{$comment.content}<ul class=\"categories\">by <cond:if var=\"comment.comment_author_url\" neq=\"\"><a href=\"{$comment.comment_author_url}\" title=\"{$comment.comment_author}\">{$comment.comment_author}</a><cond:else />{$comment.comment_author}</cond:if> on {$comment.date} </ul></div>postfix text"))
;; what's generated:
("prefix text" (:HTML-TAG "" (:HTML-TAG-NAME "div") (:HTML-ATTRS (:HTML-ATTR "class" "post")) "") "" (:HTML-TAG "" (:HTML-TAG-NAME "a") (:HTML-ATTRS (:HTML-ATTR "name" "comment-{$comment.comment_ID}") (:HTML-ATTR "id" "comment-{$comment.comment_ID}")) "") "" (:HTML-TAG "/" (:HTML-TAG-NAME "a") (:HTML-ATTRS) "") "{$comment.content}" (:HTML-TAG "" (:HTML-TAG-NAME "ul") (:HTML-ATTRS (:HTML-ATTR "class" "categories")) "") "by " (:HTML-TAG "" (:HTML-TAG-NAME "cond:if") (:HTML-ATTRS (:HTML-ATTR "var" "comment.comment_author_url") (:HTML-ATTR "neq" "")) "") ""
(defun-parser :html-attr
(no-capture (repeat 0 nil " "))
(and (concat (repeat 0 nil (range #\a #\z))
(and ":" (repeat 0 nil (concat (range #\a #\z)))))
(no-capture #\= #\")
(find-next #\")
(no-capture #\")))
(defun-parser :html-attrs
(repeat 0 nil :html-attr))
("prefix text"
(:HTML-TAG
""
(:HTML-TAG-NAME "div")
(:HTML-ATTRS
(:HTML-ATTR "class" "post"))
"")
""
(:HTML-TAG
""
(print (parse ':html "prefix text<div class=\"post\"><a name=\"comment-{$comment.comment_ID}\" id=\"comment-{$comment.comment_ID}\"></a>{$comment.content}<ul class=\"categories\">by <cond:if var=\"comment.comment_author_url\" neq=\"\"><a href=\"{$comment.comment_author_url}\" title=\"{$comment.comment_author}\">{$comment.comment_author}</a><cond:else />{$comment.comment_author}</cond:if> on {$comment.date} </ul></div>postfix text"))
package minesweeper;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
/**
* The Mine Sweeper program.
*
* @author Peter Goodman
package minesweeper;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.util.Random;
import java.util.Stack;
import javax.swing.*;
package minesweeper;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
import minesweeper.functional.*;
/**
package minesweeper;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import minesweeper.functional.*;
import minesweeper.gui.*;
import minesweeper.components.*;
import static minesweeper.functional.ArrayUtils.map;