Xtext语法文字的表达式=“ 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,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')))?;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...