port lexer to cpp
This commit is contained in:
parent
cacc641378
commit
b3b21f3101
13 changed files with 276 additions and 32 deletions
14
src/compilers/Bindings.ts
Normal file
14
src/compilers/Bindings.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import bindings from "bindings"
|
||||
import { Token } from "./bindings/types.js"
|
||||
|
||||
export const {
|
||||
Lexer,
|
||||
isBlankChar,
|
||||
isWordChar,
|
||||
isNumberChar,
|
||||
}: {
|
||||
Lexer: (input: string) => Token[]
|
||||
isBlankChar: (char: string) => boolean
|
||||
isWordChar: (char: string) => boolean
|
||||
isNumberChar: (char: string) => boolean
|
||||
} = bindings("asajs-compiler")
|
||||
|
|
@ -9,3 +9,7 @@ export function isWordChar(char: string) {
|
|||
export function isNumberChar(char: string) {
|
||||
return /\d/.test(char)
|
||||
}
|
||||
|
||||
export function isCompileBinding(input: string) {
|
||||
return input.startsWith("[") && input.endsWith("]")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { Expression, GenBinding, Token, TokenKind, TSToken, TSTokenKind } from "./types.js"
|
||||
import { BindingType } from "../../types/enums/BindingType.js"
|
||||
import { BindingItem } from "../../types/properties/value.js"
|
||||
import { FuntionMap } from "./Funtion.js"
|
||||
import { Lexer } from "./Lexer.js"
|
||||
import { Expression, GenBinding, Token, TokenKind, TSToken, TSTokenKind } from "./types.js"
|
||||
|
||||
export class Parser {
|
||||
position: number = 0
|
||||
|
|
@ -240,14 +240,14 @@ export class Parser {
|
|||
this.eat()
|
||||
|
||||
return this.funtionCall(<string>callerToken.value, ...args)
|
||||
} else if (left.kind === TokenKind.OPERATOR) {
|
||||
} else if (left?.kind === TokenKind.OPERATOR) {
|
||||
this.warn(
|
||||
`Implicit string literal '${callerToken.value}'. Use quoted string ('${callerToken.value}') for clarity!`,
|
||||
callerToken,
|
||||
)
|
||||
return <string>callerToken.value
|
||||
} else {
|
||||
this.expect(TokenKind.OPERATOR, "Unexpected token!")
|
||||
this.expect(TokenKind.WORD, "Unexpected token!")
|
||||
return <string>callerToken.value
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue