emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/parseclj 3a92eafce9 079/185: Rename reduce-node to reduce-


From: ELPA Syncer
Subject: [nongnu] elpa/parseclj 3a92eafce9 079/185: Rename reduce-node to reduce-branch
Date: Tue, 28 Dec 2021 14:05:20 -0500 (EST)

branch: elpa/parseclj
commit 3a92eafce95e6fd52ffa11e344a2e593f4e230a2
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>

    Rename reduce-node to reduce-branch
    
    To differentiate "leaf nodes" from "branch nodes".
---
 DESIGN.md   | 14 +++++++-------
 clj-ast.el  |  4 ++--
 clj-edn.el  |  4 ++--
 parseclj.el |  8 ++++----
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/DESIGN.md b/DESIGN.md
index b90ae0e577..3a31a5e242 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -121,23 +121,23 @@ Tokens can be recognized by the `:token-type` key, which 
must always come first
 
 ## Shift-reduce parser
 
-The parser is again a single function `parseclj-parse`. It is a higher order 
function, with much of the final result determined by the `reduce-leaf` and 
`reduce-node` functions passed in as arguments.
+The parser is again a single function `parseclj-parse`. It is a higher order 
function, with much of the final result determined by the `reduce-leaf` and 
`reduce-branch` functions passed in as arguments.
 
 `parseclj-parse` internally operates by using a stack. This stack contains 
tokens (as returned by `clj-lex-next`), and reduced values.
 
 `reduce-leaf` is a two-argument function. It takes the current value of the 
stack, and a token, and returns an updated stack, typically by parsing the 
token to a value and pushing that value onto the stack.
 
-`reduce-node` is a three-argument function. It takes the current value of the 
stack, a node type, and a list of children, and returns an updated stack.
+`reduce-branch` is a three-argument function. It takes the current value of 
the stack, a node type, and a list of children, and returns an updated stack.
 
 The parser reads consecutive input tokens. If the token represents a leaf node 
(like a number, symbol, string), then it calls `reduce-leaf`, giving it a 
chance to add a value to the stack. If the token is a non-leaf node (a 
delimiter) it gets put on the stack as-is. This part is known as the "shift" 
phase.
 
 After "shifting" a value on to the stack, the parser tries to "reduce", by 
inspecting the top one, two, or three items on the stack.
 
-If the top item is a closing delimiter token, then the parser scans down the 
stack until it finds a matching opening delimiter. It pops both delimiters and 
everything in between them off the stack, and passes them to `reduce-node`, 
which can "reduce" this sequence to a single value (say, a list), and push that 
item onto the stack.
+If the top item is a closing delimiter token, then the parser scans down the 
stack until it finds a matching opening delimiter. It pops both delimiters and 
everything in between them off the stack, and passes them to `reduce-branch`, 
which can "reduce" this sequence to a single value (say, a list), and push that 
item onto the stack.
 
 The type of values pushed onto the stack depends on the reducing functions 
used. The parser only distinguishes between tokens and non-tokens. It follows 
that a reducing functions should not push raw tokens back onto the stack.
 
-When parsing finishes the stack will contain all parsed forms in reverse 
order. It will call `reduce-node` once more with a node type of `:root`, to 
give it a chance to finalize.
+When parsing finishes the stack will contain all parsed forms in reverse 
order. It will call `reduce-branch` once more with a node type of `:root`, to 
give it a chance to finalize.
 
 ### Example
 
@@ -157,7 +157,7 @@ An example, when parsing the following EDN, with parsing 
done up to the position
  ((:token-type . :lparen) (:form . "(") (:pos . 1)))
 ```
 
-Now the parser encounters the first closing parenthesis. It pops `3` and 
`:lparen` off the stack, and passes `(((:token-type . :lparen) 3 ((:token-type 
. :rparen)))` to `reduce-node`, which reduces this a single list, and pushes it 
onto the stack.
+Now the parser encounters the first closing parenthesis. It pops `3` and 
`:lparen` off the stack, and passes `(((:token-type . :lparen) 3 ((:token-type 
. :rparen)))` to `reduce-branch`, which reduces this a single list, and pushes 
it onto the stack.
 
 ``` clojure
 ;; input
@@ -172,7 +172,7 @@ Now the parser encounters the first closing parenthesis. It 
pops `3` and `:lpare
  ((:token-type . :lparen) (:form . "(") (:pos . 1)))
 ```
 
-Now the parser encounters the second closing parenthesis. It pops everything 
until `:lparen` off the stack, and passes it to `reduce-node`, which turns the 
result into a list and pushes it onto the stack.
+Now the parser encounters the second closing parenthesis. It pops everything 
until `:lparen` off the stack, and passes it to `reduce-branch`, which turns 
the result into a list and pushes it onto the stack.
 
 ``` clojure
 ;; input
@@ -212,7 +212,7 @@ Unmatched closing delimiter:
 ((1 2 3) ((:token-type . :lparen)))
 ```
 
-In many cases it will be desirable to "fail fast", and raise an error as soon 
as a syntax error is encountered. A `reduce-node` function can do so if it 
wishes by checking its input sequence for raw tokens, and raising an error if 
any are present.
+In many cases it will be desirable to "fail fast", and raise an error as soon 
as a syntax error is encountered. A `reduce-branch` function can do so if it 
wishes by checking its input sequence for raw tokens, and raising an error if 
any are present.
 
 ## EDN vs Clojure
 
diff --git a/clj-ast.el b/clj-ast.el
index 7b56d3ec99..96e90d5bb0 100644
--- a/clj-ast.el
+++ b/clj-ast.el
@@ -42,7 +42,7 @@
                            ':value (parseclj--leaf-token-value token))
      stack)))
 
-(defun clj-ast--reduce-node (stack opener-token children)
+(defun clj-ast--reduce-branch (stack opener-token children)
   (let* ((pos (a-get opener-token 'pos))
          (type (clj-lex-token-type opener-token))
          (type (cl-case type
@@ -66,7 +66,7 @@
 
 Parses code in the current buffer, starting from the current
 position of (point)."
-  (parseclj-parse #'clj-ast--reduce-leaf #'clj-ast--reduce-node))
+  (parseclj-parse #'clj-ast--reduce-leaf #'clj-ast--reduce-branch))
 
 (defun clj-ast-parse-str (s)
   "Parse Clojure code in string S to AST."
diff --git a/clj-edn.el b/clj-edn.el
index 49a8730a09..a1de242a41 100644
--- a/clj-edn.el
+++ b/clj-edn.el
@@ -46,7 +46,7 @@ handlers as an optional argument to the reader functions.")
       stack
     (cons (parseclj--leaf-token-value token) stack)))
 
-(defun clj-edn-reduce-node (tag-readers)
+(defun clj-edn-reduce-branch (tag-readers)
   (lambda (stack opener-token children)
     (let ((token-type (clj-lex-token-type opener-token)))
       (if (member token-type '(:root :discard))
@@ -71,7 +71,7 @@ handlers as an optional argument to the reader functions.")
 
 (defun clj-edn-read (&optional tag-readers)
   (parseclj-parse #'clj-edn-reduce-leaf
-                    (clj-edn-reduce-node (a-merge clj-edn-default-tag-readers 
tag-readers))))
+                    (clj-edn-reduce-branch (a-merge 
clj-edn-default-tag-readers tag-readers))))
 
 (defun clj-edn-read-str (s &optional tag-readers)
   (with-temp-buffer
diff --git a/parseclj.el b/parseclj.el
index 3b42ab20f8..fe3dcb0b5a 100644
--- a/parseclj.el
+++ b/parseclj.el
@@ -137,7 +137,7 @@
         (message "STACK: %S , CLOSER: %S" stack closer-token)
         (error "Syntax Error")))))
 
-(defun parseclj-parse (reduce-leaf reduce-node)
+(defun parseclj-parse (reduce-leaf reduce-branch)
   (let ((stack nil))
 
     (while (not (eq (clj-lex-token-type (setq token (clj-lex-next))) :eof))
@@ -148,17 +148,17 @@
       (let ((token-type (clj-lex-token-type token)))
         (cond
          ((member token-type parseclj--leaf-tokens) (setf stack (funcall 
reduce-leaf stack token)))
-         ((member token-type parseclj--closer-tokens) (setf stack 
(parseclj--reduce-coll stack token reduce-node)))
+         ((member token-type parseclj--closer-tokens) (setf stack 
(parseclj--reduce-coll stack token reduce-branch)))
          (t (push token stack))))
 
       ;; Reduce based on top two items on the stack (special prefixed elements)
       (seq-let [top lookup] stack
         (when (and (parseclj--is-open-prefix? lookup)
                    (not (clj-lex-token? top))) ;; top is fully reduced
-            (setf stack (funcall reduce-node (cddr stack) lookup (list 
top))))))
+            (setf stack (funcall reduce-branch (cddr stack) lookup (list 
top))))))
 
     ;; reduce root
-    (setf stack (funcall reduce-node stack '((type . :root) (pos . 1)) stack))
+    (setf stack (funcall reduce-branch stack '((type . :root) (pos . 1)) 
stack))
     ;; (message "RESULT: %S" stack)
     stack))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]