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

Clarify execution environment of actions. #531

Merged
merged 4 commits into from
Sep 14, 2017
Merged

Conversation

felix9
Copy link
Contributor

@felix9 felix9 commented Sep 12, 2017

This refactors the explanation of actions and predicates, and makes a new section for describing the common execution environment.

This refactors the explanation of actions and predicates
and makes a new section for describing the common execution
environment.
@jtenner
Copy link

jtenner commented Sep 12, 2017

This is a wonderful pull request.

@futagoza
Copy link
Member

This is a great idea, never thought of it because I'm used to most of the helpers.

Just a few things before I merge:

  1. Add Action Execution Environment as a sub-link of Grammar Syntax and Semantics in the TOC
  2. Format the content in the location() section, it seems slightly off going to the left

README.md Outdated
offset, there's also a function `offset` that returns just the start offset,
and a function `range` that returns the array `[start, end]` offsets.
The predicate should `return` a boolean value. If the result is
truthy, the match result is `undefined`, otherwise the match is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now match result is result of return-ed expression. And I think that this must stay true and #66 must be closed unresolved.

Copy link
Member

@futagoza futagoza Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mingun I just confirmed on pegjs.org/online (PEG.js 0.10) and on runkit.com/futagoza/59b9917124ab7b001102b0f2 (pegjs-dev and Node.js v6) that the behaviour is exactly like it is described, error on failed match and undefined on pass.

I didn't start using predicate's until PEG.js 0.10, and I've never seen a predicate return the result of it's action.

README.md Outdated
expression as its arguments. The action should return some JavaScript value
using the `return` statement. This value is considered match result of the
preceding expression.
The action shuuld be JavaScript code, and it's executed as a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misprint: shuuld

README.md Outdated

The code inside the action can also access location information using the
`location` function. It returns an object like this:
* Labels in the preceding expression are available as local
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to specify that from subexpressions labels of parental expressions are available and maybe add an example:

rule = _1:'a' (_2:'c') _3:(_4:'b' { return [_1, _4]; });// _1 also visible, but _2 and _3 not

README.md Outdated
expression.

* `range()` returns an array containing the start and end offsets
of the preceding expression, such as `[23, 25]`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what for predicates can be noted that the start and end a the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a translation error, I'm guessing you said:

I think that for predicates it can be noted that the start and end are the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you right. Thank you for helping me :)

@felix9
Copy link
Contributor Author

felix9 commented Sep 14, 2017

ok, I think I've resolved all outstanding comments.

@futagoza
Copy link
Member

I've never used text() inside predicates so I never actually realised it did that, so much for 5 years of experience with PEG.js 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants