-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot pass custom InputPos
#6
Comments
Can you provide an illustrating code fragment? |
yes, I will add initialization of values from options of |
Looks like current implementation works only with keyword pos extendable via adding |
Sure, here is an example: (require '[strojure.parsesso.parser :as p]
'[strojure.parsesso.impl.pos :as pos])
(p/parse (p/get-state :pos) "" {:pos :text}) ; => {:tab 8, :line 1, :col 1}
(p/parse (p/get-state :pos) "" {:pos (pos/->TextPos 8 7 13)}) ; => nil So I wanted to tell the parser not to start at 1,1, but 7,13. As you can see, the position is reported as The Ideally, I would not need to construct the (p/parse (p/get-state :pos) "" {:pos :text, :line 7, :col 13}) ; => {:tab 8, :line 7, :col 13} Should be quite easy, as the Let me know if it would help if I wrote a PR! |
I currently work around it by providing a custom method: (defmethod pos/init-pos ::text
[{:keys [tab line col] :or {tab 8, line 1, col 1}} _]
(pos/TextPos. tab line col))
(p/parse (p/get-state :pos) "" {:pos ::text, :line 7, :col 13}) ; => {:tab 8, :line 7, :col 13} |
@ferdinand-beyer thank you for report 🙇 |
Thanks for improving this! Small nitpick for a rainy day: You forgot to update the {:arglists '([p input]
[p input {:keys [pos, tab, user-state] :as options}])} |
I've tried to create a custom
InputPos
and pass it via the:pos
option top/parse
. Unfortunately, the resulting positions are alwaysnil
.I've tracked it down to the
:default
method ofinit-pos
:The
when
should probably be anif
, to use the passedpos
if it is not a keyword.Side question: Is there a recommended way to construct a
TextPos
, sincestrojure.parsesso.impl.pos
is a private namespace? Alternatively, could we pass:line
and:col
options to initialize theTextPos
with values other than 1? This is useful in a multi-pass scenario, when we want to pass a known position to a sub-parser (e.g. parsing a XML attribute value, where we already know the attribute node's position).The text was updated successfully, but these errors were encountered: