1.0.2 • Published 4 years ago

@kajberg/parser v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

:memo: Kaj Berg - Parser

User Manual!

  1. Import startApplication from @kajberg/parser.
  2. startApplication(x,y) Returns an Instans of a parser.
  3. X parameter: Collection of grammar.
  4. Y parameter: Document to create tokens from(Type String).
  5. Use methods below for desired behavior.

How to use it

import { startApplikation } from '@kajberg/Parser.'

 const grammarExample = [
  {
    tokenType: "WORD",
    tokenRegex: /^[\w|åäöÅÄÖ]+/,
  },
  {
    tokenType: "DOT",
    tokenRegex: /^\./,
  },
  {
    tokenType: "EXCLAMATION",
    tokenRegex: /^\!/,
  },
  {
    tokenType: "QUESTION",
    tokenRegex: /^\?/,
  },
];

const inputExample= 'Hello example! Hello? Yes.'

const parser = new Parser(grammarExample);
const document = parser.parse(inputExample);
// Returns all created sentences object.
  const allSentences = document.getAllSentences();

// Returns all regular sentences object.
  const allRegularSentences = document.getRegularSentences();

// Returns all question sentences object.
  const allQuestionSentences = document.getQuestionSentences();

// Returns all exclamation sentences object.
  const allExclamationSentences = document.getExclamationSentences();

Methods for Parser

getAllSentences()
Returns all created sentences.

getRegularSentences()
Returns all regular sentences.

getQuestionSentences()
Returns all question sentences.

getExclamationSentences()
Returns all exclamation sentences.