Commit graph

34 commits

Author SHA1 Message Date
David Majda 25ab98027d Remove info about found string from syntax errors
The |found| property wasn't very useful as it mostly contained just one
character or |null| (the exception being syntax errors triggered by
|error| or |expected|). Similarly, the "but XXX found" part of the error
message (based on the |found| property) wasn't much useful and was
redundant in presence of location info.

For these reasons, this commit removes the |found| property and
corresponding part of the error message from syntax errors. It also
modifies error location info slightly to cover a range of 0 characters,
not 1 character (except when the error is triggered by |error| or
|expected|). This corresponds more precisely to the actual situation.

Fixes #372.
2015-09-18 10:01:15 -07:00
David Majda 6ff005786c Talk about "consuming input", not "advancing parser position"
It's shorter, less technical, and more understandible.
2015-09-04 17:23:42 +02:00
David Majda 60ebd9e695 Simplify JSHint directives 2015-09-04 16:52:38 +02:00
David Majda 969d39e8d9 Remove trailing commas in object literals
They broke IE 8-9.
2015-08-21 16:02:13 +02:00
David Majda 6f2c75f7d8 Label specs: Improve structure and descriptions 2015-07-17 14:16:46 +02:00
David Majda 8487c9a0ff Label specs: Add missing test case 2015-07-17 11:43:30 +02:00
David Majda f4385da177 Label specs: Unify formatting with other code 2015-07-17 11:36:35 +02:00
David Majda ddff5feea3 Label specs: Simplify and regularize block-scoped label specs
There is no need to test 3 labels from the outside scope, 1 is enough.
2015-07-17 11:28:15 +02:00
Arlo Breault 12c169e7b5 Convert PEG.js code to strict mode
* Issues #323
2015-06-12 17:34:59 -07:00
David Majda 065f4e1b75 Improve location info in syntax errors
Replace |line|, |column|, and |offset| properties of |SyntaxError| with
the |location| property. It contains an object similar to the one
returned by the |location| function available in action code:

  {
    start: { offset: 23, line: 5, column: 6 },
    end:   { offset: 25, line: 5, column: 8 }
  }

For syntax errors produced in the middle of the input, |start| refers to
the first unparsed character and |end| refers to the character behind it
(meaning the span is 1 character). This corresponds to the portion of
the input in the |found| property.

For syntax errors produced the end of the input, both |start| and |end|
refer to a character past the end of the input (meaning the span is 0
characters).

For syntax errors produced by calling |expected| or |error| functions in
action code the location info is the same as the |location| function
would return.
2015-04-04 10:04:04 +02:00
David Majda 4f7145e360 Improve location info available in action code
Replace |line|, |column|, and |offset| functions with the |location|
function. It returns an object like this:

  {
    start: { offset: 23, line: 5, column: 6 },
    end:   { offset: 25, line: 5, column: 8 }
  }

In actions, |start| refers to the position at the beginning of action's
expression and |end| refers to the position after the end of action's
expression. This allows one to easily add location info e.g. to AST
nodes created in actions.

In predicates, both |start| and |end| refer to the current position.

Fixes #246.
2015-04-03 16:26:34 +02:00
David Majda fb5f6c6ee9 Make labels behave like block-scoped variables
Action and predicate code can now see variables defined in expressions
"above" them.

Based on a pull request by Bryon Vandiver (@asterick):

  https://github.com/pegjs/pegjs/pull/180

Fixes #316.
2015-02-13 14:10:32 +01:00
David Majda 73795a65cc Behavior specs cleanup: Add group specs
While groups don't create separate nodes on the AST level, they exist
as concept on the user level, so they should be specified.
2015-01-26 09:54:29 +01:00
David Majda e306b58443 Behavior specs cleanup: Improve error reporting specs 2015-01-26 09:54:29 +01:00
David Majda e9d038547d Behavior specs cleanup: Improve semantic predicate specs
Note that use of |text| inside semantic predicate code is no longer
tested and officially supported.
2015-01-26 09:54:29 +01:00
David Majda 3d9600b81b Behavior specs cleanup: Improve action specs 2015-01-26 09:54:29 +01:00
David Majda b623396cb8 Behavior specs cleanup: Improve initializer specs
Note that use of |text|, |offset|, |line|, and |column| inside
initializer code is no longer tested and officially supported.
2015-01-26 09:54:29 +01:00
David Majda fee58d0806 Behavior specs cleanup: Improve rule specs 2015-01-26 09:54:29 +01:00
David Majda fa70e70ddf Behavior specs cleanup: Improve choice specs 2015-01-24 20:04:49 +01:00
David Majda b3828919e2 Behavior specs cleanup: Improve sequence specs 2015-01-24 20:02:06 +01:00
David Majda 548209b48b Behavior specs cleanup: Improve simple predicate specs 2015-01-24 19:57:49 +01:00
David Majda 52144e48cb Behavior specs cleanup: Improve label specs 2015-01-24 19:57:49 +01:00
David Majda c5c44b9d0c Behavior specs cleanup: Improve text specs 2015-01-24 19:57:49 +01:00
David Majda bb708490a0 Behavior specs cleanup: Improve one or more specs 2015-01-24 19:57:49 +01:00
David Majda b9a3b44cf2 Behavior specs cleanup: Improve zero or more specs 2015-01-24 19:57:49 +01:00
David Majda c377eff876 Behavior specs cleanup: Improve optional specs 2015-01-24 19:57:48 +01:00
David Majda ade2c249f2 Behavior specs cleanup: Improve rule reference specs 2015-01-24 19:57:48 +01:00
David Majda 936d6453a5 Behavior specs cleanup: Improve dot specs 2015-01-24 19:57:48 +01:00
David Majda 74be12c657 Behavior specs cleanup: Improve character class specs 2015-01-24 19:57:48 +01:00
David Majda 54191fbf12 Behavior specs cleanup: Improve literal specs 2015-01-24 19:57:48 +01:00
David Majda 2faff0000e Behavior specs cleanup: Make |toParse| work without expected value
This means we can assert just "this string parses" and ignore the
returned value.
2015-01-12 16:40:28 +01:00
David Majda ce91921a1d Behavior specs cleanup: Don't describe named rules separately
While naming a rule creates a separate node on the AST level, it's not a
new concept on the user level, so its specs should be a part of rule
specs.
2015-01-12 16:40:28 +01:00
David Majda a597e65a66 Behavior specs cleanup: Reorder toplevel |describe| blocks
Reorder toplevel |describe| blocks to more closely match ordering used
in the PEG.js grammar and elsewhere in PEG.js.
2015-01-12 16:40:28 +01:00
David Majda 3308807d22 Behavior specs cleanup: Move spec/api/generated-parser-behavior.spec.js
Move spec/api/generated-parser-behavior.spec.js to
spec/behavior/generated-parser-behavior.spec.js. It's not an API test,
strictly speaking.
2015-01-12 16:39:56 +01:00