almost working

This commit is contained in:
Daniel Bulant 2024-02-18 11:58:20 +01:00
parent 4cb8ae3f80
commit bd8728abdd
2 changed files with 15 additions and 14 deletions

View file

@ -43,8 +43,8 @@
In, In,
Then, Then,
Else, Else,
End, End//,
identifier // identifier
} }
@external specialize {identifier} specializeIdent from "./tokens" { @external specialize {identifier} specializeIdent from "./tokens" {
Return, Return,
@ -177,8 +177,10 @@ Field {
expression (As identifier)? | expression (As identifier)? |
Star Star
} }
ReferencedFulltextOperator { @skip {} {
"@" identifier "@" ReferencedFulltextOperator {
"@" int+ "@"
}
} }
BinaryExpression { BinaryExpression {
expression !and And expression | expression !and And expression |
@ -364,6 +366,8 @@ statement[@isGroup=Statement] {
whitespace { @whitespace+ } whitespace { @whitespace+ }
LineComment { ("//" | "-- ") ![\n]* } LineComment { ("//" | "-- ") ![\n]* }
identifier { $[a-zA-Z_] $[a-zA-Z0-9_]* }
int { @digit+ } int { @digit+ }
RIDDelim { "`" } RIDDelim { "`" }

View file

@ -64,8 +64,7 @@ import {
// extend // extend
Changes, Changes,
Table, Table
identifier
} from "./surrealql.grammar.terms" } from "./surrealql.grammar.terms"
const enum Ch { const enum Ch {
@ -154,6 +153,7 @@ const kwmap = new Map([
[["else"], Else], [["else"], Else],
[["end"], End], [["end"], End],
]); ]);
let allkws = [...kwmap.keys()].reduce((a, b) => a.concat(b), [])
const specmap = new Map([ const specmap = new Map([
["return", Return], ["return", Return],
["transaction", Transaction], ["transaction", Transaction],
@ -199,10 +199,10 @@ const cspecmap = new Map([
]); ]);
function isAlpha(ch: number) { function isAlpha(ch: number) {
return ch >= Ch.A && ch <= Ch.Z || ch >= Ch.a && ch <= Ch.z return ch >= Ch.A && ch <= Ch.Z || ch >= Ch.a && ch <= Ch.z || ch == Ch.Underscore
} }
function isAlphaNum(ch: number) { function isAlphaNum(ch: number) {
return ch >= Ch.A && ch <= Ch.Z || ch >= Ch.a && ch <= Ch.z || ch >= Ch._0 && ch <= Ch._9 return ch >= Ch.A && ch <= Ch.Z || ch >= Ch.a && ch <= Ch.z || ch >= Ch._0 && ch <= Ch._9 || ch == Ch.Underscore
} }
function readWord(input: InputStream, result?: string) { function readWord(input: InputStream, result?: string) {
@ -225,7 +225,6 @@ export const tokens = new ExternalTokenizer((input, stack) => {
if(isAlpha(next)) { if(isAlpha(next)) {
input.advance() input.advance()
let word = readWord(input, String.fromCharCode(next)) let word = readWord(input, String.fromCharCode(next))
console.log("Got word", word)
let word2: string | undefined = undefined let word2: string | undefined = undefined
if (word != null) { if (word != null) {
word = word.toLowerCase() word = word.toLowerCase()
@ -242,21 +241,19 @@ export const tokens = new ExternalTokenizer((input, stack) => {
return return
} }
} }
console.log("accepting identifier", word)
input.acceptToken(identifier)
} }
} }
}, {contextual: true}) }, {contextual: false})
export const specializeIdent = (text, stack) => { export const specializeIdent = (text, stack) => {
if(specmap.has(text)) { if(specmap.has(text)) {
return specmap.get(text) return specmap.get(text)
} }
// console.log("sspec", text) return -1
} }
export const extendIdent = (text, stack) => { export const extendIdent = (text, stack) => {
if(cspecmap.has(text)) { if(cspecmap.has(text)) {
return cspecmap.get(text) return cspecmap.get(text)
} }
console.log("cspec", text) return -1
} }