1
1
/**
2
2
*
3
3
* CodeMirrorGrammar
4
- * @version : 2.6.0
4
+ * @version : 2.6.1
5
5
*
6
6
* Transform a grammar specification in JSON format, into a syntax-highlight parser mode for CodeMirror
7
7
* https://github.com/foo123/codemirror-grammar
@@ -36,7 +36,7 @@ else if ( !(name in root) )
36
36
"use strict" ;
37
37
/**
38
38
* EditorGrammar Codebase
39
- * @version : 2.6.0
39
+ * @version : 2.6.1
40
40
*
41
41
* https://github.com/foo123/editor-grammar
42
42
**/
@@ -1934,6 +1934,39 @@ function get_block_types( grammar, the_styles )
1934
1934
return blocks ;
1935
1935
}
1936
1936
1937
+ function preprocess_and_parse_grammar ( grammar )
1938
+ {
1939
+ var processed = { } ; // for recursive references
1940
+ grammar . Lex = grammar . Lex || { } ; grammar . Syntax = grammar . Syntax || { } ;
1941
+ grammar = preprocess_grammar ( grammar ) ;
1942
+ if ( grammar . Parser && grammar . Parser . length )
1943
+ {
1944
+ iterate ( function process ( i , T ) {
1945
+ var id = T [ i ] , t , token , type , tokens ;
1946
+ if ( processed [ id ] ) return ;
1947
+ if ( T_ARRAY & get_type ( id ) )
1948
+ {
1949
+ // literal n-gram as array
1950
+ t = id ; id = "NGRAM_" + t . join ( "_" ) ;
1951
+ if ( ! grammar . Syntax [ id ] ) grammar . Syntax [ id ] = { type :"ngram" , tokens :t } ;
1952
+ }
1953
+ token = get_backreference ( id , grammar . Lex , grammar . Syntax ) ;
1954
+ if ( T_STR & get_type ( token ) )
1955
+ {
1956
+ token = parse_peg_bnf_notation ( token , grammar . Lex , grammar . Syntax ) ;
1957
+ token = grammar . Lex [ token ] || grammar . Syntax [ token ] || null ;
1958
+ }
1959
+ if ( token )
1960
+ {
1961
+ processed [ id ] = token ;
1962
+ type = token . type ? tokenTypes [ token . type [ LOWER ] ( ) . replace ( dashes_re , '' ) ] || T_SIMPLE : T_SIMPLE ;
1963
+ if ( T_COMPOSITE & type ) iterate ( process , 0 , token . tokens . length - 1 , token . tokens ) ;
1964
+ }
1965
+ } , 0 , grammar . Parser . length - 1 , grammar . Parser ) ;
1966
+ }
1967
+ return grammar ;
1968
+ }
1969
+
1937
1970
function parse_grammar ( grammar )
1938
1971
{
1939
1972
var RegExpID , tokens ,
@@ -3396,7 +3429,7 @@ var Folder = {
3396
3429
/**
3397
3430
*
3398
3431
* CodeMirrorGrammar
3399
- * @version : 2.6.0
3432
+ * @version : 2.6.1
3400
3433
*
3401
3434
* Transform a grammar specification in JSON format, into a syntax-highlight parser mode for CodeMirror
3402
3435
* https://github.com/foo123/codemirror-grammar
@@ -3406,7 +3439,7 @@ var Folder = {
3406
3439
3407
3440
3408
3441
// codemirror supposed to be available
3409
- var $CodeMirror$ = CodeMirror || { Pass : { toString : function ( ) { return "CodeMirror.Pass" ; } } } ,
3442
+ var $CodeMirror$ = 'undefined' !== typeof CodeMirror ? CodeMirror : { Pass : { toString : function ( ) { return "CodeMirror.Pass" ; } } } ,
3410
3443
// used for autocompletion
3411
3444
RE_W = / [ \w $ ] / , by_score = function ( a , b ) { return b . score - a . score }
3412
3445
;
@@ -3719,7 +3752,7 @@ function get_mode( grammar, DEFAULT, CodeMirror )
3719
3752
* __For node:__
3720
3753
*
3721
3754
* ```javascript
3722
- * CodeMirrorGrammar = require('build/codemirror_grammar.js').CodeMirrorGrammar ;
3755
+ * CodeMirrorGrammar = require('build/codemirror_grammar.js');
3723
3756
* ```
3724
3757
*
3725
3758
* __For browser:__
@@ -3731,14 +3764,14 @@ function get_mode( grammar, DEFAULT, CodeMirror )
3731
3764
[/DOC_MARKDOWN]**/
3732
3765
var CodeMirrorGrammar = exports [ 'CodeMirrorGrammar' ] = {
3733
3766
3734
- VERSION : "2.6.0 " ,
3767
+ VERSION : "2.6.1 " ,
3735
3768
3736
3769
// clone a grammar
3737
3770
/**[DOC_MARKDOWN]
3738
3771
* __Method__: `clone`
3739
3772
*
3740
3773
* ```javascript
3741
- * cloned = CodeMirrorGrammar.clone( grammar [, deep=true] );
3774
+ * cloned_grammar = CodeMirrorGrammar.clone( grammar [, deep=true] );
3742
3775
* ```
3743
3776
*
3744
3777
* Clone (deep) a `grammar`
@@ -3752,7 +3785,7 @@ var CodeMirrorGrammar = exports['CodeMirrorGrammar'] = {
3752
3785
* __Method__: `extend`
3753
3786
*
3754
3787
* ```javascript
3755
- * extendedgrammar = CodeMirrorGrammar.extend( grammar, basegrammar1 [, basegrammar2, ..] );
3788
+ * extended_grammar = CodeMirrorGrammar.extend( grammar, basegrammar1 [, basegrammar2, ..] );
3756
3789
* ```
3757
3790
*
3758
3791
* Extend a `grammar` with `basegrammar1`, `basegrammar2`, etc..
@@ -3766,21 +3799,21 @@ var CodeMirrorGrammar = exports['CodeMirrorGrammar'] = {
3766
3799
* __Method__: `pre_process`
3767
3800
*
3768
3801
* ```javascript
3769
- * CodeMirrorGrammar.pre_process( grammar );
3802
+ * pre_processed_grammar = CodeMirrorGrammar.pre_process( grammar );
3770
3803
* ```
3771
3804
*
3772
3805
* This is used internally by the `CodeMirrorGrammar` Class `parse` method
3773
- * In order to pre-process, in-place, a `JSON grammar`
3774
- * to transform any shorthand configurations to full object configurations and provide defaults .
3806
+ * In order to pre-process a `JSON grammar` (in-place) to transform any shorthand configurations to full object configurations and provide defaults.
3807
+ * It also parses `PEG`/`BNF` (syntax) notations into full (syntax) configuration objects, so merging with other grammars can be easier, if needed .
3775
3808
[/DOC_MARKDOWN]**/
3776
- pre_process : preprocess_grammar ,
3809
+ pre_process : preprocess_and_parse_grammar ,
3777
3810
3778
3811
// parse a grammar
3779
3812
/**[DOC_MARKDOWN]
3780
3813
* __Method__: `parse`
3781
3814
*
3782
3815
* ```javascript
3783
- * parsedgrammar = CodeMirrorGrammar.parse( grammar );
3816
+ * parsed_grammar = CodeMirrorGrammar.parse( grammar );
3784
3817
* ```
3785
3818
*
3786
3819
* This is used internally by the `CodeMirrorGrammar` Class
0 commit comments