-
On assembly for arm64 instruction sets, the harsh symbol can be either a comment or a prefix for a value. For example:
It should have this parsing result:
In the first line, This is a minimal parse configuration I got to test it: module.exports = grammar({
name: "asm",
extras: ($) => [/\s|\t|\r/, $.comment],
rules: {
program: ($) => repeat($._definition),
_definition: ($) =>
choice(
$.mov_instruction,
// TODO: other kinds of definitions
),
mov_instruction: ($) => seq("mov", $.arg_src, ",", $.arg_dst),
arg_src: ($) => /X[0-9]+/,
arg_dst: ($) => /#[0-9]+/,
comment: ($) =>
choice(
token(
choice(
// comment types
seq("#", /.*/),
seq(";", /.*/),
seq("//", /.*/),
),
),
),
},
}); Here is the parse debug output I get for
And this is the parse debug output I get for
I really appreciate any feedback on how to solve it. I tried using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I got it to work by removing module.exports = grammar({
name: "asm",
extras: ($) => [/\s|\t|\r/],
rules: {
program: ($) => repeat(choice($._definition, $.comment)),
_definition: ($) =>
prec.left(
1,
seq(
choice(
$.mov_instruction,
// TODO: other kinds of definitions
),
optional($.comment),
),
),
mov_instruction: ($) =>
prec.left(1, seq("mov", $.arg_src, ",", $.arg_dst, optional($.comment))),
arg_src: ($) => /X[0-9]+/,
arg_dst: ($) => /#[0-9]+/,
comment: ($) =>
choice(
token(
choice(
// comment types
seq("#", /.*/),
seq(";", /.*/),
seq("//", /.*/),
),
),
),
},
}); Now this:
Outputs what I expected:
I will go with that for now. But please, let me know if anyone has any better ideas. |
Beta Was this translation helpful? Give feedback.
I got it to work by removing
comment
from extras, and properly configuring it on the parts it should be supported instead of automatically depending on the extras feature for that.