-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruby.lex
98 lines (77 loc) · 2.74 KB
/
ruby.lex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//%print-tokens
DIGIT [0-9]
INT -?[0-9]+
FLOAT -?[0-9]*\.[0-9]+
ID [a-zA-Z_][a-zA-Z0-9_]*
%%
"#".*\n {/* skip oneline */} // oneline comment
^"=begin"[\w\n][.\n]*[\w\n]"=end"$ {/* skip multiline */} // multiline comment
"alias" { return(Parser::ALIAS); }
"break" { return(Parser::BREAK); }
"case" { return(Parser::CASE); }
"def" { return(Parser::DEF); }
"defined?" { return(Parser::DEFINED); }
"else" { return(Parser::ELSE); }
"elsif" { return(Parser::ELSIF); }
"end" { return(Parser::END); }
"false" { return(Parser::FALSE); }
"if" { return(Parser::IF); }
"nil" { return(Parser::NIL); }
"retry" { return(Parser::RETRY); }
"return" { return(Parser::RETURN); }
"require" { return(Parser::REQUIRE); }
"then" { return(Parser::THEN); }
"true" { return(Parser::TRUE); }
"undef" { return(Parser::UNDEF); }
"unless" { return(Parser::UNLESS); }
"when" { return(Parser::WHEN); }
"while" { return(Parser::WHILE); }
"+" { return(Parser::PLUS); }
"-" { return(Parser::MINUS); }
"*" { return(Parser::MUL); }
"/" { return(Parser::DIV); }
"%" { return(Parser::MOD); }
"**" { return(Parser::EXP); }
"==" { return(Parser::EQUAL); }
"!=" { return(Parser::NOT_EQUAL); }
">" { return(Parser::GREATER); }
"<" { return(Parser::LESS); }
"<=" { return(Parser::LESS_EQUAL); }
">=" { return(Parser::GREATER_EQUAL); }
"=" { return(Parser::ASSIGN); }
"+=" { return(Parser::PLUS_ASSIGN); }
"-=" { return(Parser::MINUS_ASSIGN); }
"*=" { return(Parser::MUL_ASSIGN); }
"/=" { return(Parser::DIV_ASSIGN); }
"%=" { return(Parser::MOD_ASSIGN); }
"**=" { return(Parser::EXP_ASSIGN); }
"&" { return(Parser::BIT_AND); }
"|" { return(Parser::BIT_OR); }
"^" { return(Parser::BIT_XOR); }
"~" { return(Parser::BIT_NOT); }
"<<" { return(Parser::BIT_SHL); }
">>" { return(Parser::BIT_SHR); }
"and" { return(Parser::AND); }
"or" { return(Parser::OR); }
"not" { return(Parser::NOT); }
"&&" { return(Parser::AND); }
"||" { return(Parser::OR); }
"!" { return(Parser::NOT); }
"?" { return(Parser::TERNARY_THEN); }
":" { return(Parser::TERNARY_ELSE); }
"(" { return(Parser::LEFT_RBRACKET); }
")" { return(Parser::RIGHT_RBRACKET); }
"[" { return(Parser::LEFT_SBRACKET); }
"]" { return(Parser::RIGHT_SBRACKET); }
"," { return(Parser::COMMA); }
"$"{ID} { PushValue(matched()); return(Parser::ID_GLOBAL); }
";" { return(Parser::SEMICOLON); }
\"(\\.|[^\\"])*\" |
\'(\\.|[^\\'])*\' { PushValue(matched()); return(Parser::LITERAL); }
{ID}[!?] { PushValue(matched()); return(Parser::ID_FUNCTION); }
{ID} { PushValue(matched()); return(Parser::ID); }
{FLOAT} { PushValue(matched()); return(Parser::NUM_FLOAT); }
{INT} { PushValue(matched()); return(Parser::NUM_INTEGER); }
\n { return(Parser::CRLF); }
[ \t\n\r] { /* skip whitespace */ }
%%