Skip to content

Commit d24e2b8

Browse files
committed
Support for keywords and classes
1 parent 4fc8f6e commit d24e2b8

File tree

4 files changed

+167
-4
lines changed

4 files changed

+167
-4
lines changed

Cargo.lock

+84
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
sanny_builder_core = { git = "https://github.com/sannybuilder/core", branch = "master", package = "sanny_builder_core" }

src/main.rs

+74-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,88 @@
1+
extern crate sanny_builder_core as sb;
2+
use sb::dictionary::dictionary_num_by_str::DictNumByStr;
3+
use sb::dictionary::ffi::*;
4+
use sb::namespaces::namespaces::Namespaces;
5+
use std::ffi::CString;
6+
17
fn main() {
28
if let Some(input_file) = std::env::args().nth(1) {
39
match std::fs::read(input_file) {
410
Ok(buf) => {
511
let file_content = String::from_utf8_lossy(&buf);
612
let mut uniq_opcodes = vec![];
713
let mut output = vec![];
14+
let mut keywords = DictNumByStr::new(
15+
Duplicates::Replace,
16+
CaseFormat::NoFormat,
17+
String::from(";"),
18+
String::from("=,"),
19+
true,
20+
true,
21+
);
22+
let mut classes = Namespaces::new();
23+
24+
// todo: read from command line
25+
let has_keywords = keywords.load_file("keywords.txt").is_some();
26+
let has_classes = classes.load_classes("classes.db").is_some();
827

928
for line in file_content.lines() {
1029
let line = line.trim();
30+
31+
// opcode
1132
if let Some(':') = line.chars().nth(4) {
12-
let opcode = line.get(0..4).unwrap();
13-
if !uniq_opcodes.contains(&opcode) {
14-
uniq_opcodes.push(opcode);
15-
output.push(line);
33+
if let Some(opcode) = line.get(0..4) {
34+
if !uniq_opcodes.contains(&opcode) {
35+
uniq_opcodes.push(opcode);
36+
output.push(line);
37+
continue;
38+
}
39+
}
40+
}
41+
42+
if !has_classes && !has_keywords {
43+
continue;
44+
}
45+
46+
if let Some(first_word) = line
47+
.split(|c: char| {
48+
c.is_ascii_whitespace() || c == '(' || c == ')' || c == ','
49+
})
50+
.next()
51+
{
52+
// keyword
53+
if has_keywords {
54+
if let Some(key) = CString::new(first_word).ok() {
55+
if keywords.map.contains_key(&key) {
56+
if !uniq_opcodes.contains(&first_word) {
57+
uniq_opcodes.push(first_word);
58+
output.push(line);
59+
continue;
60+
}
61+
}
62+
}
63+
}
64+
65+
// classes
66+
if has_classes {
67+
if first_word.contains('.') {
68+
let mut class = first_word.split(|c| c == '.');
69+
70+
if let Some(class_name) = class.next() {
71+
if let Some(member_name) = class.next() {
72+
// bug: see https://github.com/sannybuilder/dev/issues/92
73+
if classes
74+
.get_opcode_index_by_name(class_name, member_name)
75+
.is_some()
76+
{
77+
if !uniq_opcodes.contains(&first_word) {
78+
uniq_opcodes.push(first_word);
79+
output.push(line);
80+
continue;
81+
}
82+
}
83+
}
84+
}
85+
}
1686
}
1787
}
1888
}

src/test/1.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
0000: nop
2+
0001: wait
3+
4+
5+
terminate_this_script
6+
7+
player.money($player) += 1
8+
player.controllable(0)

0 commit comments

Comments
 (0)