Commit d4a6ea3c authored by Zachary Goldstein's avatar Zachary Goldstein
Browse files

Initial commit

parents
UMASM Syntax Package
Author: Zachary Goldstein (zgolds01), Tufts University
Date: 23 Apr 2020
Purpose:
- highlight UMASM source according to grammar specification
- facilitate (relatively) painless UMASM programming
- coat the UMASM language in some super sweet syntactic sugar
- highlight UMASM grammar violations
File Overview:
- UMASM_Language.sublime-color-scheme
This file contains the styling data for each scope defined in the
'sublime-syntax' for UMASM_Language. If you want to change the color
and or styling for a particular scope, that can be done in this file.
You can read up on Sublime Text 3 color schemes here:
https://www.sublimetext.com/docs/3/color_schemes.html
- UMASM_Language.sublime-settings
This file contains settings for this package. Crucially, it links the
'sublime-syntax' with the 'sublime-color-scheme'.
- UMASM_Language.sublime-syntax
This file contains all the syntactic sugar. Scopes are specified using
'regular expression' pattern matching (and since Sublime in built on
Python, we have access to a robust set of 'regex' tools). If you want
to add additional scopes, that can be done in this file.
{
"name": "UMASM",
"author": "Zachary Goldstein",
"variables":
{
"black": "hsl(0, 0%, 0%)",
"black2": "hsl(60, 17%, 11%)",
"black3": "hsl(70, 8%, 15%)",
"blue": "hsl(190, 81%, 67%)",
"grey": "hsl(55, 8%, 26%)",
"lightgrey": "hsl(55, 8%, 60%)",
"orange": "hsl(32, 98%, 56%)",
"orange2": "hsl(30, 83%, 34%)",
"orange3": "hsl(47, 100%, 79%)",
"purple": "hsl(261, 100%, 75%)",
"purple2": "hsl(261, 100%, 40%)",
"red": "hsl(0, 93%, 59%)",
"red2": "hsl(338, 95%, 56%)",
"white": "hsl(0, 0%, 97%)",
"white2": "hsl(60, 36%, 96%)",
"white3": "hsl(60, 30%, 96%)",
"yellow": "hsl(54, 70%, 68%)",
"yellow2": "hsl(80, 76%, 53%)",
"yellow3": "hsl(60, 12%, 79%)",
"yellow4": "hsl(55, 11%, 22%)",
"yellow5": "hsl(50, 11%, 41%)"
},
"globals":
{
"foreground": "var(white3)",
"background": "var(black3)",
"caret": "color(var(white2) alpha(0.9))",
"block_caret": "color(var(white2) alpha(0.4))",
"invisibles": "color(var(white3) alpha(0.35))",
"line_highlight": "var(yellow4)",
"selection": "var(grey)",
"selection_border": "var(black2)",
"misspelling": "var(red2)",
"active_guide": "color(var(orange2) alpha(0.69))",
"find_highlight_foreground": "var(black)",
"find_highlight": "var(orange3)",
"brackets_options": "underline",
"brackets_foreground": "color(var(white3) alpha(0.65))",
"bracket_contents_options": "underline",
"bracket_contents_foreground": "color(var(white3) alpha(0.65))",
"tags_options": "stippled_underline"
},
"rules":
[
{
"name": "Dummy",
"scope": "dummy",
"foreground": "var(grey)",
"font_style": "italic"
},
{
"name": "Label",
"scope": "label",
"foreground": "var(blue)",
"font_style": "italic"
},
{
"name": "Register",
"scope": "register",
"foreground": "var(orange)",
"font_style": "italic"
},
{
"name": "Comment",
"scope": "comment",
"foreground": "var(yellow5)"
},
{
"name": "Number",
"scope": "literal.numeric",
"foreground": "var(purple)"
},
{
"name": "Character",
"scope": "literal.character",
"foreground": "var(yellow)"
},
{
"name": "String",
"scope": "string",
"foreground": "var(yellow)"
},
{
"name": "Directive",
"scope": "directive",
"foreground": "var(yellow2)",
"font_style": "italic"
},
{
"name": "Assignment",
"scope": "operator.assignment",
"foreground": "var(red2)"
},
{
"name": "Relational",
"scope": "operator.relational",
},
{
"name": "Binary",
"scope": "operator.binary"
},
{
"name": "Unary",
"scope": "operator.unary",
},
{
"name": "Keyword",
"scope": "keyword",
"foreground": "var(red2)"
},
{
"name": "Invalid",
"scope": "invalid",
"foreground": "var(white2)",
"background": "var(red2)"
},
]
}
\ No newline at end of file
[
{ "keys": ["command+a"], "command": "toggle_comment", "args": { "block": false } }
]
\ No newline at end of file
{
"color_scheme": "umasm.sublime-color-scheme",
"tab_size": 4,
"translate_tabs_to_spaces": true,
}
\ No newline at end of file
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: UMASM
file_extensions:
- ums
scope: source
variables:
reserved: |-
(?x)
(?:
if | m | goto | map | segment | nand | xor | string |
mod | unmap | input | output | in | program | using | off |
here | halt | words | push | pop | on | off | stack | linking
)
directive: |-
(?x)
(?:
section | data | space | string | zero | temps
)
\b
register: \br\d\b
ident: |-
(?x)
\b
(?!{{reserved}}\b)
(?!{{register}}\b)
[A-Za-z_][A-Za-z_0-9]*
label: '{{ident}}'
hex_literal: '\b(-)?0x[A-Fa-f0-9]+\b'
decimal_literal: '\b(-)?[0-9]+\b'
character_literal: '''(?:\\.|.)'''
k: (?:{{hex_literal}}|{{decimal_literal}}|{{character_literal}})
rvalue_helper: |-
(?x)
(?: {{register}} | (-)?{{k}} | {{label}}
)
rvalue: |-
(?x)
(?: m\[{{register}}\]\[(?: {{rvalue_helper}} (\s+)? (?:\+|\-) (\s+)? {{rvalue_helper}}
| {{rvalue_helper}})\]
| {{rvalue_helper}}(\s+?)(?:\+|\-)(\s+?){{rvalue_helper}}
| {{rvalue_helper}}
)
lvalue: (?:{{register}}|m\[{{register}}\]\[{{rvalue}}\])
relop: (?:!=|==|<s|>s|<=s|>=s)
binop: (?:\+|-|\*|/|nand|&|\||xor|mod)
unop: (?:-|~)
instr: |-
(?x)
(?: {{lvalue}} (\s+)? := (\s+)? {{rvalue}}
| {{lvalue}} (\s+)? := (\s+)? {{rvalue}} \s+ {{binop}} \s+ {{rvalue}}
| {{lvalue}} (\s+)? := (\s+)? {{unop}} (\s+)? {{rvalue}}
| {{lvalue}} (\s+)? := (\s+)? input\(\)
| {{lvalue}} (\s+)? := (\s+)? map \s+ segment \s+ \( {{rvalue}} \s+ words \)
| {{lvalue}} (\s+)? := (\s+)? map \s+ segment \s+ (string \s+ ".+")
| unmap \s+ m\[ {{register}} \]
| output \s+ {{rvalue}}
| output \s+ ".+"
| goto\s+{{rvalue}}(\s+)?(linking\s+{{register}})?(?!(\s+)?using)
| if \s+ \( (\s+)? {{rvalue}} (\s+)? {{relop}} (\s+)? {{rvalue}} (\s+)? \) \s+ goto \s+ {{rvalue}}
| if \s+ \( (\s+)? {{rvalue}} (\s+)? {{relop}} (\s+)? {{rvalue}} (\s+)? \) \s+ {{lvalue}} (\s+)? := (\s+)? {{rvalue}}
| push \s+ {{rvalue}} \s+ on \s+ stack \s+ {{register}}
| pop \s+ ({{lvalue}} \s+ off \s+ )? stack \s+ {{register}}
| halt
| goto *{{register}} in program m\[{{register}}\]
)
directive_syntax: |-
(?x)
\.
(?: section\s+{{ident}}
| data \s+ {{label}}(\s+(?:\+|-)\s+{{k}})?
| data \s+ {{k}}
| space \s+ {{k}}
| string \s+ ".+"
| zero \s+ {{register}}
| zero \s+ off
| temps \s+ {{register}} ((,\s+{{register}})+)?
| temps \s+ off
)
line: |-
(?x)
# leading whitespace
^(\s+)?
# optional label
({{label}}:)?
# optional instruction/directive
(
# leading whitespace
(\s+)?
(?: {{instr}}(\s+)?(using\s+{{register}}((\s+)? (,\s+{{register}})+ )?)?
| {{directive_syntax}}
)?
)
# trailing comments
(\s+)?
((?:\#|//).*)?
contexts:
# The prototype context is prepended to all contexts but those setting
# meta_include_prototype: false.
prototype:
- include: comments
main:
# highlights syntactically dubious lines
- match: '^(?!^{{line}}$).*'
scope: invalid
- include: keyword
- include: literal
- include: operator
keyword:
- match: \b{{reserved}}\b
scope: keyword
- match: \b{{register}}\b
scope: register
- match: '{{label}}(?=:)'
scope: label
- match: '\.{{directive}}\b'
scope: directive
literal:
- match: '\b{{decimal_literal}}\b'
scope: literal.numeric
- match: '\b{{hex_literal}}\b'
scope: literal.numeric
- match: '{{character_literal}}'
scope: literal.character
# string-literals begin and end with quotes, and use backslashes as an escape character.
- match: '"'
scope: punctuation.definition.string.begin
push: inside_string
inside_string:
- meta_include_prototype: false
- meta_scope: string.quoted.double
- match: '\.'
scope: constant.character.escape
- match: '"'
scope: punctuation.definition.string.end
pop: true
operator:
# assignment operator
- match: \:\=
scope: operator.assignment
- match: '{{relop}}'
scope: operator.relational
- match: '{{binop}}'
scope: operator.binary
- match: '{{unop}}'
scope: operator.unary
comments:
# Comments begin with a '//' or '#' and finish at the end of the line.
- match: '//|#'
scope: punctuation.definition.comment
push:
- meta_scope: comment.line.double-slash
- match: $\n?
pop: true
UMASM_Language Syntax Package
Author: Zachary Goldstein (zgolds01), Tufts University
Date: 23 Apr 2020
Purpose:
- highlight UMASM source according to grammar specification
- facilitate (relatively) painless UMASM programming
- coat the UMASM language in some super sweet syntactic sugar
File Overview:
- UMASM_Language.sublime-color-scheme
This file contains the styling data for each scope defined in the
'sublime-syntax' for UMASM_Language. If you want to change the color
and or styling for a particular scope, that can be done in this file.
You can read up on Sublime Text 3 color schemes here:
https://www.sublimetext.com/docs/3/color_schemes.html
- UMASM_Language.sublime-settings
This file contains settings for this package. Crucially, it links the
'sublime-syntax' with the 'sublime-color-scheme'.
- UMASM_Language.sublime-syntax
This file contains all the syntactic sugar. Scopes are specified using
'regular expression' pattern matching (and since Sublime in built on
Python, we have access to a robust set of 'regex' tools). If you want
to add additional scopes, that can be done in this file.
For an extra dash of syntactic sugar, it is possible to build a (rather
cumbersome) pattern that identifies and highlights syntactically invalid
lines of UMASM source code. To do this, you'll have to represent the
UMASM grammar as a 'regex' pattern.
{
"name": "UMASM_Language",
"author": "Zachary Goldstein",
"variables":
{
"black": "hsl(0, 0%, 0%)",
"black2": "hsl(60, 17%, 11%)",
"black3": "hsl(70, 8%, 15%)",
"blue": "hsl(190, 81%, 67%)",
"grey": "hsl(55, 8%, 26%)",
"lightgrey": "hsl(55, 8%, 60%)",
"orange": "hsl(32, 98%, 56%)",
"orange2": "hsl(30, 83%, 34%)",
"orange3": "hsl(47, 100%, 79%)",
"purple": "hsl(261, 100%, 75%)",
"purple2": "hsl(261, 100%, 40%)",
"red": "hsl(0, 93%, 59%)",
"red2": "hsl(338, 95%, 56%)",
"white": "hsl(0, 0%, 97%)",
"white2": "hsl(60, 36%, 96%)",
"white3": "hsl(60, 30%, 96%)",
"yellow": "hsl(54, 70%, 68%)",
"yellow2": "hsl(80, 76%, 53%)",
"yellow3": "hsl(60, 12%, 79%)",
"yellow4": "hsl(55, 11%, 22%)",
"yellow5": "hsl(50, 11%, 41%)"
},
"globals":
{
"foreground": "var(white3)",
"background": "var(black3)",
"caret": "color(var(white2) alpha(0.9))",
"block_caret": "color(var(white2) alpha(0.4))",
"invisibles": "color(var(white3) alpha(0.35))",
"line_highlight": "var(yellow4)",
"selection": "var(grey)",
"selection_border": "var(black2)",
"misspelling": "var(red2)",
"active_guide": "color(var(orange2) alpha(0.69))",
"find_highlight_foreground": "var(black)",
"find_highlight": "var(orange3)",
"brackets_options": "underline",
"brackets_foreground": "color(var(white3) alpha(0.65))",
"bracket_contents_options": "underline",
"bracket_contents_foreground": "color(var(white3) alpha(0.65))",
"tags_options": "stippled_underline"
},
"rules":
[
{
"name": "Label",
"scope": "label",
"foreground": "var(blue)",
"font_style": "italic"
},
{
"name": "Register",
"scope": "register",
"foreground": "var(orange)",
"font_style": "italic"
},
{
"name": "Comment",
"scope": "comment",
"foreground": "var(yellow5)"
},
{
"name": "Number",
"scope": "literal.numeric",
"foreground": "var(purple)"
},
{
"name": "Character",
"scope": "literal.character",
"foreground": "var(yellow)"
},
{
"name": "String",
"scope": "string",
"foreground": "var(yellow)"
},
{
"name": "Directive",
"scope": "directive",
"foreground": "var(yellow2)",
"font_style": "italic"
},
{
"name": "Assignment",
"scope": "operator.assignment",
"foreground": "var(red2)"
},
{
"name": "Relational",
"scope": "operator.relational",
},
{
"name": "Binary",
"scope": "operator.binary"
},
{
"name": "Unary",
"scope": "operator.unary",
},
{
"name": "Keyword",
"scope": "keyword",
"foreground": "var(red2)"
},
]
}
\ No newline at end of file
{
"color_scheme": "UMASM_Language.sublime-color-scheme",
}
\ No newline at end of file
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: UMASM_Language
file_extensions:
- ums
scope: source
variables:
reserved: |-
(?x)
(?:
if | m | goto | map | segment | nand | xor | string |
unmap | input | output | in | program | using | off |
here | halt | words | push | pop | on | off | stack | linking | using
)
directive: |-
(?x)
(?:
section | data | space | string | zero | temps
)
\b
register: \br\d\b
ident: |-
(?x)
\b
(?!{{reserved}}\b)
(?!{{register}}\b)
[A-Za-z_][A-Za-z_0-9]*
label: '{{ident}}'
hex_literal: '\b(-)?0x[A-Fa-f0-9]+\b'
decimal_literal: '\b(-)?[0-9]+\b'
character_literal: '''(?:\\.|.)'''
relop: (?:!=|==|<s|>s|<=s|>=s)
binop: (?:\+|-|\*|/|nand|&|\||xor|mod)
unop: (?:-|~)
contexts:
# The prototype context is prepended to all contexts but those setting
# meta_include_prototype: false.
prototype:
- include: comments
main:
- include: keyword
- include: literal
- include: operator
keyword:
- match: \b{{reserved}}\b
scope: keyword
- match: \b{{register}}\b
scope: register
- match: '{{label}}(?=:)'
scope: label
- match: '\.{{directive}}\b'
scope: directive
literal:
- match: '\b{{decimal_literal}}\b'
scope: literal.numeric
- match: '\b{{hex_literal}}\b'
scope: literal.numeric
- match: '{{character_literal}}'
scope: literal.character
# string-literals begin and end with quotes, and use backslashes as an escape character.
- match: '"'
scope: punctuation.definition.string.begin
push: inside_string
inside_string:
- meta_include_prototype: false
- meta_scope: string.quoted.double
- match: '\.'
scope: constant.character.escape
- match: '"'
scope: punctuation.definition.string.end
pop: true
operator:
# assignment operator
- match: \:\=
scope: operator.assignment
- match: '{{relop}}'
scope: operator.relational
- match: '{{binop}}'
scope: operator.binary
- match: '{{unop}}'
scope: operator.unary