Выражение грамматики Xtext для text = "text"
Мне нужно разобрать текст в следующем формате:
text = "text" text "text" ............
Какое правило терминала мне нужно написать, чтобы решить этот сценарий?
Ниже мой текстовый файл:
//grammar com.provar.eclipse.xtext.TestExpression with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations
grammar com.provar.eclipse.xtext.TestExpression with org.eclipse.xtext.common.Terminals
generate testExpression "http://www.provar.com/xtext/TestExpression"
//import 'http://www.eclipse.org/xtext/xbase/Xbase' as xbase
TestExpression:
(body+=TopLevelElement)*
;
TopLevelElement returns Expression:
FreeText | Expression
;
Literal returns Expression:
ValueLiteral
;
ValueLiteral returns Expression
: BooleanLiteral
| RealLiteral // must be placed before IntegerLiteral
| IntegerLiteral
| NullLiteral
| StringLiteral
;
BooleanLiteral returns Expression :
{BooleanLiteral} value = BooleanValue
;
IntegerLiteral returns Expression:
{IntegerLiteral} value= RadixIntValue
;
StringLiteral returns Expression:
{StringLiteral} value = STRING
;
RealLiteral returns Expression:
{RealLiteral} value = RealValue
;
// Note: NullLiteral has a java null value as its value
NullLiteral returns Expression:
{NullLiteral} "null"
;
//RegexpLiteral:
// pattern = REGULAR_EXPR
// ;
//
//SimplePatternLiteral:
// pattern = SIMPLE_PATTERN
// ;
// Has conversion rule
BooleanValue: ("true" | "false" );
// Has conversion rule
RealValue: REAL ;
// Has conversion rule that handles decimal, octal, and hexadecimal values but returns an Integer
IntValue: INT | HEX ;
// Has conversion rule that handles decimal, octal, and hexadecimal values with radix
RadixIntValue: INT | HEX ;
FreeText returns Expression:
{FreeText} value = FREE_TEXT;
ParanthesizedExpression returns Expression:
'(' Expression ')'
;
// All expressions except variable and value definitions
Expression returns Expression
: OrExpression
;
OrExpression returns Expression:
AndExpression ({BinaryOpExpression.leftExpr=current} functionName=("or" | "OR") rightExpr=AndExpression)*
;
AndExpression returns Expression :
RelationalExpression ({BinaryOpExpression.leftExpr=current} functionName=("and" | "AND") rightExpr=RelationalExpression)*
;
RelationalExpression returns Expression :
AdditiveExpression ({BinaryOpExpression.leftExpr=current}
functionName=RelationalOperator rightExpr=AdditiveExpression)*
;
AdditiveExpression returns Expression :
MultiplicativeExpression ({BinaryOpExpression.leftExpr=current} functionName=("+" | "-") rightExpr=MultiplicativeExpression)*
;
MultiplicativeExpression returns Expression :
ConcatenateExpression ({BinaryOpExpression.leftExpr=current} functionName=("*" | "/" | "%") rightExpr=ConcatenateExpression)*
;
ConcatenateExpression returns Expression :
CallExpression ({BinaryOpExpression.leftExpr=current} functionName=("&") rightExpr=CallExpression)*
;
CallExpression returns Expression:
PrimaryExpression ({FunctionCall.name = current} "(" (parameterList = ParameterList)? ")")*
;
PrimaryExpression returns Expression:
Literal
| ParanthesizedExpression
//| CallExpression
| ToplevelVariableAccess
;
ToplevelVariableAccess returns Expression:
"$" QualifiedVariableAccess {ToplevelVariableAccess.qualifiedVariableAccess=current}
| QualifiedVariableAccess
;
QualifiedVariableAccess returns Expression:
{QualifiedVariableAccess} paths += FilteredVariableAccess ("." paths += FilteredVariableAccess)*
//{QualifiedVariableAccess} paths += FilteredVariableAccess+
//FilteredVariableAccess ({QualifiedVariableAccess.parentVariable=current} '.' childVariable=FilteredVariableAccess)*
;
FilteredVariableAccess returns Expression:
SimpleVariableAccess ({FilteredVariableAccess.parentVariable=current} '[' filter=Expression ']')*
;
SimpleVariableAccess returns Expression:
{SimpleVariableAccess} name = VALID_ID
;
ParameterList returns Expression:
parameters += Parameter ("," parameters += Parameter)*
;
Parameter returns Expression:
expr = Expression
;
RelationalOperator
: "=" | "!=" | "<>"
| ">=" | "<=" | ">" | "<"
| "~" | "!~"
;
REAL hidden(): INT '.' (EXT_INT | INT); // INT ? '.' (EXT_INT | INT);
terminal EXT_INT: INT ('e'|'E')('-'|'+') INT;
terminal FREE_TEXT:
'}' ( '\\{' | !('{') )* ('{');
terminal VALID_ID:
('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal HEX:
('0x'|'0X') ('0'..'9'|'a'..'f'|'A'..'F'|'_')+
('#' (('b'|'B')('i'|'I') | ('l'|'L')))?;