-
Notifications
You must be signed in to change notification settings - Fork 419
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
Conversation
This refactors the explanation of actions and predicates and makes a new section for describing the common execution environment.
This is a wonderful pull request. |
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:
|
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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]`. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
andend
are the same.
There was a problem hiding this comment.
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 :)
ok, I think I've resolved all outstanding comments. |
I've never used |
This refactors the explanation of actions and predicates, and makes a new section for describing the common execution environment.