VirtoolsTranslation/NlpParser/Nlp.g4

33 lines
981 B
Plaintext
Raw Permalink Normal View History

2023-06-28 22:56:18 +08:00
grammar Nlp;
2023-06-30 17:19:08 +08:00
// ===== Parser =====
2023-06-29 21:46:58 +08:00
document: LANG_HEADER (section)* ;
2023-06-28 22:56:18 +08:00
2023-06-29 21:46:58 +08:00
section: SECTION_HEAD (subSection | entry)* ;
2023-06-28 22:56:18 +08:00
2023-06-29 21:46:58 +08:00
subSection: SUB_SECTION_HEAD (entry)* ;
2023-06-28 22:56:18 +08:00
2023-06-29 21:46:58 +08:00
entry: ENTRY_STRING # entryString
2023-06-30 17:19:08 +08:00
| ENTRY_STRING (LINE_CONCATOR ENTRY_STRING)+ # entryConcatedString
2023-06-29 21:46:58 +08:00
| ENTRY_INTEGER # entryInteger
2023-06-28 22:56:18 +08:00
;
2023-06-30 17:19:08 +08:00
// ===== Lexer =====
2023-06-28 22:56:18 +08:00
LANG_HEADER: 'Language:' [a-zA-Z]+ ;
SECTION_HEAD: '[' NAME_SECTION ']' ;
SUB_SECTION_HEAD: '<' NAME_SECTION '>' ;
fragment NAME_SECTION: [ a-zA-Z0-9]+ ; // section name are consisted of space, char and number
2023-06-30 17:19:08 +08:00
ENTRY_STRING: '"' (ENTRY_STRING_ESC| ~'"' )* '"' ;
fragment ENTRY_STRING_ESC: '""' | '\\\\' | '\\t' | '\\n' ;
2023-06-28 22:56:18 +08:00
ENTRY_INTEGER: [1-9][0-9]+ ;
2023-06-30 17:19:08 +08:00
LINE_CONCATOR: '\\';
2023-06-28 22:56:18 +08:00
SPLITTOR: [ ,;\r\n]+ -> skip; // ignore all splittor and space
LINE_COMMENT: '//' ~[\r\n]* -> skip ; // consume all non-line-breaker. because we need line breaker.
BLOCK_COMMENT: '/*' .*? '*/' -> skip ;