blob: 0882222bef4214503dfe4918d10f3b6ed21f9552 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// If you want to put an additional import, just add import statements like the following.
// import package name
import org.apache.asterix.lang.extension.EchoStatement;
// To remove an import, we use the keyword, unimport
// unimport package name
// If you want to add a method in the class definition (before PARSER_END), use the following phrase and attach
// new method right after the phrase.
// @new_at_the_end
@new_at_the_class_def
public void initScope() {
scopeStack.push(RootScopeFactory.createRootScope(this));
}
// Merging of non-terminals can only be done on non-terminals which conform to the following structure.
// Content will simply be prepended or appended to the base blocks.
// Note: refrain from using the strings "before:" and "after:" in the merge areas as that will break the merge.
// As a workaround, you can always override
// one additional possible change is direct replacement and it can be done through the followin syntax:
// @merge replace "base phrase" with "extension phrase" true/false
// Here, true/false tells whether the tool needs to process the three blocks.
// If true, like normal @merge case, before and after clause in each block will be processed
// after "base phrase" in the blocks have been replaced with "new phrase".
// If false, then it just expects the blank form that consists of three blocks and not process them.
// Only, "base phrase" in the blocks will be replaced with "new phrase".
@merge
Statement SingleStatement() throws ParseException:
{
// merge area 1
before:
after:
}
{
(
// merge area 2
before:
after: | stmt = EchoStatement())
{
// merge area 3
}
}
// In the following case, all instances of the first phrase inside of "" will be replaced with the second phrase in "".
// Also, we don't check "before:" and "after:" section of each area. That check will be ignored since
// the last parameter is set to false.
@merge replace "nameComponents = QualifiedName() (<AS> var = Variable())?" with "nameComponents = QualifiedName() (<AS> var = Variable())? " false
InsertStatement InsertStatement() throws ParseException:
{
// merge area 1
}
{
(
// merge area 2
)
{
// merge area 3
}
}
// The default
// Adding a new node. if a node exists, it will throw an exception.
@new
Statement EchoStatement() throws ParseException:
{
String arg = null;
}
{
<ECHO> arg = Identifier()
{
return new EchoStatement(arg);
}
}
// Overriding a non-terminal. if exists in base, it will be overriden, otherwise, it will be added
// @override
// Terminals can be added like the following.
<DEFAULT,IN_DBL_BRACE>
TOKEN :
{
<ECHO : "echo">
}
// If something needs to be added at the end of file, you can use @new_at_the_end like the following.
@new_at_the_end
<DEFAULT,IN_DBL_BRACE>
TOKEN :
{
<METAVARIABLE : "$$" <IDENTIFIER> >
}