Skip to content

Commit

Permalink
feat: Assembly support (#122)
Browse files Browse the repository at this point in the history
Updates #1

Signed-off-by: Ian Lewis <ianlewis@google.com>
  • Loading branch information
Ian Lewis authored Jul 21, 2023
1 parent 08a378d commit ff5c222
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 15 deletions.
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

0 comments on commit ff5c222

Please sign in to comment.