Skip to content

Latest commit

 

History

History
88 lines (48 loc) · 2 KB

api-reference.md

File metadata and controls

88 lines (48 loc) · 2 KB

PrismGrammar Methods

For node:

PrismGrammar = require('build/prism_grammar.js');

For browser:

<script src="build/prism_grammar.js"></script>

Method: clone

cloned_grammar = PrismGrammar.clone( grammar [, deep=true] );

Clone (deep) a grammar

Utility to clone objects efficiently

Method: extend

extended_grammar = PrismGrammar.extend( grammar, basegrammar1 [, basegrammar2, ..] );

Extend a grammar with basegrammar1, basegrammar2, etc..

This way arbitrary dialects and variations can be handled more easily

Method: pre_process

pre_processed_grammar = PrismGrammar.pre_process( grammar );

This is used internally by the PrismGrammar Class parse method In order to pre-process a JSON grammar (in-place) to transform any shorthand configurations to full object configurations and provide defaults. It also parses PEG/BNF (syntax) notations into full (syntax) configuration objects, so merging with other grammars can be easier if needed.

Method: parse

parsed_grammar = PrismGrammar.parse( grammar );

This is used internally by the PrismGrammar Class In order to parse a JSON grammar to a form suitable to be used by the syntax-highlighter. However user can use this method to cache a parsedgrammar to be used later. Already parsed grammars are NOT re-parsed when passed through the parse method again

Method: getMode

mode = PrismGrammar.getMode( grammar );

This is the main method which transforms a JSON grammar into a syntax-highlighter for Prism.

Parser Class: Parser

Parser = PrismGrammar.Parser;

The Parser Class used to instantiate a highlight parser, is available. The getMode method will instantiate this parser class, which can be overriden/extended if needed, as needed. In general there is no need to override/extend the parser, unless you definately need to.