Skip to content

Commit

Permalink
Add support for SavePos statements
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcaliburZero committed Nov 5, 2023
1 parent 5757052 commit 1efc5cb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following QuickBMS commands are currently supported by the langauge server.
* [ ] Support all operators
* [ ] `XMath VAR INSTR`
* [ ] `Open FOLDER NAME [FILENUM] [EXISTS]`
* [ ] `SavePos VAR [FILENUM]`
* [x] `SavePos VAR [FILENUM]`
* [x] `Set VAR [TYPE] VAR`
* [ ] `Do`
* [ ] `While VAR COND VAR`
Expand Down
10 changes: 10 additions & 0 deletions src/server/keyword_docs/savepos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SavePos VAR [FILENUM]

Current position of the file, like ftell in C.

Arguments:
VAR Variable which will contain the offset
FILENUM Number of the file associated to the archive (0)

Examples:
SavePos OFFSET
4 changes: 4 additions & 0 deletions src/server/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ pub fn get_keyword_docs() -> HashMap<String, String> {
"padding".to_string(),
include_str!("keyword_docs/padding.txt").to_string(),
),
(
"savepos".to_string(),
include_str!("keyword_docs/savepos.txt").to_string(),
),
]
.iter()
.cloned()
Expand Down
7 changes: 7 additions & 0 deletions tree-sitter-quickbms/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = grammar({
$.comtype_statement,
$.clog_statement,
$.padding_statement,
$.savepos_statement,
),
set_statement: $ => seq(
$.set,
Expand Down Expand Up @@ -275,6 +276,11 @@ module.exports = grammar({
),
)),
),
savepos_statement: $ => seq(
$.savepos,
field("variable", $._expression),
field("file_number", optional($._expression)),
),
comparison: $ => choice(
"<",
">",
Expand Down Expand Up @@ -401,6 +407,7 @@ module.exports = grammar({
comtype: $ => /[Cc][Oo][Mm][Tt][Yy][Pp][Ee]/,
clog: $ => /[Cc][Ll][Oo][Gg]/,
padding: $ => /[Pp][Aa][Dd][Dd][Ii][Nn][Gg]/,
savepos: $ => /[Ss][Aa][Vv][Ee][Pp][Oo][Ss]/,
question_mark: $ => /\?/,

identifier: $ => /[a-zA-Z_\\\.]+[a-zA-Z0-9_\-\\\.]*/,
Expand Down
12 changes: 12 additions & 0 deletions tree-sitter-quickbms/test/corpus/savepos.bms
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
================================================================================
SavePos statements
================================================================================

savepos OFFSET

--------------------------------------------------------------------------------

(source_file
(savepos_statement
(savepos)
(identifier)))

0 comments on commit 1efc5cb

Please sign in to comment.