parsing html xml parsing expression grammar peg

By Xah Lee. Date: .

parsing expression grammar (peg)

xtodo

parsing html xml

xtodo
;; -*- coding: utf-8; lexical-binding: t; -*-

;; 2025-10-03
;; show a example of elisp code of peg-run with success-function

;; from grok ai.
;; does not work

(require 'peg)

(defun my-peg-success-function (result)
  "Function called when PEG parsing succeeds."
  (message "Parsing succeeded! Result: %s" result))

(defun parse-example-string (input)
  "Parse INPUT string using PEG with a success function."
  (peg-run
   (peg example-grammar
        ((number (and (substring (+ [0-9]))))
         (example-grammar number)))
   input
   #'my-peg-success-function))

;; Example usage
(parse-example-string "12345")

;; This code:

;; Defines a simple PEG grammar to match a number (one or more digits).
;; Uses peg-run to parse an input string.
;; Specifies my-peg-success-function as the success function, which will be called with the parsing result if successful.
;; When run with "12345", it will output a message with the parsed result.

;; The success function is invoked only when the parsing succeeds, receiving the parsed result as its argument.
xtodo

when done study pasing html reformat my site citation.

〔<cite>...</cite> <time>...</time> @ <a ...>...</a>〕
<cite>...</cite> <time>...</time> @ <a ...>...</a>