Skip to content

Commit

Permalink
OZ: Improved tokenization (#3240)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 10, 2021
1 parent c3f9fb7 commit a3905c0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
9 changes: 6 additions & 3 deletions components/prism-oz.js
@@ -1,5 +1,8 @@
Prism.languages.oz = {
'comment': /\/\*[\s\S]*?\*\/|%.*/,
'comment': {
pattern: /\/\*[\s\S]*?\*\/|%.*/,
greedy: true
},
'string': {
pattern: /"(?:[^"\\]|\\[\s\S])*"/,
greedy: true
Expand All @@ -18,8 +21,8 @@ Prism.languages.oz = {
}
],
'number': /\b(?:0[bx][\da-f]+|\d+(?:\.\d*)?(?:e~?\d+)?)\b|&(?:[^\\]|\\(?:\d{3}|.))/i,
'variable': /\b[A-Z][A-Za-z\d]*|`(?:[^`\\]|\\.)+`/,
'attr-name': /\b\w+(?=:)/,
'variable': /`(?:[^`\\]|\\.)+`/,
'attr-name': /\b\w+(?=[ \t]*:(?![:=]))/,
'operator': /:(?:=|::?)|<[-:=]?|=(?:=|<?:?)|>=?:?|\\=:?|!!?|[|#+\-*\/,~^@]|\b(?:andthen|div|mod|orelse)\b/,
'punctuation': /[\[\](){}.:;?]/
};
2 changes: 1 addition & 1 deletion components/prism-oz.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions tests/languages/oz/attr-name_feature.test
@@ -1,14 +1,25 @@
menubutton(text:'Test' underline:0)

% negative example
val:=Value

----------------------------------------------------

[
["function", "menubutton"], ["punctuation", "("],
["attr-name", "text"], ["punctuation", ":"], ["atom", "'Test'"],
["attr-name", "underline"], ["punctuation", ":"], ["number", "0"],
["punctuation", ")"]
["function", "menubutton"],
["punctuation", "("],
["attr-name", "text"],
["punctuation", ":"],
["atom", "'Test'"],
["attr-name", "underline"],
["punctuation", ":"],
["number", "0"],
["punctuation", ")"],

["comment", "% negative example"],
"\r\nval", ["operator", ":="], "Value"
]

----------------------------------------------------

Checks for parameter names.
Checks for parameter names.
22 changes: 7 additions & 15 deletions tests/languages/oz/variable_feature.test
@@ -1,15 +1,7 @@
A
Foobar
Foo42

----------------------------------------------------

[
["variable", "A"],
["variable", "Foobar"],
["variable", "Foo42"]
]

----------------------------------------------------

Checks for variables.
`foo`

----------------------------------------------------

[
["variable", "`foo`"]
]

0 comments on commit a3905c0

Please sign in to comment.