Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. [![Npm Package](https://badgen.net/npm/v/jsdoc-type-pratt-parser)](https://www.npmjs.com/package/jsdoc-type-pratt-parser)
  2. [![Test Status](https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/actions?query=branch%3Amain)
  3. [![Coverage Status](https://coveralls.io/repos/github/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/badge.svg?branch=main)](https://coveralls.io/github/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser?branch=main)
  4. [![Code Style](https://badgen.net/badge/code%20style/ts-standard/blue?icon=typescript)](https://github.com/standard/ts-standard)
  5. [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
  6. This project is a parser for jsdoc types. It is heavily inspired by the existing libraries catharsis and
  7. jsdoctypeparser, but does not use PEG.js, instead it is written as a pratt parser.
  8. * https://github.com/hegemonic/catharsis
  9. * https://github.com/jsdoctypeparser/jsdoctypeparser
  10. * http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
  11. Live Demo
  12. ---------
  13. A simple live demo to test expressions can be found at: https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/
  14. Getting started
  15. ---------------
  16. ```
  17. npm install jsdoc-type-pratt-parser@alpha
  18. ```
  19. ```js
  20. import { parse } from 'jsdoc-type-pratt-parser'
  21. const result = parse('myType.<string>', 'closure')
  22. ```
  23. This library supports compatibility modes for catharsis and jsdoctypeparser. The provided transform functions attempt to
  24. transform the output to the expected output of the target library. This will not always be the same as some types are
  25. parsed differently. These modes are thought to make transition easier, but it is advised to use the native output as
  26. this will be more uniform and will contain more information.
  27. Catharsis compat mode:
  28. ```js
  29. import { parse, catharsisTransform } from 'jsdoc-type-pratt-parser'
  30. const result = catharsisTransform(parse('myType.<string>', 'closure'))
  31. ```
  32. Jsdoctypeparser compat mode:
  33. ```js
  34. import { parse, jtpTransform } from 'jsdoc-type-pratt-parser'
  35. const result = jtpTransform(parse('myType.<string>', 'closure'))
  36. ```
  37. Stringify:
  38. ```js
  39. import { stringify } from 'jsdoc-type-pratt-parser'
  40. const val = stringify({ type: 'JsdocTypeName', value: 'name'}) // -> 'name'
  41. ```
  42. You can customize the stringification by using `stringifyRules` and `transform`:
  43. ```js
  44. import { stringifyRules, transform } from 'jsdoc-type-pratt-parser'
  45. const rules = stringifyRules()
  46. // `result` is the current node and `transform` is a function to transform child nodes.
  47. rules.NAME = (result, transform) => 'something else'
  48. const val = transform(rules, { type: 'JsdocTypeName', value: 'name'}) // -> 'something else'
  49. ```
  50. You can traverse a result tree with the `traverse` function:
  51. ```js
  52. import { traverse } from 'jsdoc-type-pratt-parser'
  53. // property is the name of the property on parent that contains node
  54. function onEnter(node, parent, property) {
  55. console.log(node.type)
  56. }
  57. // an onEnter and/or an onLeave function can be supplied
  58. traverse({ type: 'JsdocTypeName', value: 'name'}, onEnter, console.log)
  59. ```
  60. You can also build your own transform rules by implementing the `TransformRules<TransformResultType>` interface or you
  61. can build upon the identity ruleset like this:
  62. ```js
  63. import { identityTransformRules, transform } from 'jsdoc-type-pratt-parser'
  64. const myRules = identityTransformRules()
  65. myRules.NAME = () => ({ type: 'JsdocTypeName', value: 'funky' })
  66. const val = transform(myRules, result)
  67. ```
  68. Available Grammars
  69. ------------------
  70. Three different modes (grammars) are supported: `'jsdoc'`, `'closure'` and `'typescript'`
  71. Tests Status
  72. ------------
  73. This parser runs most tests of https://github.com/hegemonic/catharsis and
  74. https://github.com/jsdoctypeparser/jsdoctypeparser. It compares the results of the different parsing libraries. If you
  75. want to find out where the output differs, look in the tests for the comments `// This seems to be an error of ...` or
  76. the `differ` keyword which indicates that differing results are produced.
  77. API Documentation
  78. -----------------
  79. An API documentation can be found here: https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/modules.html
  80. Performance
  81. -----------
  82. A simple performance [comparision](benchmark/benchmark.js) using [Benchmark.js](https://benchmarkjs.com/) produced the following results:
  83. ```
  84. Testing expression: Name
  85. catharsis x 36,338 ops/sec ±1.10% (1071 runs sampled)
  86. jsdoc-type-pratt-parser x 400,260 ops/sec ±0.87% (1070 runs sampled)
  87. jsdoctypeparser x 61,847 ops/sec ±1.18% (1071 runs sampled)
  88. The fastest was jsdoc-type-pratt-parser
  89. Testing expression: Array<number>
  90. catharsis x 7,969 ops/sec ±1.05% (1079 runs sampled)
  91. jsdoc-type-pratt-parser x 159,001 ops/sec ±0.95% (1074 runs sampled)
  92. jsdoctypeparser x 42,278 ops/sec ±1.01% (1070 runs sampled)
  93. The fastest was jsdoc-type-pratt-parser
  94. Testing expression: { keyA: Type<A | "string val" >, keyB: function(string, B): A }
  95. catharsis x 933 ops/sec ±1.15% (1070 runs sampled)
  96. jsdoc-type-pratt-parser x 29,596 ops/sec ±0.90% (1068 runs sampled)
  97. jsdoctypeparser x 16,206 ops/sec ±1.38% (1055 runs sampled)
  98. The fastest was jsdoc-type-pratt-parser
  99. ```
  100. the test uses catharsis without cache, as this is just a simple lookup table that could easily be implemented for any parser.