Reputation: 3618
I have written a small hylang program that parses a log. However, when i try to evaluate it, i get the following error:
File "", line 8, column 38
(setv rule (.next irule))))))) ^ LexException: Ran into a RPAREN where it wasn't expected.
The function in question (also gives an error when evaluated separately) is the following:
(defmain [&rest args]
(setv inname (get args 1))
(setv outname (get args 2))
(with [ifile (open inname 'r')]
(with [ofile (open outname 'w')]
(setv tl (Tableline))
(setv irule (iter (.get-rule tl)))
(setv rule (.next irule))
(for [line ifile]
(setv match (re.match (get rule 0) line))
(when match
(for [(, group-num attr-data) (enumerate (get rule 1))]
(setattr tl (get attr-data 1) (apply (get attr-data 0)
[(.group match (inc group-num))])))
(if (. tl ready) (write ofile (str tl)))
(setv rule (.next irule)))))))
As far as i can tell, it is balanced expression, with all parens in their places. Why does the lexer fails?
The full text of my program is here: pastebin
Upvotes: 1
Views: 107
Reputation: 286
You need to use double quotes for making strings.
In lisps, the single quote is used for something completely different than making strings- "quoting" the next form. When lisp code is parsed, expressions like 'a
are transformed into (quote a)
. Similarly, '(hello)
becomes (quote (hello))
. Note that there is only one ' mark, as it always wraps the next expression. The quote form lets you "turn off" evaluation for a single expression. Look up lisp quotation- it's pretty useful, and is important for some of the more powerful features of the language.
Upvotes: 1