Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active December 17, 2021 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sogaiu/d7ac333b751ed964511bc22f75942293 to your computer and use it in GitHub Desktop.
Save sogaiu/d7ac333b751ed964511bc22f75942293 to your computer and use it in GitHub Desktop.
sample meg/match debug output for margaret
;; would like to improve the ability to visualize the following output
;; straight-forward table seems like it wouldn't encode indentation very well
;; seeing all of the output suddenly at once doesn't seem good? might be nice
;; to be able to iteratively show one additional frame at a time (and then
;; might as well be able to "back up" by one frame?)
(import ../margaret/meg :as peg)
(comment
(setdyn :meg-debug true)
(setdyn :meg-debug nil)
(setdyn :meg-debug {:captures true
:peg true
:text true})
(peg/match ~(capture "a")
"abc")
# => @["a"]
# capture >
# captures: @[]
# peg: (capture "a")
# text: "abc"
# RULE_LITERAL >
# captures: @[]
# peg: "a"
# text: "abc"
# RULE_LITERAL <
# captures: @[]
# peg: "a"
# text: "abc"
# ret: 1
# capture <
# captures: @["a"]
# peg: (capture "a")
# text: "abc"
# ret: 1
# --------
# tags: @[nil]
# captures: @["a"]
# index: 1
# --------
# @["a"]
(peg/match ~(capture "ab")
"abc")
# => @["ab"]
# capture >
# captures: @[]
# peg: (capture "ab")
# text: "abc"
# RULE_LITERAL >
# captures: @[]
# peg: "ab"
# text: "abc"
# RULE_LITERAL <
# captures: @[]
# peg: "ab"
# text: "abc"
# ret: 2
# capture <
# captures: @["ab"]
# peg: (capture "ab")
# text: "abc"
# ret: 2
# --------
# tags: @[nil]
# captures: @["ab"]
# index: 2
# --------
# @["ab"]
(peg/match ~(sequence (capture "a")
(capture "b"))
"abc")
# => @["a" "b"]
# sequence >
# captures: @[]
# peg: (sequence (capture "a") (capture "b"))
# text: "abc"
# capture >
# captures: @[]
# peg: (capture "a")
# text: "abc"
# RULE_LITERAL >
# captures: @[]
# peg: "a"
# text: "abc"
# RULE_LITERAL <
# captures: @[]
# peg: "a"
# text: "abc"
# ret: 1
# capture <
# captures: @["a"]
# peg: (capture "a")
# text: "abc"
# ret: 1
# capture >
# captures: @["a"]
# peg: (capture "b")
# text: "bc"
# RULE_LITERAL >
# captures: @["a"]
# peg: "b"
# text: "bc"
# RULE_LITERAL <
# captures: @["a"]
# peg: "b"
# text: "bc"
# ret: 1
# capture <
# captures: @["a" "b"]
# peg: (capture "b")
# text: "bc"
# ret: 1
# sequence <
# captures: @["a" "b"]
# peg: (sequence (capture "a") (capture "b"))
# text: "abc"
# ret: 2
# --------
# tags: @[nil nil]
# captures: @["a" "b"]
# index: 2
# --------
# @["a" "b"]
(setdyn :meg-debug {:captures true
:peg true
:tags true
:tagged_captures true
:text true})
(peg/match ~(capture "a" :x)
"abc")
# => @["a"]
# capture >
# captures: @[]
# tags: @[]
# tagged_captures: @[]
# peg: (capture "a" :x)
# text: "abc"
# RULE_LITERAL >
# captures: @[]
# tags: @[]
# tagged_captures: @[]
# peg: "a"
# text: "abc"
# RULE_LITERAL <
# captures: @[]
# tags: @[]
# tagged_captures: @[]
# peg: "a"
# text: "abc"
# ret: 1
# capture <
# captures: @["a"]
# tags: @[:x]
# tagged_captures: @["a"]
# peg: (capture "a" :x)
# text: "abc"
# ret: 1
# --------
# tags: @[:x]
# captures: @["a"]
# index: 1
# --------
# @["a"]
(peg/match ~(sequence (capture "a" :x)
(capture "b" :y))
"abc")
# => @["a" "b"]
# sequence >
# captures: @[]
# tags: @[]
# tagged_captures: @[]
# peg: (sequence (capture "a" :x) (capture "b" :y))
# text: "abc"
# capture >
# captures: @[]
# tags: @[]
# tagged_captures: @[]
# peg: (capture "a" :x)
# text: "abc"
# RULE_LITERAL >
# captures: @[]
# tags: @[]
# tagged_captures: @[]
# peg: "a"
# text: "abc"
# RULE_LITERAL <
# captures: @[]
# tags: @[]
# tagged_captures: @[]
# peg: "a"
# text: "abc"
# ret: 1
# capture <
# captures: @["a"]
# tags: @[:x]
# tagged_captures: @["a"]
# peg: (capture "a" :x)
# text: "abc"
# ret: 1
# capture >
# captures: @["a"]
# tags: @[:x]
# tagged_captures: @["a"]
# peg: (capture "b" :y)
# text: "bc"
# RULE_LITERAL >
# captures: @["a"]
# tags: @[:x]
# tagged_captures: @["a"]
# peg: "b"
# text: "bc"
# RULE_LITERAL <
# captures: @["a"]
# tags: @[:x]
# tagged_captures: @["a"]
# peg: "b"
# text: "bc"
# ret: 1
# capture <
# captures: @["a" "b"]
# tags: @[:x :y]
# tagged_captures: @["a" "b"]
# peg: (capture "b" :y)
# text: "bc"
# ret: 1
# sequence <
# captures: @["a" "b"]
# tags: @[:x :y]
# tagged_captures: @["a" "b"]
# peg: (sequence (capture "a" :x) (capture "b" :y))
# text: "abc"
# ret: 2
# --------
# tags: @[:x :y]
# captures: @["a" "b"]
# index: 2
# --------
# @["a" "b"]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment