Skip to content

Commit

Permalink
Add comments descibing what annotations are in parser and AST files
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm committed Sep 27, 2024
1 parent 6585188 commit fea5e16
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,29 @@
import java.util.ArrayList;
import java.util.List;

/** Abstract Syntax Tree parser object for "annotation" token */
/**
* Abstract Syntax Tree parser object for "annotation" token
*
* <p>Column Annotations are NOT a feature of Cloud Spanner.
*
* <p>This is an additional feature of the Cloud Spanner Schema parser exclusively in this tool so
* that users of this tool can add metadata to colums, and have that metadata represented in the
* parsed schema.
*
* <p>To use Annotations, they should be added to a CREATE TABLE statement as follows:
*
* <pre>
* CREATE TABLE Albums (
* -- @ANNOTATION SOMETEXT,
* id STRING(36),
* ) PRIMARY KEY (id)
* </pre>
*
* Annotations need to be on their own line, and terminate with a comma. (This is because the '-- '
* prefix is removed before using the JJT parser).
*
* <p>As they are comments, they are ignored by the diff generator and by Spanner itself.
*/
public class ASTannotation extends SimpleNode {
public ASTannotation(int id) {
super(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions src/main/jjtree-sources/DdlParser.head
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cat src/main/jjtree-sources/DdlParser.head \
src/main/jjtree-sources/ddl_keywords.jjt \
src/main/jjtree-sources/ddl_string_bytes_tokens.jjt \
src/main/jjtree-sources/ddl_expression.jjt \
src/main/jjtree-sources/ddl_annotation.jjt \
src/main/jjtree-sources/ddl_parser.jjt \
> src/main/jjtree/DdlParser.jjt

Expand Down
37 changes: 37 additions & 0 deletions src/main/jjtree-sources/ddl_annotation.jjt
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
//
// Copyright 2024 Google LLC
//
// Licensed 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.
//

// Column Annotations are NOT a feature of Cloud Spanner.
//
// This is an additional feature of the Cloud Spanner Schema parser exclusively
// in this tool so that users of this tool can add metadata to colums, and have
// that metadata represented in the parsed schema.
//
// To use Annotations, they should be added to a CREATE TABLE statement as
// follows:
//
// CREATE TABLE Albums (
// -- @ANNOTATION SOMETEXT,
// id STRING(36),
// ) PRIMARY KEY (id)
//
// Annotations need to be on their own line, and terminate with a comma.
// (This is because the '-- ' prefix is removed before using the JJT parser).
//
// As they are comments, they are ignored by the diff generator and by
// Spanner itself.
//

TOKEN:
{
<ANNOTATION: "@ANNOTATION">
Expand Down
4 changes: 4 additions & 0 deletions src/main/jjtree-sources/ddl_parser.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ void table_element() #void :
LOOKAHEAD(3) foreign_key()
| LOOKAHEAD(3) check_constraint()
| LOOKAHEAD(3) synonym_clause()

// Column annotations are not a Spanner feature.
// See file ddl_annotation.jjt for more details.
| column_annotation()

| column_def()
}

Expand Down

0 comments on commit fea5e16

Please sign in to comment.