-
Notifications
You must be signed in to change notification settings - Fork 15
/
NieczaFrontendSTD.pm6
136 lines (113 loc) · 3.51 KB
/
NieczaFrontendSTD.pm6
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class NieczaFrontendSTD;
use STD;
use Stash;
use NieczaGrammar;
use NieczaActions;
use MONKEY_TYPING;
augment class Match {
method CURSOR() { Q:CgOp { (ns (rawcall UnMatch (cast cursor (@ {self})))) } }
method cursor() { Q:CgOp { (ns (rawcall UnMatch (cast cursor (@ {self})))) } }
method reduced() { Q:CgOp { (box Str (rawcall Reduced (cast cursor (@ {self})))) } }
method trim_heredoc () { self } # NYI
}
augment class STD {
our $ALL;
method lineof ($p) {
return 1 unless defined $p;
my $line = @*LINEMEMOS[$p];
return $line if $line;
$line = 1; my $pos = 0;
my $lm = @*LINEMEMOS;
self.orig ~~ / :r [ \n { $lm[$pos++] = $line++ } ||
. { $lm[$pos++] = $line } ]* /;
$lm[$pos++] = $line;
return $lm[$p] // 0;
}
method lookup_dynvar($name) { Any } # NYI
method check_old_cclass($text) { } # NYI
method do_use($module,$args) {
self.do_need($module);
self.do_import($module,$args);
self;
}
method do_need($mo) {
my $module = $mo.Str;
my $topsym;
$topsym = self.sys_load_modinfo($module);
if !defined $topsym {
self.panic("Could not load $module");
}
self.add_my_name($module);
$*DECLARAND<really> = $topsym;
self;
}
method sys_load_modinfo($module) {
# These are handled within the grammar
if $module eq 'MONKEY_TYPING' || $module eq 'lib' ||
$module eq 'fatal' {
return { };
}
$*module_loader.($module).create_syml;
}
method load_lex($setting) {
if $setting eq 'NULL' {
my $id = "MY:file<NULL.pad>:line(1):pos(0)";
my $core = Stash.new('!id' => [$id], '!file' => 'NULL.pad',
'!line' => 1);
return Stash.new('CORE' => $core, 'MY:file<NULL.pad>' => $core,
'SETTING' => $core, $id => $core);
}
$*module_loader.($setting).create_syml;
}
}
augment class Cursor {
our $RED = "\e[31m";
our $GREEN = "\e[32m";
our $YELLOW = "\e[33m";
our $CLEAR = "\e[37m";
}
has $.lang;
has $.safemode;
method parse(:$unitname, :$filename, :$modtime, :$source) {
my $*SETTINGNAME = $.lang;
my $*SAFEMODE = $.safemode;
my $*UNITNAME = $unitname;
my $*modtime = $modtime;
if $unitname eq 'SAFE' {
$*SETTINGNAME = 'NULL';
$*SAFEMODE = False;
}
if $unitname eq 'CORE' {
$*SETTINGNAME = 'SAFE';
$*SAFEMODE = False;
}
# XXX temp() or should be contextuals
my @save_herestub = @STD::herestub_queue;
my $save_all = $STD::ALL;
$STD::ALL = {};
@STD::herestub_queue = ();
my @*MEMOS;
my @*LINEMEMOS;
my $*FILE = { name => $filename };
my @*ACTIVE;
my $*HIGHWATER = 0;
my $*HIGHEXPECT = {};
my $*HIGHMESS = "";
my $*LASTSTATE = 0;
my $*IN_PANIC = 0;
my $*IN_SUPPOSE = 0;
my $*FATALS = 0;
$DEBUG::EXPR = $STD::DEBUG::EXPR = $STD::DEBUG::symtab =
$*verbose > 1;
my $*LAST_NIBBLE = 0;
my $*LAST_NIBBLE_START = 0;
my $*LAST_NIBBLE_MULTILINE = 0;
my $*LAST_NIBBLE_MULTILINE_START = 0;
my $*GOAL = "(eof)";
my $*SETTING; my $*CORE; my $*GLOBAL; my $*UNIT; my $*YOU_WERE_HERE;
my $*CCSTATE; my $*BORG; my %*RX; my $*XACT; my $*VAR; my $*IN_REDUCE;
my $ast = NieczaGrammar.parse($source, actions => NieczaActions).ast;
$STD::ALL = $save_all;
@STD::herestub_queue = @save_herestub;
$ast;
}