|
52 | 52 | EdnTaggedValue
|
53 | 53 | EdnCommentLine
|
54 | 54 | EdnRegex
|
| 55 | + EdnVarQuote |
55 | 56 |
|
56 | 57 | CommentPlacement* = enum
|
57 | 58 | Before
|
|
105 | 106 | comment*: string
|
106 | 107 | of EdnRegex:
|
107 | 108 | regex*: string
|
| 109 | + of EdnVarQuote: |
| 110 | + var_symbol: EdnNode |
108 | 111 | line*: int
|
109 | 112 | column*: int
|
110 | 113 | comments*: seq[Comment]
|
|
118 | 121 | HMap* = ref HMapObj
|
119 | 122 |
|
120 | 123 | ParseError* = object of Exception
|
121 |
| - ParseInfo = tuple[line, col: int] |
| 124 | + ParseInfo* = tuple[line, col: int] |
122 | 125 |
|
123 | 126 | MacroReader = proc(p: var EdnParser): EdnNode
|
124 | 127 | MacroArray = array[char, MacroReader]
|
|
226 | 229 |
|
227 | 230 | ### === ERROR HANDLING UTILS ===
|
228 | 231 |
|
229 |
| -proc err_info(p: EdnParser): ParseInfo = |
| 232 | +proc err_info*(p: EdnParser): ParseInfo = |
230 | 233 | result = (p.line_number, get_col_number(p, p.bufpos))
|
231 | 234 |
|
232 | 235 | ### === MACRO READERS ===
|
@@ -934,6 +937,8 @@ proc hash*(node: EdnNode): Hash =
|
934 | 937 | h = h !& hash(node.comment)
|
935 | 938 | of EdnRegex:
|
936 | 939 | h = h !& hash(node.regex)
|
| 940 | + of EdnVarQuote: |
| 941 | + h = h !& hash(node.var_symbol) |
937 | 942 | result = !$h
|
938 | 943 |
|
939 | 944 | proc `==`*(this, that: EdnNode): bool =
|
@@ -976,7 +981,17 @@ proc `==`*(this, that: EdnNode): bool =
|
976 | 981 | return this.comment == that.comment
|
977 | 982 | of EdnRegex:
|
978 | 983 | return this.regex == that.regex
|
| 984 | + of EdnVarQuote: |
| 985 | + return this.var_symbol == that.var_symbol |
979 | 986 |
|
| 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 | + |
980 | 995 | proc read_regex(p: var EdnParser): EdnNode =
|
981 | 996 | let s = read_string(p)
|
982 | 997 | result = EdnNode(kind: EdnRegex, regex: s.str)
|
@@ -1029,6 +1044,7 @@ proc init_dispatch_macro_array() =
|
1029 | 1044 | dispatch_macros['('] = read_anonymous_fn
|
1030 | 1045 | dispatch_macros['?'] = read_reader_conditional
|
1031 | 1046 | dispatch_macros['"'] = read_regex
|
| 1047 | + dispatch_macros['\''] = read_var_quote |
1032 | 1048 |
|
1033 | 1049 | proc init_edn_readers() =
|
1034 | 1050 | init_macro_array()
|
|
0 commit comments