首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >网络上的Dart和Antlr4 -不匹配输入

网络上的Dart和Antlr4 -不匹配输入
EN

Stack Overflow用户
提问于 2022-10-13 23:05:59
回答 1查看 52关注 0票数 0

哇,这是一个非常用词的查询,让我再试一次。

我还在学英语,试着理解语法。我使用的是语法(不是我写的--所以我尽量不调整它,因为它是许多组( 在这里发现的)使用的标准)。

我正在使用它在颤振应用程序中。当我在Linux或Android上运行它时,它没有问题地运行。当我尝试运行它没有网页,我立即有问题。我使用的全部语法如下。

代码语言:javascript
复制
grammar FhirPath;

// Grammar rules [FHIRPath](http://hl7.org/fhirpath/N1) Normative Release

//prog: line (line)*; line: ID ( '(' expr ')') ':' expr '\r'? '\n';
entireExpression: expression EOF;

expression:
    term                                                # termExpression
    | expression '.' invocation                         # invocationExpression
    | expression '[' expression ']'                     # indexerExpression
    | ('+' | '-') expression                            # polarityExpression
    | expression ('*' | '/' | 'div' | 'mod') expression # multiplicativeExpression
    | expression ('+' | '-' | '&') expression           # additiveExpression
    | expression '|' expression                         # unionExpression
    | expression ('<=' | '<' | '>' | '>=') expression   # inequalityExpression
    | expression ('is' | 'as') typeSpecifier            # typeExpression
    | expression ('=' | '~' | '!=' | '!~') expression   # equalityExpression
    | expression ('in' | 'contains') expression         # membershipExpression
    | expression 'and' expression                       # andExpression
    | expression ('or' | 'xor') expression              # orExpression
    | expression 'implies' expression                   # impliesExpression;
//| (IDENTIFIER)? '=>' expression                             #lambdaExpression

term:
    invocation              # invocationTerm
    | literal               # literalTerm
    | externalConstant      # externalConstantTerm
    | '(' expression ')'    # parenthesizedTerm;

literal:
    '{' '}'                 # nullLiteral
    | ('true' | 'false')    # booleanLiteral
    | STRING                # stringLiteral
    | NUMBER                # numberLiteral
    | DATE                  # dateLiteral
    | DATETIME              # dateTimeLiteral
    | TIME                  # timeLiteral
    | quantity              # quantityLiteral;

externalConstant: '%' ( identifier | STRING);

invocation: // Terms that can be used after the function/member invocation '.'
    identifier  # memberInvocation
    | function  # functionInvocation
    | '$this'   # thisInvocation
    | '$index'  # indexInvocation
    | '$total'  # totalInvocation;

function: identifier '(' paramList? ')';

paramList: expression (',' expression)*;

quantity: NUMBER unit?;

unit:
    pluralDateTimePrecision
    | dateTimePrecision
    | STRING; // UCUM syntax for units of measure

pluralDateTimePrecision:
    'years'
    | 'months'
    | 'weeks'
    | 'days'
    | 'hours'
    | 'minutes'
    | 'seconds'
    | 'milliseconds';

dateTimePrecision:
    'year'
    | 'month'
    | 'week'
    | 'day'
    | 'hour'
    | 'minute'
    | 'second'
    | 'millisecond';

typeSpecifier: qualifiedIdentifier;

qualifiedIdentifier: identifier ('.' identifier)*;

identifier:
    IDENTIFIER
    | DELIMITEDIDENTIFIER
    | 'as'
    | 'is'
    | 'contains'
    | 'in'
    | 'div';

/****************************************************************
 Lexical rules ***************************************************************
 */

/*
 NOTE: The goal of these rules in the grammar is to provide a date token to the parser. As such it
 is not attempting to validate that the date is a correct date, that task is for the parser or
 interpreter.
 */

DATE: '@' DATEFORMAT;

DATETIME:
    '@' DATEFORMAT 'T' (TIMEFORMAT TIMEZONEOFFSETFORMAT?)?;

TIME: '@' 'T' TIMEFORMAT;

fragment DATEFORMAT:
    [0-9][0-9][0-9][0-9] ('-' [0-9][0-9] ('-' [0-9][0-9])?)?;

fragment TIMEFORMAT:
    [0-9][0-9] (':' [0-9][0-9] (':' [0-9][0-9] ('.' [0-9]+)?)?)?;

fragment TIMEZONEOFFSETFORMAT: (
        'Z'
        | ('+' | '-') [0-9][0-9]':' [0-9][0-9]
    );

IDENTIFIER: ([A-Za-z] | '_') ([A-Za-z0-9] | '_')*;
// Added _ to support CQL (FHIR could constrain it out)

DELIMITEDIDENTIFIER: '`' (ESC | ~[\\`])* '`';

STRING: '\'' (ESC | ~['])* '\'';

// Also allows leading zeroes now (just like CQL and XSD)
NUMBER: [0-9]+ ('.' [0-9]+)?;

// Pipe whitespace to the HIDDEN channel to support retrieving source text through the parser.
WS: [ \r\n\t]+ -> channel(HIDDEN);

COMMENT: '/*' .*? '*/' -> channel(HIDDEN);

LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN);

fragment ESC:
    '\\' ([`'\\/fnrt] | UNICODE); // allow \`, \', \\, \/, \f, etc. and \uXXX

fragment UNICODE: 'u' HEX HEX HEX HEX;

fragment HEX: [0-9a-fA-F];

我用以下代码生成代码:

代码语言:javascript
复制
antlr4 -Dlanguage=Dart FhirPath.g4 -visitor -no-listener

然后,为了测试,我使用以下代码:

代码语言:javascript
复制
final input = InputStream.fromString('name');
final lexer = FhirPathLexer(input);
final tokens = CommonTokenStream(lexer);
final parser = FhirPathParser(tokens);
parser.buildParseTree = true;
final tree = parser.expression();

如果我在一个简单的省道脚本中运行它,它就会毫无问题地运行。但是,如果我将它放入一个颤振应用程序(同样,只在web上运行,否则它似乎没有问题),我就会得到以下错误:

代码语言:javascript
复制
line 1:0 mismatched input 'name' expecting {'as', 'in', 'is', 'contains', 'div', 'mod', IDENTIFIER, DELIMITEDIDENTIFIER}

我想我对语法有一些不理解的地方,所以任何见解都是值得赞赏的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-18 15:07:14

我的结论是,这是一个转到javascript的错误。antlr4版本适用于我对Android和Linux的所有测试,然后抛出大量的web错误。我回到了使用叶柄分析器而不是antlr4。如果其他人有建议的话,请随便留下,但现在,我要结束这个话题。如果您想比较这两个版本的外观,这里有两个版本:路径/库

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74062687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档