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

Added support for flow library definitions #411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Added support for flow library definitions #411

wants to merge 2 commits into from

Conversation

lyckligtax
Copy link

Changes

Added flow library definitions for nearley.js

  • Adds type inference support for most major IDEs
  • No changes to the codebase needed -> no harm done

Test

> mocha test/*.test.js



  bootstrapped lexer
    ✓ lexes directives
    ✓ lexes a simple rule
    ✓ lexes arrows
    ✓ lexes js code
    ✓ lexes charclasses
    ✓ rejects newline in charclass
    ✓ lexes macros
    ✓ lexes strings
    ✓ lexes strings non-greedily 
    ✓ lexes a rule

  bootstrapped parser
    ✓ parses directives
    ✓ parses simple rules
    ✓ parses postprocessors
    ✓ parses js code
    ✓ parses options
    ✓ parses tokens
    ✓ parses strings
    ✓ parses charclasses
    ✓ parses macro definitions
    ✓ parses macro use
    ✓ parses macro use
    ✓ parses a rule

  Linter
    ✓ runs without warnings on empty rules
    ✓ warns about undefined symbol
    ✓ doesn't warn about defined symbol
    ✓ doesn't warn about duplicate symbol

  bin/nearleyc
    ✓ builds for ES5 (77ms)
    ✓ builds for ES6+ (831ms)
    ✓ builds for CoffeeScript (183ms)
    ✓ builds for TypeScript (1322ms)
    ✓ builds modules in folders (87ms)
    ✓ builds modules with multiple includes of the same file (75ms)
    ✓ warns about undefined symbol (92ms)
    ✓ doesn't warn when used with the --quiet option (81ms)
    ✓ allows trailing comments without newline terminators (81ms)

  nearleyc: example grammars
    ✓ calculator example
    ✓ csscolor example
    ✓ exponential whitespace bug
    ✓ percent bug
    ✓ json
    ✓ classic crontab
    ✓ case-insensitive strings
    ✓ scannerless nearley grammar

  nearleyc: builtins
    ✓ generate includes id
    - nuller

  nearleyc: macros
    ✓ seems to work
    ✓ must be defined before use
    ✓ compiles a simple macro from external file

  Parser: API
    ✓ shows line number in errors
    ✓ shows token index in errors
    ✓ can save state
    ✓ can rewind
    ✓ won't rewind without `keepHistory` option
    ✓ restores line numbers
    ✓ restores column number

  Parser: examples
    ✓ nullable whitespace bug
    ✓ parentheses
    ✓ tokens
    ✓ json
    ✓ tosh (259ms)


  59 passing (3s)
  1 pending


Process finished with exit code 0

Benchmark

> benchr test/benchmark.js

• test/benchmark.js:

  • calculator: parse.

    ✔  nearley  11,778.95  ops/sec  ±2.69%  (83 runs)

  • json: parse sample1k.

    ✔  nearley  88.97  ops/sec  ±8.07%  (65 runs)

  • tosh: parse.

    ✔  nearley  1,811.38  ops/sec  ±4.53%  (82 runs)


Process finished with exit code 0

  - libdef added for nearley.js
@tjvr tjvr requested a review from kach November 5, 2018 23:16
nearley.js.flow Outdated
* @deprecated rewind
*/
rewind(index: number): void;
rewind(index: number): void;
Copy link
Owner

Choose a reason for hiding this comment

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

This line seems duplicated?

Copy link
Author

Choose a reason for hiding this comment

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

Your're absolutely correct. Must have hit the duplicate key instead of save (ctrl+d vs ctrl+s), sry for that. Has been fixed :-)

removed duplicate Parser.rewind function declaration
@lyckligtax
Copy link
Author

Is there anything left to do to merge this? Will gladly work further on this if needed

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

2 participants