forked from mehmetakifakkus/turkceprogramlamadili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hataAyikla.pegjs
92 lines (65 loc) · 1.79 KB
/
hataAyikla.pegjs
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
// Hata satiri ayiklayicisi
//
// Accepts expressions like
// Line 1, column 23: Expected ")", "*", "+", "-", or "/" but "p" found.
// ReferenceError: a is not defined
// ReferenceError: no is not defined
start
= errorLineExpected
/ referenceError
errorLineExpected
= 'Line ' line:Integer ',' _ 'column ' col:Integer ': Expected ' StringList _ 'or' _ String _ 'but' _ errorChar:String _ 'found.' {
return 'Satır '+line+ ', sıra '+col + ': Hatalı karakter: '+errorChar.value;
}
referenceError
= _ errorName:name _ 'is not defined' _
{
return 'Hey! \''+errorName + '\' maalesef tanımlı değil.'
}
///// Name = Variable
name = l:letter i:Integer {return l+i}
/ l:letter {return l;}
dogru = 'doğru' {return true;}
yanlis = 'yanlış' {return false;}
letter "letter"
= [a-zA-Z_|ş|ğ|ç|ö|ü|ı|ü]+ {return text()}
///// String
StringList = (String ', ')*
String "string"
= '"' chars:DoubleStringCharacter* '"' {
return { type: "Literal", value: chars.join("") };
}
DoubleStringCharacter
= !('"' / "\\" / LineTerminator) SourceCharacter { return text(); }
/ "\\" sequence:EscapeSequence { return sequence; }
/ LineContinuation
LineContinuation
= "\\" LineTerminatorSequence { return ""; }
LineTerminatorSequence "end of line"
= "\n"
/ "\r\n"
/ "\r"
/ "\u2028"
/ "\u2029"
LineTerminator
= [\n\r\u2028\u2029]
SourceCharacter
= .
EscapeSequence
= CharacterEscapeSequence
CharacterEscapeSequence
= SingleEscapeCharacter
SingleEscapeCharacter
= "'"
/ '"'
/ "\\"
/ "b" { return "\b"; }
/ "f" { return "\f"; }
/ "n" { return "\n"; }
/ "r" { return "\r"; }
/ "t" { return "\t"; }
/ "v" { return "\v"; }
Integer "integer"
= _ [0-9]+ { return parseInt(text(), 10); }
_ "whitespace"
= [ \t\n\r]*