Skip to content

Commit

Permalink
Property place holder support inside SPEL
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Sep 12, 2024
1 parent 30abaec commit fca3fc0
Show file tree
Hide file tree
Showing 24 changed files with 2,385 additions and 825 deletions.
1 change: 1 addition & 0 deletions headless-services/commons/jpql/generate-parsers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ java -jar ${workdir}/antlr-${ANTLR_VERSION}.jar MySqlLexer.g4 MySqlParser.g4 -o
java -jar ${workdir}/antlr-${ANTLR_VERSION}.jar SpelLexer.g4 SpelParser.g4 -o ${workdir}/src/main/java/org/springframework/ide/vscode/parser/spel -package org.springframework.ide.vscode.parser.spel
java -jar ${workdir}/antlr-${ANTLR_VERSION}.jar PostgreSqlLexer.g4 PostgreSqlParser.g4 -o ${workdir}/src/main/java/org/springframework/ide/vscode/parser/postgresql -package org.springframework.ide.vscode.parser.postgresql
java -jar ${workdir}/antlr-${ANTLR_VERSION}.jar CronLexer.g4 CronParser.g4 -o ${workdir}/src/main/java/org/springframework/ide/vscode/parser/cron -package org.springframework.ide.vscode.parser.cron
java -jar ${workdir}/antlr-${ANTLR_VERSION}.jar PropertyPlaceHolder.g4 -o ${workdir}/src/main/java/org/springframework/ide/vscode/parser/placeholder -package org.springframework.ide.vscode.parser.placeholder

74 changes: 74 additions & 0 deletions headless-services/commons/jpql/grammars/PropertyPlaceHolder.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*******************************************************************************/

/**
* Based on the answer to this Stack Overflow question:
* https://stackoverflow.com/questions/6132529/antlr-parsing-java-properties
*/

grammar PropertyPlaceHolder;

start
: line* EOF
;

line
: Space* keyDefaultValuePair Space* EOF
;

keyDefaultValuePair
: key
| key defaultValue
;

defaultValue
: Colon value
;

key
: identifier (Dot identifier)*
;

identifier
: Identifier+
;

value
: (Identifier | Exclamation | Number | Space | Backslash Backslash | Backslash LineBreak | Equals | Colon | Dot)*
;

Backslash : '\\';
Colon : ':';
Equals : '=';
Exclamation: '!';
Number : '#';
Dot : '.';

LineBreak
: '\r'? '\n'
| '\r'
;

Space
: ' '
| '\t'
| '\f'
| LineBreak
;

Identifier
: IdentifierChar+
;

fragment IdentifierChar
: ~(' ' | ':' | '=' | '\r' | '\n' | '.')
| Backslash (Colon | Equals)
;
6 changes: 5 additions & 1 deletion headless-services/commons/jpql/grammars/SpelLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ DOUBLE_QUOTED_STRING
: '"' ( '""' | ~["\n] )* '"'
;
PROPERTY_PLACE_HOLDER
: '${' (.)*? '}'
;
fragment INTEGER_TYPE_SUFFIX : ( 'L' | 'l' );
fragment HEX_DIGIT : [0-9A-Fa-f];
fragment DECIMAL_DIGIT: [0-9];
Expand Down Expand Up @@ -184,4 +188,4 @@ TEMPLATE_TEXT
BACKTICK_IN_TEMPLATE
: '`' -> type(BACKTICK), popMode
;
;
6 changes: 6 additions & 0 deletions headless-services/commons/jpql/grammars/SpelParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ node
nonDottedNode
: (LSQUARE spelExpr RSQUARE)
| inputParameter
| propertyPlaceHolder
;

dottedNode
Expand Down Expand Up @@ -107,6 +108,7 @@ startNode
| selection
| inlineListOrMap
| inputParameter
| propertyPlaceHolder
;


Expand Down Expand Up @@ -178,3 +180,7 @@ inputParameter
: (LSQUARE INTEGER_LITERAL RSQUARE)
;

propertyPlaceHolder
: PROPERTY_PLACE_HOLDER
;

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Generated from PropertyPlaceHolder.g4 by ANTLR 4.13.1
package org.springframework.ide.vscode.parser.placeholder;

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;

/**
* This class provides an empty implementation of {@link PropertyPlaceHolderListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
@SuppressWarnings("CheckReturnValue")
public class PropertyPlaceHolderBaseListener implements PropertyPlaceHolderListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterStart(PropertyPlaceHolderParser.StartContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitStart(PropertyPlaceHolderParser.StartContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterLine(PropertyPlaceHolderParser.LineContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitLine(PropertyPlaceHolderParser.LineContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterKeyDefaultValuePair(PropertyPlaceHolderParser.KeyDefaultValuePairContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitKeyDefaultValuePair(PropertyPlaceHolderParser.KeyDefaultValuePairContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDefaultValue(PropertyPlaceHolderParser.DefaultValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDefaultValue(PropertyPlaceHolderParser.DefaultValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterKey(PropertyPlaceHolderParser.KeyContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitKey(PropertyPlaceHolderParser.KeyContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterIdentifier(PropertyPlaceHolderParser.IdentifierContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitIdentifier(PropertyPlaceHolderParser.IdentifierContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterValue(PropertyPlaceHolderParser.ValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitValue(PropertyPlaceHolderParser.ValueContext ctx) { }

/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}
Loading

0 comments on commit fca3fc0

Please sign in to comment.