Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Assembly support #122

Merged
merged 1 commit into from
Jul 21, 2023
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
47 changes: 32 additions & 15 deletions internal/scanner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {

var (
languageMap = map[string]*Config{
"Assembly": &AssemblyConfig,
"C": &CConfig,
"C++": &CPPConfig,
"C#": &CSConfig,
Expand All @@ -35,21 +36,34 @@ var (
"Java": &JavaConfig,
"JavaScript": &JavascriptConfig,
// NOTE: Some JSON files support JS comments (e.g. tsconfig.json)
"JSON": &JavascriptConfig,
"Lua": &LuaConfig,
"Makefile": &MakefileConfig,
"Objective-C": &ObjectiveCConfig,
"Perl": &PerlConfig,
"PHP": &PHPConfig,
"Python": &PythonConfig,
"Ruby": &RubyConfig,
"Scala": &ScalaConfig,
"Shell": &ShellConfig,
"Swift": &SwiftConfig,
"TOML": &TOMLConfig,
"TypeScript": &TypescriptConfig,
"XML": &XMLConfig,
"YAML": &YAMLConfig,
"JSON": &JavascriptConfig,
"Lua": &LuaConfig,
"Makefile": &MakefileConfig,
"Objective-C": &ObjectiveCConfig,
"Perl": &PerlConfig,
"PHP": &PHPConfig,
"Python": &PythonConfig,
"Ruby": &RubyConfig,
"Scala": &ScalaConfig,
"Shell": &ShellConfig,
"Swift": &SwiftConfig,
"TOML": &TOMLConfig,
"TypeScript": &TypescriptConfig,
"Unix Assembly": &UnixAssemblyConfig,
"XML": &XMLConfig,
"YAML": &YAMLConfig,
}

// AssemblyConfig is a config for Assembly.
AssemblyConfig = Config{
LineCommentStart: []string{";"},
// TODO(#1): Parsing should exclude the leading '*' for multi-line comments.
MultilineCommentStart: "/*",
MultilineCommentEnd: "*/",
Strings: [][2]string{
{"\"", "\""},
{"'", "'"},
},
}

// CConfig is a config for C.
Expand Down Expand Up @@ -194,6 +208,9 @@ var (
// TypescriptConfig is a config for Typescript.
TypescriptConfig = JavascriptConfig

// UnixAssemblyConfig is a config for Unix Assembly.
UnixAssemblyConfig = AssemblyConfig

// XMLConfig is a config for XML.
XMLConfig = Config{
MultilineCommentStart: "<!--",
Expand Down
118 changes: 118 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,124 @@ var scannerTestCases = []*struct {
line int
}
}{
// Assembly
{
name: "line_comments.s",
src: `; file comment

; TODO is a function.
TODO:
ret ; Random comment`,
config: UnixAssemblyConfig,
comments: []struct {
text string
line int
}{
{
text: "; file comment",
line: 1,
},
{
text: "; TODO is a function.",
line: 3,
},
{
text: "; Random comment",
line: 5,
},
},
},
{
name: "comments_in_string.s",
src: `; file comment

; TODO is a function.
TODO:
msg x "; Random comment",0
msg y '; Random comment',0
ret`,
config: UnixAssemblyConfig,
comments: []struct {
text string
line int
}{
{
text: "; file comment",
line: 1,
},
{
text: "; TODO is a function.",
line: 3,
},
},
},
{
name: "escaped_string.s",
src: `; file comment

; TODO is a function.
TODO:
msg x "\"; Random comment",0
msg y '\'; Random comment',0
ret`,
config: UnixAssemblyConfig,
comments: []struct {
text string
line int
}{
{
text: "; file comment",
line: 1,
},
{
text: "; TODO is a function.",
line: 3,
},
// TODO(#1): Assembly doesn't seems to support escaped double or single quotes.
// {
// text: "; Random comment',0",
// line: 5,
// },
// {
// text: "; Random comment',0",
// line: 6,
// },
},
},
{
name: "multi_line.s",
src: `; file comment

/*
TODO is a function.
*/
TODO:
ret ; Random comment
/* extra comment */`,
config: UnixAssemblyConfig,
comments: []struct {
text string
line int
}{
{
text: "; file comment",
line: 1,
},
{
text: "/*\n\t\t\tTODO is a function.\n\t\t\t*/",
line: 3,
},
{
text: "; Random comment",
line: 7,
},
{
text: "/* extra comment */",
line: 8,
},
},
},

// Go
{
name: "line_comments.go",
Expand Down