-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexer.rex
40 lines (40 loc) · 1.27 KB
/
lexer.rex
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
require_relative "utils.rb"
class BlangLexer
macro
BLANK [\ \t]+
DEF ကြေညာချက်
CLASS အခန်း
STRING \A"([^"]*)"
NUMBER ([\u1040-\u1049]+)
MYANMAR ([\u1000-\u109F]+)
IF အကယ်၍
OPERATOR \A(\|\||&&|==|!=|<=|>=)
WHILE မဖြစ်မချင်း
END ပြီး
TRUE မှန်
TRUE_ENG true
FALSE_ENG false
FALSE မှား
NIL နတ္ထိ
rule
\r
{OPERATOR} { [text, text]}
{IF} { [:BIF, "if"]}
{TRUE} { [:BTRUE, "true"]}
{FALSE} { [:BFALSE, "false"]}
{TRUE_ENG} { [:BTRUE, "true"]}
{FALSE_ENG} { [:BFALSE, "false"]}
{STRING} { [:BSTRING, text.gsub('"', '')]}
{NIL} { [:BNIL, "nil"] }
{WHILE} { [:BWHILE,"while"]}
{NUMBER} { [:BNUMBER, text.myanmar_numbers_to_english.to_i]}
\d+ { [:BNUMBER, text.myanmar_numbers_to_english.to_i] }
\n { [:NEWLINE,:NEWLINE] }
{CLASS} {[:BCLASS,"class"]}
{BLANK}
{DEF}(\s+) { [:BDEF,"def"] }
{END} { [:BEND,"end"] }
[a-zA-Z]+ { [:BIDENTIFIER, text] }
{MYANMAR} { [:BIDENTIFIER, text] }
. { [text, text] }
end