Skip to content

Commit 8100cd9

Browse files
committed
reading var quotes
1 parent 72e24c4 commit 8100cd9

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

edn.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.1.0"
3+
version = "0.1.1"
44
author = "Roland Sadowski"
55
description = "EDN and Clojure parser"
66
license = "EPL-2.0"

src/edn.nim

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type
5252
EdnTaggedValue
5353
EdnCommentLine
5454
EdnRegex
55+
EdnVarQuote
5556

5657
CommentPlacement* = enum
5758
Before
@@ -105,6 +106,8 @@ type
105106
comment*: string
106107
of EdnRegex:
107108
regex*: string
109+
of EdnVarQuote:
110+
var_symbol: EdnNode
108111
line*: int
109112
column*: int
110113
comments*: seq[Comment]
@@ -118,7 +121,7 @@ type
118121
HMap* = ref HMapObj
119122

120123
ParseError* = object of Exception
121-
ParseInfo = tuple[line, col: int]
124+
ParseInfo* = tuple[line, col: int]
122125

123126
MacroReader = proc(p: var EdnParser): EdnNode
124127
MacroArray = array[char, MacroReader]
@@ -226,7 +229,7 @@ let
226229

227230
### === ERROR HANDLING UTILS ===
228231

229-
proc err_info(p: EdnParser): ParseInfo =
232+
proc err_info*(p: EdnParser): ParseInfo =
230233
result = (p.line_number, get_col_number(p, p.bufpos))
231234

232235
### === MACRO READERS ===
@@ -934,6 +937,8 @@ proc hash*(node: EdnNode): Hash =
934937
h = h !& hash(node.comment)
935938
of EdnRegex:
936939
h = h !& hash(node.regex)
940+
of EdnVarQuote:
941+
h = h !& hash(node.var_symbol)
937942
result = !$h
938943

939944
proc `==`*(this, that: EdnNode): bool =
@@ -976,7 +981,17 @@ proc `==`*(this, that: EdnNode): bool =
976981
return this.comment == that.comment
977982
of EdnRegex:
978983
return this.regex == that.regex
984+
of EdnVarQuote:
985+
return this.var_symbol == that.var_symbol
979986

987+
proc read_var_quote(p: var EdnParser): EdnNode =
988+
let node = read(p)
989+
case node.kind
990+
of EdnSymbol:
991+
result = EdnNode(kind: EdnVarQuote, var_symbol: node)
992+
else:
993+
raise new_exception(ParseError, "Attempted to read a var qote, but got" & $node.kind)
994+
980995
proc read_regex(p: var EdnParser): EdnNode =
981996
let s = read_string(p)
982997
result = EdnNode(kind: EdnRegex, regex: s.str)
@@ -1029,6 +1044,7 @@ proc init_dispatch_macro_array() =
10291044
dispatch_macros['('] = read_anonymous_fn
10301045
dispatch_macros['?'] = read_reader_conditional
10311046
dispatch_macros['"'] = read_regex
1047+
dispatch_macros['\''] = read_var_quote
10321048

10331049
proc init_edn_readers() =
10341050
init_macro_array()

tests/test.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ test "everything":
350350
node = read("#\".*\"")
351351
check node.kind == EdnRegex
352352

353-
#check add(5, 5) == 10
353+
node = read("#'some-ns/symbol")
354+
check node.kind == EdnVarQuote
354355

355356

0 commit comments

Comments
 (0)