Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions common/identifiers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// A single unquoted segment: starts with letter or %, then letters/digits
const IDENT_SEG = /[%A-Za-z][A-Za-z0-9]*/;

// Dotted form where *each* segment follows the same rule
const DOTTED_ID_STRICT =
/[%A-Za-z][A-Za-z0-9]*(?:\.[%A-Za-z][A-Za-z0-9]*)*/;

// this will be used for routine names and labels
const DOTTED_ID_RELAXED = /[%A-Za-z][A-Za-z0-9]*(?:\.[A-Za-z0-9]+)*/;

module.exports = {
IDENT_SEG,
DOTTED_ID_STRICT,
DOTTED_ID_RELAXED,
};
36 changes: 25 additions & 11 deletions core/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Note: CommonJS warning is expected - TypeScript repos commonly have this issue
const objectscript_expr = require('../expr/grammar');

const {
unspace: generate_post_conditionals,
repeat_with_commas,
Expand Down Expand Up @@ -71,13 +72,15 @@ module.exports = grammar(objectscript_expr, {
$._block_comment_inner,
$.macro_value_line_with_continue,
$.sentinel,
$.bol,
$._inline_statement_separator
],
conflicts: ($, previous) =>
previous.concat([
[$.keyword_hang, $.keyword_halt],
[$.command_xecute, $._parenthetical_expression],
[ $.label_ref, $.objectscript_identifier ],
]),
// [$.statement, $.expression]],

// These are what I can think of
// \r: Carriage return
Expand All @@ -97,6 +100,7 @@ module.exports = grammar(objectscript_expr, {
// Note that adding the word key
// makes tree sitter not like the one letter form of keyword write
precedences: ($, previous) => [

[$.oref_method_post_cond, $.oref_property_post_cond],
[$.oref_chain_expr_post_cond, $.expr_atom_post_cond],
[$.command_hang, $.command_halt],
Expand Down Expand Up @@ -174,11 +178,12 @@ module.exports = grammar(objectscript_expr, {
),

dotted_statement: ($) =>
prec.right(10, seq(
repeat1('.'),
optional(token.immediate(/[ \t]+/)),
$.statement,
)),
seq(
// this is from the external scanner, and it means that it was
// at the start of a line and there were dots matching the dotted statement
$.bol,
$.statement
),
pound_dim: ($) =>
seq(
field('preproc_keyword', $.keyword_dim),
Expand Down Expand Up @@ -389,8 +394,11 @@ module.exports = grammar(objectscript_expr, {
field('mnemonic', $.mnemonic_name),
optional($.method_args)
),
mnemonic_name: (_) =>
token(/\/[%A-Za-z0-9][A-Za-z0-9]*/),
mnemonic_name: ($) =>
seq(
"/",
$.identifier_segment_immediate
),

// Reference: https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_cdo
command_do: ($) =>
Expand Down Expand Up @@ -468,6 +476,7 @@ module.exports = grammar(objectscript_expr, {
seq(
field('command_name', $.keyword_for),
$._immediate_single_whitespace_followed_by_non_whitespace,
optional($._whitespace_before_block),
repeat_with_commas($.for_parameter),
'{',
repeat($.statement),
Expand Down Expand Up @@ -558,7 +567,7 @@ module.exports = grammar(objectscript_expr, {

command_lock: ($) =>
choice(
build_command_rule_argumentless($, $.keyword_lock),
seq(field('command_name', $.keyword_lock), $._argumentless_command_end),
build_command_rule_argumentful(
$,
$.keyword_lock,
Expand Down Expand Up @@ -809,6 +818,7 @@ module.exports = grammar(objectscript_expr, {
field('command_name', $.keyword_if),
$._immediate_single_whitespace_followed_by_non_whitespace,
repeat_with_commas($.expression),
optional($._whitespace_before_block),
'{',
repeat($.statement),
'}',
Expand All @@ -821,10 +831,14 @@ module.exports = grammar(objectscript_expr, {
field('command_name', $.keyword_if),
$._immediate_single_whitespace_followed_by_non_whitespace,
repeat_with_commas($.expression),
optional(choice(
$._immediate_single_whitespace_followed_by_non_whitespace,
$._inline_statement_separator,
)),
choice(
$._argumentless_command_end,
prec.left(repeat1($.statement)),
),
$._argumentless_command_end
)
),
// Argumentless IF, requires 2 spaces following
seq(
Expand Down
19 changes: 17 additions & 2 deletions core/queries/indents.scm
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,20 @@
(keyword_use)
(use_parameter) @indent)

(command_while
(statements) @indent)
; ----- Block-style commands -----
(command_while "{" @indent.begin "}" @indent.end)
(command_for "{" @indent.begin "}" @indent.end)
(command_if "{" @indent.begin "}" @indent.end)
(elseif_block "{" @indent.begin "}" @indent.end)
(else_block "{" @indent.begin "}" @indent.end)

; ----- Old-style FOR -----
(command_for (for_parameter) @indent)
(command_for (statement) @indent)

; ----- Old-style IF -----
(command_if (expression) @indent)
(command_if (statement) @indent)

; Old-style ELSE:
(command_else (statement) @indent)
Loading