Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions parseclj-lex.el
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ token is returned."
(right-char 7)
(parseclj-lex-token :character (buffer-substring-no-properties pos (point)) pos))

((equal (char-after (point)) ?u)
((string-match-p "^u[0-9a-fA-F]\\{4\\}" (parseclj-lex-lookahead 5))
(right-char 5)
(parseclj-lex-token :character (buffer-substring-no-properties pos (point)) pos))

((equal (char-after (point)) ?o)
((string-match-p "^o[0-8]\\{3\\}" (parseclj-lex-lookahead 4))
(right-char 4)
(parseclj-lex-token :character (buffer-substring-no-properties pos (point)) pos))

Expand Down
20 changes: 13 additions & 7 deletions parseclj-parser.el
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,21 @@ functions. Additionally the following options are recognized
(t (push token stack)))

;; Reduce based on top two items on the stack (special prefixed elements)
(let* ((top-value (parseclj--take-value stack value-p))
(opening-token (parseclj--take-token (nthcdr (length top-value) stack) value-p '(:discard :tag)))
(new-stack (nthcdr (+ (length top-value) (length opening-token)) stack)))
(when (and top-value opening-token)
(let (top-value
opening-token
new-stack)
(setq top-value (parseclj--take-value stack value-p))
(setq opening-token (parseclj--take-token (nthcdr (length top-value) stack) value-p '(:discard :tag)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to leave these in the let, that would also make it a bit easier to review. Right now it's hard to see what exactly changed here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I screwed up while reworking the code.

(while (and top-value opening-token)
;; (message "Reducing...")
;; (message " - STACK %S" stack)
;; (message " - OPENING_TOKEN %S" opening-token)
;; (message " - TOP_VALUE %S\n" top-value)
(setq stack (funcall reduce-branch new-stack (car opening-token) (append (cdr opening-token) top-value) options))))
;; (message " - OPENING-TOKEN %S" opening-token)
;; (message " - TOP-VALUE %S" top-value)
(setq new-stack (nthcdr (+ (length top-value) (length opening-token)) stack))
(setq stack (funcall reduce-branch new-stack (car opening-token) (append (cdr opening-token) top-value) options))

(setq top-value (parseclj--take-value stack value-p))
(setq opening-token (parseclj--take-token (nthcdr (length top-value) stack) value-p '(:discard :tag)))))

(setq token (parseclj-lex-next)))

Expand Down
14 changes: 6 additions & 8 deletions test/parseclj-lex-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\c" 30))))

(with-temp-buffer
(insert "\\newline\\return\\space\\tab\\a\\b\\c")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to add an extra test case instead of replacing this one? I think it'd be good if we still tested for these special cases like \newline and \return...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just that this test is repeated already: https://github.com/lambdaisland/parseclj/blob/master/test/parseclj-lex-test.el#L105, I separated this change into its own commit so it'd be easier to spot.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thanks!

(insert "\\u \\v \\w")
(goto-char 1)
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\newline" 1)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\return" 9)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\space" 16)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\tab" 22)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\a" 26)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\b" 28)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\c" 30))))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\u" 1)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :whitespace " " 3)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\v" 4)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :whitespace " " 6)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :character "\\w" 7))))

(with-temp-buffer
(insert "\\u0078\\o170")
Expand Down
28 changes: 26 additions & 2 deletions test/parseclj-test-data.el
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
(:value . 12)))))))))


"tag"
"tag-1"
(a-list
:source "#foo/bar [1]"
:ast '((:node-type . :root)
Expand All @@ -290,7 +290,7 @@
(:form . "1")
(:value . 1))))))))))))

"nested-tag"
"tag-2"
(a-list
:source "(fn #param :param-name 1)"
:ast '((:node-type . :root)
Expand All @@ -313,6 +313,30 @@
(:form . "1")
(:value . 1)))))))))

"nested-tags"
(a-list
:source "[#lazy-error #error {:cause \"Divide by zero\"}]"
:ast '((:node-type . :root)
(:position . 1)
(:children ((:node-type . :vector)
(:position . 1)
(:children ((:node-type . :tag)
(:position . 2)
(:tag . lazy-error)
(:children ((:node-type . :tag)
(:position . 14)
(:tag . error)
(:children ((:node-type . :map)
(:position . 21)
(:children ((:node-type . :keyword)
(:position . 22)
(:form . ":cause")
(:value . :cause))
((:node-type . :string)
(:position . 29)
(:form . "\"Divide by zero\"")
(:value . "Divide by zero")))))))))))))

"booleans"
(a-list
:source "[nil true false]"
Expand Down