mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2026-04-19 08:27:40 +00:00
6502 add hex
This commit is contained in:
@@ -9,6 +9,7 @@ Line {
|
||||
Statement {
|
||||
Instruction |
|
||||
Directive |
|
||||
HexDirective |
|
||||
MacroDef |
|
||||
MacEnd |
|
||||
ControlOp |
|
||||
@@ -44,6 +45,14 @@ PseudoOp {
|
||||
>
|
||||
}
|
||||
|
||||
HexOp { @specialize<Identifier, "hex" | "HEX"> }
|
||||
|
||||
HexDirective {
|
||||
HexOp HexByte*
|
||||
}
|
||||
|
||||
@external tokens hexTokenizer from "../../src/parser/tokens-6502" { HexByte }
|
||||
|
||||
Mac { @specialize<Identifier, "mac"> }
|
||||
MacEnd { @specialize<Identifier, "endm"> }
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ export const Lezer6502: LRLanguage = LRLanguage.define({
|
||||
BinaryGt: t.compareOperator,
|
||||
UnaryLt: t.arithmeticOperator,
|
||||
UnaryGt: t.arithmeticOperator,
|
||||
HexOp: t.definition(t.variableName),
|
||||
HexByte: t.number,
|
||||
Mac: t.definitionKeyword,
|
||||
MacEnd: t.definitionKeyword,
|
||||
"MacroDef/Identifier": t.macroName,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ExternalTokenizer } from "@lezer/lr"
|
||||
import { HexByte } from "../../gen/parser/lang-6502.grammar.terms"
|
||||
|
||||
function isHexDigit(ch: number) {
|
||||
return (ch >= 48 && ch <= 57) || // 0-9
|
||||
(ch >= 65 && ch <= 70) || // A-F
|
||||
(ch >= 97 && ch <= 102) // a-f
|
||||
}
|
||||
|
||||
export const hexTokenizer = new ExternalTokenizer((input) => {
|
||||
if (!isHexDigit(input.peek(0)) || !isHexDigit(input.peek(1))) return
|
||||
let len = 2
|
||||
while (isHexDigit(input.peek(len))) len++
|
||||
if (len % 2 === 0) input.acceptToken(HexByte, len)
|
||||
})
|
||||
Reference in New Issue
Block a user