📄 sather.g
字号:
closure_expression : expression | UNDERSCORE ;except_expression : "exception" ;initial_expression : "initial" LPAREN! expression RPAREN! ;result_expression : "result" ;self_expression : "self" ;while_expression : "while!" LPAREN! expression RPAREN! ;until_expression : "until!" LPAREN! expression RPAREN! ;break_expression : "break!" ;array_expression : BAR expression_list BAR ;bool_literal_expression : "true" | "false" ;parameter_declaration_list : parameter_declaration ( COMMA! parameter_declaration )* { @parameter_declaration_list := @([PARAMETER_DECLARATION_LIST, "PARAMETER_DECLARATION_LIST"], @parameter_declaration_list); } ;parameter_declaration : IDENTIFIER ( LESS_THAN type_specifier )? ;supertyping_clause : GREATER_THAN^ type_specifier_list ;subtyping_clause : LESS_THAN^ type_specifier_list ;abstract_signature_list : abstract_signature ( SEMICOLON! ( abstract_signature )? )* { @abstract_signature_list := @([ABSTRACT_SIGNATURE_LIST, "ABSTRACT_SIGNATURE_LIST"], @abstract_signature_list); } ;abstract_signature : abstract_routine_signature | abstract_iter_signature ;abstract_routine_signature : IDENTIFIER ( LPAREN routine_argument_list RPAREN )? ( COLON type_specifier )? ;abstract_iter_signature : ITER_NAME ( LPAREN iter_argument_list RPAREN )? ( COLON type_specifier )? ;routine_argument_list : routine_argument ( COMMA! routine_argument )* ;routine_argument : ( routine_mode )? IDENTIFIER ( COMMA! ( routine_mode )? IDENTIFIER )* COLON type_specifier ;iter_argument_list : iter_argument ( COMMA! iter_argument )* ;iter_argument : ( iter_mode )? IDENTIFIER ( COMMA! ( iter_mode )? IDENTIFIER )* COLON type_specifier ;non_identifier_type_specifier : ABSTRACT_CLASS_NAME ( LCURLY type_specifier_list RCURLY )? | method_closure_type_specifier | "SAME" ;type_specifier : IDENTIFIER ( LCURLY type_specifier_list RCURLY )? | non_identifier_type_specifier ;type_specifier_list : type_specifier ( COMMA! type_specifier )* { @type_specifier_list := @([TYPE_SPECIFIER_LIST,"TYPE_SPECIFIER_LIST"], @type_specifier_list); } ;method_closure_type_specifier : routine_closure_type_specifier | iter_closure_type_specifier ;routine_closure_type_specifier : "ROUT" ( LCURLY! routine_type_specifier_list RCURLY! )? ( COLON type_specifier )? ;iter_closure_type_specifier : "ITER" ( LCURLY! iter_type_specifier_list RCURLY! )? ( COLON type_specifier )? ;iter_type_specifier_list : iter_type_specifier ( COMMA! iter_type_specifier )* ;routine_type_specifier_list : routine_type_specifier ( COMMA! routine_type_specifier )* ;routine_type_specifier : ( routine_mode )? type_specifier ;iter_type_specifier : ( iter_mode )? type_specifier ;routine_mode : "in" | "out" | "inout" ;iter_mode : routine_mode | "once" ;identifier_list : IDENTIFIER ( COMMA! IDENTIFIER )* ;class SATHER_LEXER extends Lexer;options { exportVocab = SATHER; testLiterals = true; k=2;}// operators, etc.LCURLY : '{' ;RCURLY : '}' ;LPAREN : '(' ;RPAREN : ')' ;LSQUARE : '[' ;RSQUARE : ']' ;COMMA : ',' ;COLON : ':' ;SEMICOLON : ';' ;LESS_THAN : '<' ;GREATER_THAN : '>' ;EXCLAMATION : '!' ;MINUS : '-' ;PLUS : '+' ;STAR : '*' ;SLASH : '/' ;EQUAL : '=' ;NOT : '~' ;DOT : '.' ;HASH : '#' ;BAR : '|' ;PERCENT : '%' ;CARET : '^' ;ASSIGN : ":=" ; RIGHT_ARROW : "->" ;NOT_EQUAL : "/=" ;LESS_THAN_EQUAL : "<=" ;GREATER_THAN_EQUAL : ">=" ;protected DBL_COLON : "::" ;protected DBL_COLON_ASSIGN : "::=" ;protected UNDERSCORE : '_' ;protected DOLLAR : '$' ;protectedIDENTIFIER : ( 'a'..'z' | 'A'..'Z' | '_' ) ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' )* ; // TODO: reject IDENTIFIERS without at least one letterprotectedITER_NAME : IDENTIFIER EXCLAMATION ; protectedBINARY_INT : "0b" ( '0' | '1' | '_' )* ;protectedOCTAL_INT : "0o" ( '0'..'9' | '_' )* ;protectedHEX_INT : "0x" ( '0'..'9' | 'a'..'f' | '_' )* ;protectedDECIMAL_INT : ( '0'..'9' ) ( '0'..'9' | '_' )* ;protectedINT_LITERAL : ( DECIMAL_INT | BINARY_INT | OCTAL_INT | HEX_INT ) ( 'i' )? ;protectedFLT_LITERAL : DECIMAL_INT DOT DECIMAL_INT ( 'e' ( MINUS )? DECIMAL_INT )? ( 'd' )? ; COLON_OR_ASSIGN : "::" { %setType(DBL_COLON); } ( '=' { %setType(DBL_COLON_ASSIGN); } )? ;NUM_LITERAL : ( DECIMAL_INT DOT DECIMAL_INT )=> FLT_LITERAL { %setType(FLT_LITERAL); } | DECIMAL_INT ( 'i' )? { %setType(INT_LITERAL); } | ( ( BINARY_INT | OCTAL_INT | HEX_INT ) ( 'i' )? { %setType(INT_LITERAL); } ) ;ABSTRACT_CLASS_NAME : DOLLAR IDENTIFIER ;ITER_NAME_OR_IDENTIFIER_OR_UNDERSCORE : '_' { %setType(UNDERSCORE); } ( ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' )+ { %setType(IDENTIFIER); } ( EXCLAMATION { %setType(ITER_NAME); } )? )? | ( ( 'a'..'z' | 'A'..'Z' ) ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' )* { %setType(IDENTIFIER); } ( EXCLAMATION { %setType(ITER_NAME); } )? ) ;// what follows is shamelessly taken from java.g: thanks guys!// character literalsCHAR_LITERAL : '\'' ( ESC | ~'\'' ) '\'' ;// string literalsSTRING_LITERAL : '"' (ESC|~('"'|'\\'))* '"' ;// escape sequence -- note that this is protected; it can only be called// from another lexer rule -- it will not ever directly return a token to// the parser// There are various ambiguities hushed in this rule. The optional// '0'...'9' digit matches should be matched here rather than letting// them go back to STRING_LITERAL to be matched. ANTLR does the// right thing by matching immediately; hence, it's ok to shut off// the FOLLOW ambig warnings.protectedESC : '\\' ( 'n' | 'r' | 't' | 'b' | 'f' | 'v' // Sather/Library/char.sa uses \v -- still needed? | 'a' | '"' | '\'' | '\\' | ('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT | ('0'..'3') ( options { warnWhenFollowAmbig = false; } : ('0'..'9') ( options { warnWhenFollowAmbig = false; } : '0'..'9' )? )? | ('4'..'7') ( options { warnWhenFollowAmbig = false; } : ('0'..'9') )? ) ;// hexadecimal digit (again, note it's protected!)protectedHEX_DIGIT : ('0'..'9'|'A'..'F'|'a'..'f') ;// a dummy rule to force vocabulary to be all characters (except special// ones that ANTLR uses internally (0 to 2)protectedVOCAB : '\3'..'\377' ;// Single-line commentsSL_COMMENT : "--" (~('\n'|'\r'))* ('\n'|'\r'('\n')?) { %setType(ANTLR_COMMON_TOKEN::SKIP); newline; } ;// multiple-line commentsML_COMMENT : "(*" ( options { greedy=false; } : '\r' '\n' { newline; } | '\r' { newline; } | '\n' { newline; } | . )* "*)" { %setType(ANTLR_COMMON_TOKEN::SKIP); } ;// Whitespace -- ignoredWS : ( ' ' | '\t' | '\f' // handle newlines | ( "\r\n" // Evil DOS | '\r' // Macintosh | '\n' // Unix (the right way) ) { newline; } ) { %setType(ANTLR_COMMON_TOKEN::SKIP); } ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -