Automated merge with http://hg.netbeans.org/main/contrib
authorMarek Fukala <mfukala@netbeans.org>
Sat, 12 Jan 2013 08:46:08 +0100
changeset 179196ac43eb330ca
parent 17917 41056598da26
parent 17918 4b94799b0c17
child 17920 25a8acfe62f4
Automated merge with http://hg.netbeans.org/main/contrib
     1.1 --- a/o.n.antlr.editor/manifest.mf	Fri Jan 11 18:31:02 2013 +0100
     1.2 +++ b/o.n.antlr.editor/manifest.mf	Sat Jan 12 08:46:08 2013 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4  Manifest-Version: 1.0
     1.5  OpenIDE-Module: org.netbeans.antlr.editor
     1.6 -OpenIDE-Module-Layer: org/netbeans/antlr/editor/layer.xml
     1.7 -OpenIDE-Module-Localizing-Bundle: org/netbeans/antlr/editor/Bundle.properties
     1.8 +OpenIDE-Module-Layer: org/netbeans/modules/antlr/editor/layer.xml
     1.9 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/antlr/editor/Bundle.properties
    1.10  OpenIDE-Module-Specification-Version: 0.1
    1.11  
     2.1 --- a/o.n.antlr.editor/nbproject/project.xml	Fri Jan 11 18:31:02 2013 +0100
     2.2 +++ b/o.n.antlr.editor/nbproject/project.xml	Sat Jan 12 08:46:08 2013 +0100
     2.3 @@ -122,6 +122,15 @@
     2.4                      </run-dependency>
     2.5                  </dependency>
     2.6              </module-dependencies>
     2.7 +            <test-dependencies>
     2.8 +                <test-type>
     2.9 +                    <name>unit</name>
    2.10 +                    <test-dependency>
    2.11 +                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
    2.12 +                        <compile-dependency/>
    2.13 +                    </test-dependency>
    2.14 +                </test-type>
    2.15 +            </test-dependencies>
    2.16              <public-packages/>
    2.17          </data>
    2.18      </configuration>
     3.1 --- a/o.n.antlr.editor/src/org/netbeans/modules/antlr/editor/AntlrCslLanguage.java	Fri Jan 11 18:31:02 2013 +0100
     3.2 +++ b/o.n.antlr.editor/src/org/netbeans/modules/antlr/editor/AntlrCslLanguage.java	Sat Jan 12 08:46:08 2013 +0100
     3.3 @@ -46,6 +46,7 @@
     3.4  import org.netbeans.modules.csl.spi.DefaultLanguageConfig;
     3.5  import org.netbeans.modules.csl.spi.LanguageRegistration;
     3.6  import org.netbeans.modules.parsing.spi.indexing.PathRecognizerRegistration;
     3.7 +import org.openide.filesystems.MIMEResolver;
     3.8  import org.openide.util.Lookup;
     3.9  import org.openide.util.NbBundle;
    3.10  import org.openide.windows.TopComponent;
    3.11 @@ -61,6 +62,13 @@
    3.12  @PathRecognizerRegistration(mimeTypes = "text/antlr", libraryPathIds = {}, binaryLibraryPathIds = {}) //NOI18N
    3.13  public class AntlrCslLanguage extends DefaultLanguageConfig {
    3.14   
    3.15 +    @MIMEResolver.ExtensionRegistration(
    3.16 +        extension={ "g" },
    3.17 +        displayName="#AntlrResolver",
    3.18 +        mimeType="text/antlr",
    3.19 +        position=1111
    3.20 +    )
    3.21 +    @NbBundle.Messages("AntlrResolver=ANTLR Files")
    3.22       @MultiViewElement.Registration(displayName = "#LBL_AntlrEditorTab",
    3.23          iconBase = "org/netbeans/modules/antlr/editor/build.png",
    3.24          persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
    3.25 @@ -75,12 +83,7 @@
    3.26      public org.netbeans.api.lexer.Language getLexerLanguage() {
    3.27          return AntlrTokenId.language();
    3.28      }
    3.29 -
    3.30 -    @Override
    3.31 -    public String getPreferredExtension() {
    3.32 -        return "g";
    3.33 -    }
    3.34 -   
    3.35 +  
    3.36      @Override
    3.37      public String getDisplayName() {
    3.38          return Bundle.language_displaname();
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/o.n.antlr.editor/test/unit/data/testfiles/ANTLRv3.g	Sat Jan 12 08:46:08 2013 +0100
     4.3 @@ -0,0 +1,610 @@
     4.4 +/*
     4.5 + [The "BSD licence"]
     4.6 + Copyright (c) 2005-2007 Terence Parr
     4.7 + All rights reserved.
     4.8 +
     4.9 + Redistribution and use in source and binary forms, with or without
    4.10 + modification, are permitted provided that the following conditions
    4.11 + are met:
    4.12 + 1. Redistributions of source code must retain the above copyright
    4.13 +    notice, this list of conditions and the following disclaimer.
    4.14 + 2. Redistributions in binary form must reproduce the above copyright
    4.15 +    notice, this list of conditions and the following disclaimer in the
    4.16 +    documentation and/or other materials provided with the distribution.
    4.17 + 3. The name of the author may not be used to endorse or promote products
    4.18 +    derived from this software without specific prior written permission.
    4.19 +
    4.20 + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    4.21 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    4.22 + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    4.23 + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    4.24 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    4.25 + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    4.26 + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    4.27 + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    4.28 + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    4.29 + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    4.30 +*/
    4.31 +
    4.32 +/** ANTLR v3 grammar written in ANTLR v3 with AST construction */
    4.33 +grammar ANTLRv3;
    4.34 +
    4.35 +
    4.36 +options {
    4.37 +	output=AST;
    4.38 +	ASTLabelType=CommonTree;
    4.39 +}
    4.40 +
    4.41 +tokens {
    4.42 +	DOC_COMMENT;
    4.43 +	PARSER;	
    4.44 +    LEXER;
    4.45 +    RULE;
    4.46 +    BLOCK;
    4.47 +    OPTIONAL;
    4.48 +    CLOSURE;
    4.49 +    POSITIVE_CLOSURE;
    4.50 +    SYNPRED;
    4.51 +    RANGE;
    4.52 +    CHAR_RANGE;
    4.53 +    EPSILON;
    4.54 +    ALT;
    4.55 +    EOR;
    4.56 +    EOB;
    4.57 +    EOA; // end of alt
    4.58 +    ID;
    4.59 +    ARG;
    4.60 +    ARGLIST;
    4.61 +    RET;
    4.62 +    LEXER_GRAMMAR;
    4.63 +    PARSER_GRAMMAR;
    4.64 +    TREE_GRAMMAR;
    4.65 +    COMBINED_GRAMMAR;
    4.66 +    INITACTION;
    4.67 +    LABEL; // $x used in rewrite rules
    4.68 +    TEMPLATE;
    4.69 +    SCOPE='scope';
    4.70 +    SEMPRED;
    4.71 +    GATED_SEMPRED; // {p}? =>
    4.72 +    SYN_SEMPRED; // (...) =>   it's a manually-specified synpred converted to sempred
    4.73 +    BACKTRACK_SEMPRED; // auto backtracking mode syn pred converted to sempred
    4.74 +    FRAGMENT='fragment';
    4.75 +    TREE_BEGIN='^(';
    4.76 +    ROOT='^';
    4.77 +    BANG='!';
    4.78 +    RANGE='..';
    4.79 +    REWRITE='->';
    4.80 +}
    4.81 +
    4.82 +@lexer::header {
    4.83 +package org.netbeans.antlr.editor.gen;
    4.84 +}
    4.85 +@header {
    4.86 +package org.netbeans.antlr.editor.gen;
    4.87 +}
    4.88 +@members {
    4.89 +	int gtype;
    4.90 +}
    4.91 +
    4.92 +grammarDef
    4.93 +    :   DOC_COMMENT?
    4.94 +    	(	'lexer'  {gtype=LEXER_GRAMMAR;}    // pure lexer
    4.95 +    	|   'parser' {gtype=PARSER_GRAMMAR;}   // pure parser
    4.96 +    	|   'tree'   {gtype=TREE_GRAMMAR;}     // a tree parser
    4.97 +    	|		     {gtype=COMBINED_GRAMMAR;} // merged parser/lexer
    4.98 +    	)
    4.99 +    	g='grammar' id ';' optionsSpec? tokensSpec? attrScope* action*
   4.100 +    	rule+
   4.101 +    	EOF
   4.102 +    	-> ^( {adaptor.create(gtype,$g)}
   4.103 +    		  id DOC_COMMENT? optionsSpec? tokensSpec? attrScope* action* rule+
   4.104 +    		)
   4.105 +    ;
   4.106 +
   4.107 +tokensSpec
   4.108 +	:	TOKENS tokenSpec+ '}' -> ^(TOKENS tokenSpec+)
   4.109 +	;
   4.110 +
   4.111 +tokenSpec
   4.112 +	:	TOKEN_REF
   4.113 +		(	'=' (lit=STRING_LITERAL|lit=CHAR_LITERAL)	-> ^('=' TOKEN_REF $lit)
   4.114 +		|												-> TOKEN_REF
   4.115 +		)
   4.116 +		';'
   4.117 +	;
   4.118 +
   4.119 +attrScope
   4.120 +	:	'scope' id ACTION -> ^('scope' id ACTION)
   4.121 +	;
   4.122 +
   4.123 +/** Match stuff like @parser::members {int i;} */
   4.124 +action
   4.125 +	:	'@' (actionScopeName '::')? id ACTION -> ^('@' actionScopeName? id ACTION)
   4.126 +	;
   4.127 +
   4.128 +/** Sometimes the scope names will collide with keywords; allow them as
   4.129 + *  ids for action scopes.
   4.130 + */
   4.131 +actionScopeName
   4.132 +	:	id
   4.133 +	|	l='lexer'	-> ID[$l]
   4.134 +    |   p='parser'	-> ID[$p]
   4.135 +	;
   4.136 +
   4.137 +optionsSpec
   4.138 +	:	OPTIONS (option ';')+ '}' -> ^(OPTIONS option+)
   4.139 +	;
   4.140 +
   4.141 +option
   4.142 +    :   id '=' optionValue -> ^('=' id optionValue)
   4.143 + 	;
   4.144 + 	
   4.145 +optionValue
   4.146 +    :   id
   4.147 +    |   STRING_LITERAL
   4.148 +    |   CHAR_LITERAL
   4.149 +    |   INT
   4.150 +    |	s='*' -> STRING_LITERAL[$s]  // used for k=*
   4.151 +    ;
   4.152 +
   4.153 +rule
   4.154 +scope {
   4.155 +	String name;
   4.156 +}
   4.157 +	:	DOC_COMMENT?
   4.158 +		( modifier=('protected'|'public'|'private'|'fragment') )?
   4.159 +		id {$rule::name = $id.text;}
   4.160 +		'!'?
   4.161 +		( arg=ARG_ACTION )?
   4.162 +		( 'returns' rt=ARG_ACTION  )?
   4.163 +		throwsSpec? optionsSpec? ruleScopeSpec? ruleAction*
   4.164 +		':'	altList	';'
   4.165 +		exceptionGroup?
   4.166 +	    -> ^( RULE id {modifier!=null?adaptor.create(modifier):null} ^(ARG $arg)? ^(RET $rt)?
   4.167 +	    	  optionsSpec? ruleScopeSpec? ruleAction*
   4.168 +	    	  altList
   4.169 +	    	  exceptionGroup?
   4.170 +	    	  EOR["EOR"]
   4.171 +	    	)
   4.172 +	;
   4.173 +
   4.174 +/** Match stuff like @init {int i;} */
   4.175 +ruleAction
   4.176 +	:	'@' id ACTION -> ^('@' id ACTION)
   4.177 +	;
   4.178 +
   4.179 +throwsSpec
   4.180 +	:	'throws' id ( ',' id )* -> ^('throws' id+)
   4.181 +	;
   4.182 +
   4.183 +ruleScopeSpec
   4.184 +	:	'scope' ACTION -> ^('scope' ACTION)
   4.185 +	|	'scope' id (',' id)* ';' -> ^('scope' id+)
   4.186 +	|	'scope' ACTION
   4.187 +		'scope' id (',' id)* ';'
   4.188 +		-> ^('scope' ACTION id+ )
   4.189 +	;
   4.190 +
   4.191 +block
   4.192 +    :   lp='('
   4.193 +		( (opts=optionsSpec)? ':' )?
   4.194 +		a1=alternative rewrite ( '|' a2=alternative rewrite )*
   4.195 +        rp=')'
   4.196 +        -> ^( BLOCK[$lp,"BLOCK"] optionsSpec? (alternative rewrite?)+ EOB[$rp,"EOB"] )
   4.197 +    ;
   4.198 +
   4.199 +altList
   4.200 +@init {
   4.201 +	// must create root manually as it's used by invoked rules in real antlr tool.
   4.202 +	// leave here to demonstrate use of {...} in rewrite rule
   4.203 +	// it's really BLOCK[firstToken,"BLOCK"]; set line/col to previous ( or : token.
   4.204 +    CommonTree blkRoot = (CommonTree)adaptor.create(BLOCK,input.LT(-1),"BLOCK");
   4.205 +}
   4.206 +    :   a1=alternative rewrite ( '|' a2=alternative rewrite )*
   4.207 +		-> ^( {blkRoot} (alternative rewrite?)+ EOB["EOB"] )
   4.208 +    ;
   4.209 +
   4.210 +alternative
   4.211 +@init {
   4.212 +	Token firstToken = input.LT(1);
   4.213 +	Token prevToken = input.LT(-1); // either : or | I think
   4.214 +}
   4.215 +    :   element+ -> ^(ALT[firstToken,"ALT"] element+ EOA["EOA"])
   4.216 +    |   -> ^(ALT[prevToken,"ALT"] EPSILON[prevToken,"EPSILON"] EOA["EOA"])
   4.217 +    ;
   4.218 +
   4.219 +exceptionGroup
   4.220 +	:	( exceptionHandler )+ ( finallyClause )?
   4.221 +	|	finallyClause
   4.222 +    ;
   4.223 +
   4.224 +exceptionHandler
   4.225 +    :    'catch' ARG_ACTION ACTION -> ^('catch' ARG_ACTION ACTION)
   4.226 +    ;
   4.227 +
   4.228 +finallyClause
   4.229 +    :    'finally' ACTION -> ^('finally' ACTION)
   4.230 +    ;
   4.231 +
   4.232 +element
   4.233 +	:	elementNoOptionSpec
   4.234 +	;
   4.235 +
   4.236 +elementNoOptionSpec
   4.237 +	:	id (labelOp='='|labelOp='+=') atom
   4.238 +		(	ebnfSuffix	-> ^( ebnfSuffix ^(BLOCK["BLOCK"] ^(ALT["ALT"] ^($labelOp id atom) EOA["EOA"]) EOB["EOB"]))
   4.239 +		|				-> ^($labelOp id atom)
   4.240 +		)
   4.241 +	|	id (labelOp='='|labelOp='+=') block
   4.242 +		(	ebnfSuffix	-> ^( ebnfSuffix ^(BLOCK["BLOCK"] ^(ALT["ALT"] ^($labelOp id block) EOA["EOA"]) EOB["EOB"]))
   4.243 +		|				-> ^($labelOp id block)
   4.244 +		)
   4.245 +	|	atom
   4.246 +		(	ebnfSuffix	-> ^( ebnfSuffix ^(BLOCK["BLOCK"] ^(ALT["ALT"] atom EOA["EOA"]) EOB["EOB"]) )
   4.247 +		|				-> atom
   4.248 +		)
   4.249 +	|	ebnf
   4.250 +	|   ACTION
   4.251 +	|   SEMPRED ( '=>' -> GATED_SEMPRED | -> SEMPRED )
   4.252 +	|   treeSpec
   4.253 +		(	ebnfSuffix	-> ^( ebnfSuffix ^(BLOCK["BLOCK"] ^(ALT["ALT"] treeSpec EOA["EOA"]) EOB["EOB"]) )
   4.254 +		|				-> treeSpec
   4.255 +		)
   4.256 +	;
   4.257 +
   4.258 +atom:   range ( (op='^'|op='!') -> ^($op range) | -> range )
   4.259 +    |   terminal
   4.260 +    |	notSet ( (op='^'|op='!') -> ^($op notSet) | -> notSet )
   4.261 +    |   RULE_REF ( arg=ARG_ACTION )? ( (op='^'|op='!') )?
   4.262 +    	-> {$arg!=null&&op!=null}?	^($op RULE_REF $arg)
   4.263 +    	-> {$arg!=null}?			^(RULE_REF $arg)
   4.264 +    	-> {$op!=null}?				^($op RULE_REF)
   4.265 +    	-> RULE_REF
   4.266 +    ;
   4.267 +
   4.268 +notSet
   4.269 +	:	'~'
   4.270 +		(	notTerminal	-> ^('~' notTerminal)
   4.271 +		|	block		-> ^('~' block)
   4.272 +		)
   4.273 +	;
   4.274 +
   4.275 +treeSpec
   4.276 +	:	'^(' element ( element )+ ')' -> ^(TREE_BEGIN element+)
   4.277 +	;
   4.278 +
   4.279 +/** Matches ENBF blocks (and token sets via block rule) */
   4.280 +ebnf
   4.281 +@init {
   4.282 +    Token firstToken = input.LT(1);
   4.283 +}
   4.284 +@after {
   4.285 +	$ebnf.tree.getToken().setLine(firstToken.getLine());
   4.286 +	$ebnf.tree.getToken().setCharPositionInLine(firstToken.getCharPositionInLine());
   4.287 +}
   4.288 +	:	block
   4.289 +		(	op='?'	-> ^(OPTIONAL[op] block)
   4.290 +		|	op='*'	-> ^(CLOSURE[op] block)
   4.291 +		|	op='+'	-> ^(POSITIVE_CLOSURE[op] block)
   4.292 +		|   '=>'	// syntactic predicate
   4.293 +					-> {gtype==COMBINED_GRAMMAR &&
   4.294 +					    Character.isUpperCase($rule::name.charAt(0))}?
   4.295 +					   // if lexer rule in combined, leave as pred for lexer
   4.296 +					   ^(SYNPRED["=>"] block)
   4.297 +					// in real antlr tool, text for SYN_SEMPRED is predname
   4.298 +					-> SYN_SEMPRED
   4.299 +        |			-> block
   4.300 +		)
   4.301 +	;
   4.302 +
   4.303 +range!
   4.304 +	:	c1=CHAR_LITERAL RANGE c2=CHAR_LITERAL -> ^(CHAR_RANGE[$c1,".."] $c1 $c2)
   4.305 +	;
   4.306 +
   4.307 +terminal
   4.308 +    :   (	CHAR_LITERAL				-> CHAR_LITERAL
   4.309 +    		// Args are only valid for lexer rules
   4.310 +		|   TOKEN_REF
   4.311 +			( ARG_ACTION				-> ^(TOKEN_REF ARG_ACTION)
   4.312 +			|							-> TOKEN_REF
   4.313 +			)
   4.314 +		|   STRING_LITERAL				-> STRING_LITERAL
   4.315 +		|   '.'							-> '.'
   4.316 +		)	
   4.317 +		(	'^'							-> ^('^' $terminal)
   4.318 +		|	'!' 						-> ^('!' $terminal)
   4.319 +		)?
   4.320 +	;
   4.321 +
   4.322 +notTerminal
   4.323 +	:   CHAR_LITERAL
   4.324 +	|	TOKEN_REF
   4.325 +	|	STRING_LITERAL
   4.326 +	;
   4.327 +	
   4.328 +ebnfSuffix
   4.329 +@init {
   4.330 +	Token op = input.LT(1);
   4.331 +}
   4.332 +	:	'?'	-> OPTIONAL[op]
   4.333 +  	|	'*' -> CLOSURE[op]
   4.334 +   	|	'+' -> POSITIVE_CLOSURE[op]
   4.335 +	;
   4.336 +	
   4.337 +
   4.338 +
   4.339 +// R E W R I T E  S Y N T A X
   4.340 +
   4.341 +rewrite
   4.342 +@init {
   4.343 +	Token firstToken = input.LT(1);
   4.344 +}
   4.345 +	:	(rew+='->' preds+=SEMPRED predicated+=rewrite_alternative)*
   4.346 +		rew2='->' last=rewrite_alternative
   4.347 +        -> ^($rew $preds $predicated)* ^($rew2 $last)
   4.348 +	|
   4.349 +	;
   4.350 +
   4.351 +rewrite_alternative
   4.352 +options {backtrack=true;}
   4.353 +	:	rewrite_template
   4.354 +	|	rewrite_tree_alternative
   4.355 +   	|   /* empty rewrite */ -> ^(ALT["ALT"] EPSILON["EPSILON"] EOA["EOA"])
   4.356 +	;
   4.357 +	
   4.358 +rewrite_tree_block
   4.359 +    :   lp='(' rewrite_tree_alternative ')'
   4.360 +    	-> ^(BLOCK[$lp,"BLOCK"] rewrite_tree_alternative EOB[$lp,"EOB"])
   4.361 +    ;
   4.362 +
   4.363 +rewrite_tree_alternative
   4.364 +    :	rewrite_tree_element+ -> ^(ALT["ALT"] rewrite_tree_element+ EOA["EOA"])
   4.365 +    ;
   4.366 +
   4.367 +rewrite_tree_element
   4.368 +	:	rewrite_tree_atom
   4.369 +	|	rewrite_tree_atom ebnfSuffix
   4.370 +		-> ^( ebnfSuffix ^(BLOCK["BLOCK"] ^(ALT["ALT"] rewrite_tree_atom EOA["EOA"]) EOB["EOB"]))
   4.371 +	|   rewrite_tree
   4.372 +		(	ebnfSuffix
   4.373 +			-> ^(ebnfSuffix ^(BLOCK["BLOCK"] ^(ALT["ALT"] rewrite_tree EOA["EOA"]) EOB["EOB"]))
   4.374 +		|	-> rewrite_tree
   4.375 +		)
   4.376 +	|   rewrite_tree_ebnf
   4.377 +	;
   4.378 +
   4.379 +rewrite_tree_atom
   4.380 +    :   CHAR_LITERAL
   4.381 +	|   TOKEN_REF ARG_ACTION? -> ^(TOKEN_REF ARG_ACTION?) // for imaginary nodes
   4.382 +    |   RULE_REF
   4.383 +	|   STRING_LITERAL
   4.384 +	|   d='$' id -> LABEL[$d,$id.text] // reference to a label in a rewrite rule
   4.385 +	|	ACTION
   4.386 +	;
   4.387 +
   4.388 +rewrite_tree_ebnf
   4.389 +@init {
   4.390 +    Token firstToken = input.LT(1);
   4.391 +}
   4.392 +@after {
   4.393 +	$rewrite_tree_ebnf.tree.getToken().setLine(firstToken.getLine());
   4.394 +	$rewrite_tree_ebnf.tree.getToken().setCharPositionInLine(firstToken.getCharPositionInLine());
   4.395 +}
   4.396 +	:	rewrite_tree_block ebnfSuffix -> ^(ebnfSuffix rewrite_tree_block)
   4.397 +	;
   4.398 +	
   4.399 +rewrite_tree
   4.400 +	:	'^(' rewrite_tree_atom rewrite_tree_element* ')'
   4.401 +		-> ^(TREE_BEGIN rewrite_tree_atom rewrite_tree_element* )
   4.402 +	;
   4.403 +
   4.404 +/** Build a tree for a template rewrite:
   4.405 +      ^(TEMPLATE (ID|ACTION) ^(ARGLIST ^(ARG ID ACTION) ...) )
   4.406 +    where ARGLIST is always there even if no args exist.
   4.407 +    ID can be "template" keyword.  If first child is ACTION then it's
   4.408 +    an indirect template ref
   4.409 +
   4.410 +    -> foo(a={...}, b={...})
   4.411 +    -> ({string-e})(a={...}, b={...})  // e evaluates to template name
   4.412 +    -> {%{$ID.text}} // create literal template from string (done in ActionTranslator)
   4.413 +	-> {st-expr} // st-expr evaluates to ST
   4.414 + */
   4.415 +rewrite_template
   4.416 +	:   // -> template(a={...},...) "..."    inline template
   4.417 +		id lp='(' rewrite_template_args	')'
   4.418 +		( str=DOUBLE_QUOTE_STRING_LITERAL | str=DOUBLE_ANGLE_STRING_LITERAL )
   4.419 +		-> ^(TEMPLATE[$lp,"TEMPLATE"] id rewrite_template_args $str)
   4.420 +
   4.421 +	|	// -> foo(a={...}, ...)
   4.422 +		rewrite_template_ref
   4.423 +
   4.424 +	|	// -> ({expr})(a={...}, ...)
   4.425 +		rewrite_indirect_template_head
   4.426 +
   4.427 +	|	// -> {...}
   4.428 +		ACTION
   4.429 +	;
   4.430 +
   4.431 +/** -> foo(a={...}, ...) */
   4.432 +rewrite_template_ref
   4.433 +	:	id lp='(' rewrite_template_args	')'
   4.434 +		-> ^(TEMPLATE[$lp,"TEMPLATE"] id rewrite_template_args)
   4.435 +	;
   4.436 +
   4.437 +/** -> ({expr})(a={...}, ...) */
   4.438 +rewrite_indirect_template_head
   4.439 +	:	lp='(' ACTION ')' '(' rewrite_template_args ')'
   4.440 +		-> ^(TEMPLATE[$lp,"TEMPLATE"] ACTION rewrite_template_args)
   4.441 +	;
   4.442 +
   4.443 +rewrite_template_args
   4.444 +	:	rewrite_template_arg (',' rewrite_template_arg)*
   4.445 +		-> ^(ARGLIST rewrite_template_arg+)
   4.446 +	|	-> ARGLIST
   4.447 +	;
   4.448 +
   4.449 +rewrite_template_arg
   4.450 +	:   id '=' ACTION -> ^(ARG[$id.start] id ACTION)
   4.451 +	;
   4.452 +
   4.453 +id	:	TOKEN_REF -> ID[$TOKEN_REF]
   4.454 +	|	RULE_REF  -> ID[$RULE_REF]
   4.455 +	;
   4.456 +
   4.457 +// L E X I C A L   R U L E S
   4.458 +
   4.459 +SL_COMMENT
   4.460 + 	:	'//'
   4.461 + 	 	(	' $ANTLR ' SRC // src directive
   4.462 + 		|	~('\r'|'\n')*
   4.463 +		)
   4.464 +		'\r'? '\n'
   4.465 +		{$channel=HIDDEN;}
   4.466 +	;
   4.467 +
   4.468 +ML_COMMENT
   4.469 +	:	'/*' {if (input.LA(1)=='*') $type=DOC_COMMENT; else $channel=HIDDEN;} .* '*/'
   4.470 +	;
   4.471 +
   4.472 +CHAR_LITERAL
   4.473 +	:	'\'' LITERAL_CHAR '\''
   4.474 +	;
   4.475 +
   4.476 +STRING_LITERAL
   4.477 +	:	'\'' LITERAL_CHAR LITERAL_CHAR* '\''
   4.478 +	;
   4.479 +
   4.480 +fragment
   4.481 +LITERAL_CHAR
   4.482 +	:	ESC
   4.483 +	|	~('\''|'\\')
   4.484 +	;
   4.485 +
   4.486 +DOUBLE_QUOTE_STRING_LITERAL
   4.487 +	:	'"' (ESC | ~('\\'|'"'))* '"'
   4.488 +	;
   4.489 +
   4.490 +DOUBLE_ANGLE_STRING_LITERAL
   4.491 +	:	'<<' .* '>>'
   4.492 +	;
   4.493 +
   4.494 +fragment
   4.495 +ESC	:	'\\'
   4.496 +		(	'n'
   4.497 +		|	'r'
   4.498 +		|	't'
   4.499 +		|	'b'
   4.500 +		|	'f'
   4.501 +		|	'"'
   4.502 +		|	'\''
   4.503 +		|	'\\'
   4.504 +		|	'>'
   4.505 +		|	'u' XDIGIT XDIGIT XDIGIT XDIGIT
   4.506 +		|	. // unknown, leave as it is
   4.507 +		)
   4.508 +	;
   4.509 +
   4.510 +fragment
   4.511 +XDIGIT :
   4.512 +		'0' .. '9'
   4.513 +	|	'a' .. 'f'
   4.514 +	|	'A' .. 'F'
   4.515 +	;
   4.516 +
   4.517 +INT	:	'0'..'9'+
   4.518 +	;
   4.519 +
   4.520 +ARG_ACTION
   4.521 +	:	NESTED_ARG_ACTION
   4.522 +	;
   4.523 +
   4.524 +fragment
   4.525 +NESTED_ARG_ACTION :
   4.526 +	'['
   4.527 +	(	options {greedy=false; k=1;}
   4.528 +	:	NESTED_ARG_ACTION
   4.529 +	|	ACTION_STRING_LITERAL
   4.530 +	|	ACTION_CHAR_LITERAL
   4.531 +	|	.
   4.532 +	)*
   4.533 +	']'
   4.534 +	{setText(getText().substring(1, getText().length()-1));}
   4.535 +	;
   4.536 +
   4.537 +ACTION
   4.538 +	:	NESTED_ACTION ( '?' {$type = SEMPRED;} )?
   4.539 +	;
   4.540 +
   4.541 +fragment
   4.542 +NESTED_ACTION :
   4.543 +	'{'
   4.544 +	(	options {greedy=false; k=2;}
   4.545 +	:	NESTED_ACTION
   4.546 +	|	SL_COMMENT
   4.547 +	|	ML_COMMENT
   4.548 +	|	ACTION_STRING_LITERAL
   4.549 +	|	ACTION_CHAR_LITERAL
   4.550 +	|	.
   4.551 +	)*
   4.552 +	'}'
   4.553 +   ;
   4.554 +
   4.555 +fragment
   4.556 +ACTION_CHAR_LITERAL
   4.557 +	:	'\'' (ACTION_ESC|~('\\'|'\'')) '\''
   4.558 +	;
   4.559 +
   4.560 +fragment
   4.561 +ACTION_STRING_LITERAL
   4.562 +	:	'"' (ACTION_ESC|~('\\'|'"'))* '"'
   4.563 +	;
   4.564 +
   4.565 +fragment
   4.566 +ACTION_ESC
   4.567 +	:	'\\\''
   4.568 +	|	'\\' '"' // ANTLR doesn't like: '\\"'
   4.569 +	|	'\\' ~('\''|'"')
   4.570 +	;
   4.571 +
   4.572 +TOKEN_REF
   4.573 +	:	'A'..'Z' ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
   4.574 +	;
   4.575 +
   4.576 +RULE_REF
   4.577 +	:	'a'..'z' ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
   4.578 +	;
   4.579 +
   4.580 +/** Match the start of an options section.  Don't allow normal
   4.581 + *  action processing on the {...} as it's not a action.
   4.582 + */
   4.583 +OPTIONS
   4.584 +	:	'options' WS_LOOP '{'
   4.585 +	;
   4.586 +	
   4.587 +TOKENS
   4.588 +	:	'tokens' WS_LOOP '{'
   4.589 +	;
   4.590 +
   4.591 +/** Reset the file and line information; useful when the grammar
   4.592 + *  has been generated so that errors are shown relative to the
   4.593 + *  original file like the old C preprocessor used to do.
   4.594 + */
   4.595 +fragment
   4.596 +SRC	:	'src' ' ' file=ACTION_STRING_LITERAL ' ' line=INT
   4.597 +	;
   4.598 +
   4.599 +WS	:	(	' '
   4.600 +		|	'\t'
   4.601 +		|	'\r'? '\n'
   4.602 +		)+
   4.603 +		{$channel=HIDDEN;}
   4.604 +	;
   4.605 +
   4.606 +fragment
   4.607 +WS_LOOP
   4.608 +	:	(	WS
   4.609 +		|	SL_COMMENT
   4.610 +		|	ML_COMMENT
   4.611 +		)*
   4.612 +	;
   4.613 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/o.n.antlr.editor/test/unit/src/org/netbeans/modules/antlr/editor/NbAntlrLexerTest.java	Sat Jan 12 08:46:08 2013 +0100
     5.3 @@ -0,0 +1,85 @@
     5.4 +/*
     5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 + *
     5.7 + * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
     5.8 + *
     5.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    5.10 + * Other names may be trademarks of their respective owners.
    5.11 + *
    5.12 + * The contents of this file are subject to the terms of either the GNU
    5.13 + * General Public License Version 2 only ("GPL") or the Common
    5.14 + * Development and Distribution License("CDDL") (collectively, the
    5.15 + * "License"). You may not use this file except in compliance with the
    5.16 + * License. You can obtain a copy of the License at
    5.17 + * http://www.netbeans.org/cddl-gplv2.html
    5.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.19 + * specific language governing permissions and limitations under the
    5.20 + * License.  When distributing the software, include this License Header
    5.21 + * Notice in each file and include the License file at
    5.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    5.23 + * particular file as subject to the "Classpath" exception as provided
    5.24 + * by Oracle in the GPL Version 2 section of the License file that
    5.25 + * accompanied this code. If applicable, add the following below the
    5.26 + * License Header, with the fields enclosed by brackets [] replaced by
    5.27 + * your own identifying information:
    5.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    5.29 + *
    5.30 + * If you wish your version of this file to be governed by only the CDDL
    5.31 + * or only the GPL Version 2, indicate your decision by adding
    5.32 + * "[Contributor] elects to include this software in this distribution
    5.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    5.34 + * single choice of license, a recipient has the option to distribute
    5.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    5.36 + * to extend the choice of license to its licensees as provided above.
    5.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    5.38 + * Version 2 license, then the option applies only if the new code is
    5.39 + * made subject to such option by the copyright holder.
    5.40 + *
    5.41 + * Contributor(s):
    5.42 + *
    5.43 + * Portions Copyrighted 2013 Sun Microsystems, Inc.
    5.44 + */
    5.45 +package org.netbeans.modules.antlr.editor;
    5.46 +
    5.47 +import static junit.framework.Assert.assertEquals;
    5.48 +import static junit.framework.Assert.assertFalse;
    5.49 +import static junit.framework.Assert.assertTrue;
    5.50 +import junit.framework.TestCase;
    5.51 +import org.netbeans.api.lexer.TokenHierarchy;
    5.52 +import org.netbeans.api.lexer.TokenSequence;
    5.53 +
    5.54 +/**
    5.55 + *
    5.56 + * @author marekfukala
    5.57 + */
    5.58 +public class NbAntlrLexerTest extends TestCase {
    5.59 +    
    5.60 +    public NbAntlrLexerTest(String testName) {
    5.61 +        super(testName);
    5.62 +    }
    5.63 +
    5.64 +     public void test146930() {
    5.65 +//        TokenHierarchy th = TokenHierarchy.create("<<body>", HTMLTokenId.language());
    5.66 +//        TokenSequence ts = th.tokenSequence();
    5.67 +//        ts.moveStart();
    5.68 +//
    5.69 +//        assertTrue(ts.moveNext());
    5.70 +//        assertEquals("<", ts.token().text().toString());
    5.71 +//        assertEquals(HTMLTokenId.TEXT, ts.token().id());
    5.72 +//
    5.73 +//        assertTrue(ts.moveNext());
    5.74 +//        assertEquals("<", ts.token().text().toString());
    5.75 +//        assertEquals(HTMLTokenId.TAG_OPEN_SYMBOL, ts.token().id());
    5.76 +//
    5.77 +//        assertTrue(ts.moveNext());
    5.78 +//        assertEquals("body", ts.token().text().toString());
    5.79 +//        assertEquals(HTMLTokenId.TAG_OPEN, ts.token().id());
    5.80 +//
    5.81 +//        assertTrue(ts.moveNext());
    5.82 +//        assertEquals(">", ts.token().text().toString());
    5.83 +//        assertEquals(HTMLTokenId.TAG_CLOSE_SYMBOL, ts.token().id());
    5.84 +//
    5.85 +//        assertFalse(ts.moveNext());
    5.86 +    }
    5.87 +    
    5.88 +}