Skip to content

Commit

Permalink
Add token type for intersections in LuaType tokenizer
Browse files Browse the repository at this point in the history
Fixes an issue in #133 with intersection types
  • Loading branch information
YetAnotherClown committed Oct 1, 2024
1 parent ab4157e commit c3b4429
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docusaurus-plugin-moonwave/src/components/LuaType.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TypeLinksContext } from "./LuaClass"
import styles from "./styles.module.css"
import { Op, PrOp } from "./Syntax"

const isPunc = (char) => !!char.match(/[\{\}<>\-\|]/)
const isPunc = (char) => !!char.match(/[\{\}<>\-\|&]/)
const isWhitespace = (char) => !!char.match(/\s/)
const isAtom = (char) => !isWhitespace(char) && !isPunc(char)

Expand Down Expand Up @@ -133,6 +133,11 @@ function tokenize(code, isGroup) {
continue
}

if (punc === "&") {
tokens.push({ type: "intersection" })
continue
}

tokens.push({
type: "punc",
punc,
Expand Down Expand Up @@ -262,6 +267,8 @@ function Token({ token, depth }) {
return <Op>{token.punc}</Op>
case "union":
return <Op>&nbsp;|&nbsp;</Op>
case "intersection":
return <Op>&nbsp;&amp;&nbsp;</Op>
case "indexer":
return (
<span>
Expand Down

0 comments on commit c3b4429

Please sign in to comment.