1002 Commits (7ca229a43247636de73e35248ca8597a1e70b04f)
 

Author SHA1 Message Date
David Majda 2fd77b96fc Revert "Use literal raw text in error messages"
I no longer think that using raw literal texts in error messages is the
right thing to do. The main reason is that it couples error messages
with details of the grammar such as use of single or double quotes in
literals. A better solution is coming in the next commit.

This reverts commit 69a0f769fc.
9 years ago
David Majda c50ad15461 Use http-server to serve specs and benchmarks to the browser
Previously, the instructions recommended using Python's SimpleHTTPServer
module, which created unnecessary dependency on Python.
9 years ago
David Majda 138405d89d Add syntax highlighting to code blocks in README.md files 9 years ago
David Majda 45de51a881 Consistently talk about generating (not building) a parser 9 years ago
David Majda f4504a93fe Rename the "buildParser" function to "generate"
In most places, we talk about "generating a parser", not "building a
parser", which the function name should reflect. Also, mentioning a
parser in the name is not necessary as in case of a parser generator
it's pretty clear what is generated.
9 years ago
David Majda 0847a69643 Rename the "PEG" variable to "peg"
So far, PEG.js was exported in a "PEG" global variable when no module
loader was detected. The same variable name was also conventionally used
when requiring it in Node.js or otherwise referring to it. This was
reflected in various places in the code, documentation, examples, etc.

This commit changes the variable name to "peg" and fixes all relevant
occurrences. The main reason for the change is that in Node.js, modules
are generally referred to by lower-case variable names, so "PEG" was
sticking out when used in Node.js projects.
9 years ago
David Majda 057a93fbc7 Move the "Generated by ..." comment out of wrapping functions
The wrapping functions are also generated by PEG.js, so the comment
should be above them to mark them as such. This shouldn't cause any
problems technically.
9 years ago
David Majda f934199fba Simplify code which generates parser wrappers 9 years ago
David Majda f390c7cf45 ESLint: Disable no-console in bin/.eslintrc.json, not bin/pegjs
The less clutter in JavaScript files themselves, the better.
9 years ago
David Majda 810567d865 UMD parsers: Allow specifying parser dependencies
Introduce two ways of specifying parser dependencies: the "dependencies"
option of PEG.buildParser and the -d/--dependency CLI option. Specified
dependencies are translated into AMD dependencies and Node.js's
"require" calls when generating an UMD parser.

Part of work on #362.
9 years ago
David Majda fe6ce38d08 UMD parsers: Regenerate lib/parser.js
Part of work on #362.
9 years ago
David Majda a0a57cd22d UMD parsers: Make bin/pegjs generate UMD parsers
Part of work on #362.
9 years ago
David Majda b87268ade6 UMD parsers: Allow generating parsers in UMD format from the API
Introduce new "format" and "exportVar" options to PEG.buildParser which
together allow generating parsers in UMD format.

Part of work on #362.
9 years ago
David Majda ab0e85b006 UMD parsers: Refactor "generateWrapper"
Extract "generateWrapper" code which generates code of the intro and the
returned parser object into helper functions. This is pure refactoring,
generated parser code is exactly the same as before.

This change will make it easier to modifiy "generateWrapper" to produce
UMD modules.

Part of work on #362.
9 years ago
David Majda 7f8b3f7012 UMD parsers: Generate parser wrapper separately from its toplevel code
Code which was at the toplevel of the "generateJS" function in the code
generator is now split into "generateToplevel" (which genreates parser
toplevel code) and "generateWrapper" (which generates a wrapper around
it). This is pure refactoring, generated parser code is exactly the same
as before.

This change will make it easier to modifiy the code genreator to produce
UMD modules.

Part of work on #362.
9 years ago
David Majda 5e702b5901 lib/compiler.js: Fix indentation 9 years ago
David Majda a89aa11779 README.md: Mention that AMD loader will be used in the browser 9 years ago
David Majda ce44c62f14 Support passing custom location info to "error" and "expected"
Based on a pull request by Konstantin (@YemSalat):

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

Resolves #390.
9 years ago
David Majda da2378d887 Rewrite handling of optional parameters
Instead of testing arguments.length to see whether an optional parameter
was passed to a function, compare its value to "undefined". This
approach has two advantages:

  * It is in line with handling of default parameters in ES6.

  * Optional parameters are actually spelled out in the parameter
    list.

There is also one important disadvantage, namely that it's impossible to
pass "undefined" as an optional parameter value. This required a small
change in two tests.

Additional notes:

  * Default parameter values are set in assignments immediately
    after the function header. This reflects the fact that these
    assignments really belong to the parameter list (which is where they
    are in ES6).

  * Parameter values are checked against "void 0" in places where
    "undefined" can potentially be redefiend.
9 years ago
David Majda f866712c90 Regularize Jasmine custom matcher signatures
The "toParse" matcher in generated-parser-behavior.spec.js effectively
had these signatures:

  toParse(input)
  toParse(input, expected)
  toParse(input, options, expected)

This commit regularizes them to:

  toParse(input)
  toParse(input, expected)
  toParse(input, expected, options)

Similarly, the "toFailToParse" matcher in
generated-parser-behavior.spec.js effectively had these signatures:

  toFailToParse(input)
  toFailToParse(input, details)
  toFailToParse(input, options, details)

This commit regularizes them to:

  toFailToParse(input)
  toFailToParse(input, details)
  toFailToParse(input, details, options)

Finally, the "toChangeAST" matcher in helpers.js effectively had these
signatures:

  toChangeAST(grammar, details)
  toChangeAST(grammar, options, details)

This commit regularizes them to:

  toChangeAST(grammar, details)
  toChangeAST(grammar, details, options)

The overall purpose of these changes is to avoid different parameters
appearing at the same position, which is hard to manage without using
"arguments".
9 years ago
David Majda 7089debae2 .travis.yml: Test also with Node.js 6.0.x 9 years ago
David Majda 0c39f1cf86 Fix labels leaking to outer scope
Labels in expressions like "(a:"a")" or "(a:"a" b:"b" c:"c")" were
visible to the outside despite being wrapped in parens. This commit
makes them invisible, as they should be.

Note this required introduction of a new "group" AST node, whose purpose
is purely to provide label scope isolation. This was necessary because
"label" and "sequence" nodes don't (and can't!) provide this isolation
themselves.

Part of a fix of #396.
9 years ago
David Majda 58806a3d77 Label scope specs: Add negative specs (subexpressions)
Semantic predicate and action specs which verified label scope didn't
exercise labels in subexpressions. This commit adds cases exercising
them, including few commented-out cases which reveal #396 (these will be
uncommented when the bug gets fixed).

Note that added specs exercise all relevant expression types. This is
needed because code that makes subexpression labels invisible to the
outside is separate for each expression type so one generic test
wouldn't generate enough coverage.

Part of a fix of #396.
9 years ago
David Majda ffd90a8c9e Label scope specs: Add negative specs (sequences)
So far, semantic predicate and action specs which verified scope of
labels from containing or outer sequences exercised only cases where
label variables were defined. This commit adds also some negative cases.

The idea comes from @Mingun.
9 years ago
David Majda 7229318671 Label scope specs: Don't exercise all expression types
Semantic predicate and action specs which verified scope of labels from
outer sequences exercised all relevant expression types. This is not
needed as the behavior is common for all expression types and no extra
code needs to be written to make it work for each of them.

This commit changes the specs to verify scope of labels from outer
sequences using only one expression type.
9 years ago
David Majda a20d04edf4 Label scope specs: Remove redundant sequence elements
Semantic predicate specs which verified scope of labels from containing
sequences used 3 elements where 1 is enough.

This commit removes the redundant elements.
9 years ago
David Majda 6bc91c010d Label scope specs: Tweak spec descriptions 9 years ago
David Majda 921f1fa8fa Label scope specs: Tweak suite descriptions 9 years ago
David Majda 5c5f79519a Label scope specs: Simplify semantic predicate and action specs
Semantic predicate and action specs which verified label scope used
repetitive "it" blocks. Rewrite them to use just one "it" block and a
list of testcases. This makes them more concise.
9 years ago
David Majda 31e7147081 Label scope specs: No result checks in semantic predicate specs
Semantic predicate specs which verified label scope also checked parser
results. This is not necessary because for the purpose of these specs it
is enough to verify that label variables have correct values, which is
done in predicate code already.

This commit removes parser result checks from these specs.
9 years ago
David Majda f07ab7f32e examples/json.pegjs: Fix the "unescaped" rule
The "unescaped" rule was created by mechanically translating original
RFC 7159 rule:

  unescaped = %x20-21 / %x23-5B / %x5D-10FFFF

into:

  unescaped = [\x20-\x21\x23-\x5B\x5D-\u10FFFF]

However, this mechanical translation was incorrect as PEG.js grammars
don't have 6-digit Unicode escape sequences. Sequence "\u10FFFF" was
interpreted as "\u10FF" followed by two "F" characters.

This commit rewrites the "unescaped" rule into a form which, while not
being a mechanical translation of the original rule, matches the same
characters in the whole Unicode range. It also macthes textual
description of string representation in RFC 7159:

  All Unicode characters may be placed within the quotation marks,
  except for the characters that must be escaped: quotation mark,
  reverse solidus, and the control characters (U+0000 through U+001F).

Fixes #417.
9 years ago
David Majda 6a04067a76 bin/pegjs: Do not overwrite extension-less files
Running bin/pegjs with one argument which was an extension-less file
name caused the file to be overwritten. This was because internal
extension rewriting logic didn't handle this case corectly.

This commit changes the logic from regexp-based to path.extname-based,
fixing the problem. The new code generates file names like this:

  Input file name     Output file name
  ------------------------------------
  grammar.ext         grammar.js
  grammar.ext1.ext2   grammar.ext1.js
  grammar.            grammar.js
  grammar             grammar.js

Fixes #405.
9 years ago
David Majda 5eb6225ef0 Merge pull request #420 from bkutil/patch-1
Grammar fix in ISSUE_TEMPLATE.md and CONTRIBUTING.md
9 years ago
Balázs Kutil 7f2358af1f Grammar fix in ISSUE_TEMPLATE.md and CONTRIBUTING.md 9 years ago
David Majda 4d85464ac4 README.md: Fix npm & Bower badges to show PEG.js version
Based on a pull request by Daniel Baird (@DanielBaird):

  https://github.com/pegjs/pegjs/pull/419
9 years ago
David Majda db1cc55512 Add a .github directory with contribution guidelines and templates 9 years ago
David Majda d56b43bb54 README.md: Add badges
Based on a pull request by Adrien Becchis (@AdrieanKhisbe):

  https://github.com/pegjs/pegjs/pull/392
9 years ago
David Majda 88f1d1369b Detect newlines using charCodeAt instead of charCode
In generated parsers, detect newlines using charCodeAt instead of
charCode. This should be slightly faster.
9 years ago
David Majda 18d266be67 Remove support for newlines other than "\n" and "\r\n"
Before this commit, generated parsers considered the following character
sequences as newlines:

  Sequence   Description
  ------------------------------
  "\n"       Unix
  "\r"       Old Mac
  "\r\n"     Windows
  "\u2028"   line separator
  "\u2029"   paragraph separator

This commit limits the sequences only to "\n" and "\r\n". The reason is
that nobody uses Unicode newlines or "\r" in practice.

A positive side effect of the change is that newline-handling code
became simpler (and likely faster).
9 years ago
David Majda e61c23c634 ESLint: Set environments better
Instead of setting ESLint environment to "node" globally, set it on
per-directory basis using separate .eslintrc.json files:

  Directory   Environment
  -----------------------
  bin         node
  lib         commonjs
  spec        jasmine

It was impossible to use this approach for the "benchmark" directory
which contains a mix of files used in various environments. For
benchmark/run, the environment is set inline. For the other files, as
well as spec/helpers.js, the globals are declared manually (it is
impossible to express how these files are used just by a list of
environments).

Fixes #408.
9 years ago
David Majda 0e66f19523 Makefile: Remove obsolete comment
It should have been removed with the switch to Browserify in
0d8c045823.
9 years ago
David Majda ddd4ac3787 Fix ESLint errors in lib/parser.js
Fix the following errors:

    31:9   error  "parser" is defined but never used    no-unused-vars
   406:14  error  "expected" is defined but never used  no-unused-vars
  1304:15  error  "s1" is defined but never used        no-unused-vars
  1386:15  error  "s1" is defined but never used        no-unused-vars
  1442:15  error  "s1" is defined but never used        no-unused-vars
9 years ago
David Majda c8d23e5471 Fix ESLint errors in bin/pegjs
Fix the following errors:

   12:3  error  Unexpected console statement       no-console
   16:3  error  Unexpected console statement       no-console
   17:3  error  Unexpected console statement       no-console
   18:3  error  Unexpected console statement       no-console
   19:3  error  Unexpected console statement       no-console
   20:3  error  Unexpected console statement       no-console
   21:3  error  Unexpected console statement       no-console
   22:3  error  Unexpected console statement       no-console
   23:3  error  Unexpected console statement       no-console
   24:3  error  Unexpected console statement       no-console
   25:3  error  Unexpected console statement       no-console
   26:3  error  Unexpected console statement       no-console
   27:3  error  Unexpected console statement       no-console
   28:3  error  Unexpected console statement       no-console
   29:3  error  Unexpected console statement       no-console
   30:3  error  Unexpected console statement       no-console
   31:3  error  Unexpected console statement       no-console
   32:3  error  Unexpected console statement       no-console
   33:3  error  Unexpected console statement       no-console
   34:3  error  Unexpected console statement       no-console
   35:3  error  Unexpected console statement       no-console
   36:3  error  Unexpected console statement       no-console
   37:3  error  Unexpected console statement       no-console
   38:3  error  Unexpected console statement       no-console
   39:3  error  Unexpected console statement       no-console
   40:3  error  Unexpected console statement       no-console
   41:3  error  Unexpected console statement       no-console
   42:3  error  Unexpected console statement       no-console
   43:3  error  Unexpected console statement       no-console
   44:3  error  Unexpected console statement       no-console
   56:3  error  Unexpected console statement       no-console
  232:9  error  "inputStream" is already defined   no-redeclare
  240:9  error  "outputStream" is already defined  no-redeclare
9 years ago
David Majda ee66113130 Fix ESLint errors in benchmark/run
Fix the following errors:

   37:3   error  Unexpected console statement      no-console
   38:3   error  Unexpected console statement      no-console
   42:3   error  Unexpected console statement      no-console
   43:3   error  Unexpected console statement      no-console
   44:3   error  Unexpected console statement      no-console
   51:3   error  Unexpected console statement      no-console
   64:3   error  Unexpected console statement      no-console
   68:3   error  Unexpected console statement      no-console
   74:3   error  Unexpected console statement      no-console
   75:3   error  Unexpected console statement      no-console
   76:3   error  Unexpected console statement      no-console
   77:3   error  Unexpected console statement      no-console
   78:3   error  Unexpected console statement      no-console
   79:3   error  Unexpected console statement      no-console
   80:3   error  Unexpected console statement      no-console
   81:3   error  Unexpected console statement      no-console
   82:3   error  Unexpected console statement      no-console
   94:3   error  Unexpected console statement      no-console
  126:11  error  "runCount" is already defined     no-redeclare
  169:34  error  "test" is defined but never used  no-unused-vars
  194:4   error  Unexpected trailing comma         comma-dangle
9 years ago
David Majda 488f32e661 Fix ESLint errors in benchmark/index.js
Fix the following errors:

  74:14  error  "benchmarks" is not defined       no-undef
  84:36  error  "test" is defined but never used  no-unused-vars
9 years ago
David Majda 00faf20fe1 Fix ESLint errors in spec/behavior/generated-parser-behavior.spec.js
Fix the following errors:

   24:46  error  Unexpected trailing comma  comma-dangle
  403:26  error  Unexpected trailing comma  comma-dangle
  414:26  error  Unexpected trailing comma  comma-dangle
9 years ago
David Majda 04f8b50f80 Fix ESLint errors in spec/api/plugin-api.spec.js
Fix the following errors:

   59:35  error  "options" is defined but never used  no-unused-vars
   91:11  error  "plugin" is defined but never used   no-unused-vars
  102:35  error  "options" is defined but never used  no-unused-vars
  128:35  error  "options" is defined but never used  no-unused-vars

Note that ESLint revealed a real problem where the test supposedly
verifying receiving options by a plugin didn't actually verify anything.
9 years ago
David Majda 47ac688ce9 Fix ESLint errors in spec/api/generated-parser-api.spec.js
Fix the following errors:

  65:20  error  Unexpected console statement  no-console
  66:20  error  Unexpected console statement  no-console
  67:20  error  Unexpected console statement  no-console
  68:20  error  Unexpected console statement  no-console
  69:20  error  Unexpected console statement  no-console
  70:20  error  Unexpected console statement  no-console
9 years ago
David Majda 88c957c9e8 Fix ESLint errors in lib/compiler/passes/generate-js.js
Fix the following errors:

   65:11  error  Unexpected trailing comma  comma-dangle
  211:40  error  Unexpected trailing comma  comma-dangle
  223:27  error  Unexpected trailing comma  comma-dangle
  233:27  error  Unexpected trailing comma  comma-dangle
9 years ago
David Majda 768ece28e6 Use ESLint instead of JSHint
Implement the swap and change various directives in the source code. The
"make hint" target becomes "make lint".

The change leads to quite some errors being reported by ESLint. These
will be fixed in subsequent commits.

Note the configuration enables just the recommended rules. Later I plan
to enable more rules to enforce the coding standard. The configuration
also sets the environment to "node", which is far from ideal as the
codebase contains a mix of CommonJS, Node.js and browser code. I hope to
clean this up at some point.
9 years ago