Skip to content
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

Scoping of (non-static) options #505

Open
xml-project opened this issue Aug 14, 2018 · 6 comments

Comments

@xml-project
Copy link
Contributor

commented Aug 14, 2018

In XProc 1.0 the following pipeline has a static error, because $option is not visible in the XPath-expression:

<p:declare-step version="1.0" 
  xmlns:p="http://www.w3.org/ns/xproc"
  xmlns:mox="http://www.xml-project.com/morganaxproc">
  <p:output port="result" />
	<p:option name="option" select="'name'" />	
	<p:declare-step type="mox:test" >
		<p:output port="result" />
		<p:option name="inner" select="$option" />
		<p:add-attribute match="/*">
			<p:input port="source">
				<p:inline><doc /></p:inline>
			</p:input>
			<p:with-option name="attribute-name" select="$inner" />
                        <!-- HERE IS THE PROBLEM -->
			<p:with-option name="attribute-value" select="$option" />
		</p:add-attribute>
	</p:declare-step>
	<mox:test />
</p:declare-step>		

Now in the XProc 3.0 specs, we say:

The environment of a step also includes the in-scope bindings for all of the variables and options “visible” from its lexical position.

I can't find any explanation of "visible" except the "shadowing" rule. But as $option in the marked position is not shadowed, one could assume it to be visible.
What did I miss?
Should we be a little bit more explicit about visibility (or scoping) of options and variables?

@gimsieke

This comment has been minimized.

Copy link
Contributor

commented Jul 2, 2019

I, too, understand lexical scoping in such a way that embedded step declarations see options and static variables that are declared in the surrounding step declaration.

In #826 (comment), @ndw asserts the following:

[…] Pipelines are self-contained. If I pick one up and drop it into a larger pipeline, it shouldn't suddenly break because of the static variables in the surrounding pipeline.

and in #826 (comment), he argues

I don't think we should make nested pipelines different from imported pipelines […]

So if we treat nested pipelines as if they are imported, we need to define “lexical scoping in XProc documents“ more precisely, because IMHO this contradicts everyone’s conception of lexical scope when they simply look at the XML document and its element nesting & order.

@gimsieke gimsieke reopened this Jul 2, 2019

@xml-project

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

Sorry, could you give us (at least me) a hint, why you reopened this issue.
As far as I understood our consensus "lexical scoping" means "lexical scoping inside the (embedded) step".
This seems to be inline with the cited comments. Do you see this principle at risk?

@gimsieke

This comment has been minimized.

Copy link
Contributor

commented Jul 4, 2019

It isn’t reflected anywhere in the spec. At least I didn’t see it. Maybe you can point me to the section in the spec where we explain what lexical scope means for XProc documents. If not, we need to say something about it. This is why I reopened the issue.

@xml-project

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

Ah, ok. Thanks.
Last time we thought it was clear enough from the concept of a step, but I agree that to say a bit more about it can't be wrong.

@gimsieke

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

@xml-project pointed out to me that there is this in § 16.5.1:

The in-scope bindings at the beginning of a p:declare-step are limited to the lexically preceding, statically declared options and variables.

I think it doesn’t do harm if we add notes in § 11 (Variables and Options), § 16.4 (Variables and Options) and/or § 7.2.1 (Environment, in-scope bindings) that point to this restriction wrt lexical scope.

@ndw

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2019

I believe we have consensus that p:declare-stepstarts a new context and non-static variables declared in an outer scope are not visible in the declare step.

The open assertion in this issue, as I understand it, is that the spec isn't clear on this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.