Schema: parse annotations on patterns, parse line comments

This commit is contained in:
Emery Hemingway 2023-12-25 14:19:50 +02:00
parent d146b213b4
commit 18f8f8e6b2
1 changed files with 8 additions and 6 deletions

View File

@ -63,9 +63,13 @@ proc match(text: string; p: var ParseState)
const parser = peg("Schema", p: ParseState):
Schema <- ?Annotation * S * +(Clause * S) * !1
S <- *{ ' ', '\t', '\r', '\n' }
Clause <- (Version | EmbeddedTypeName | Include | Definition) * S * '.'
Schema <- +Clause * S * !1
Clause <- *LineComment * S * (Version | EmbeddedTypeName | Include | Definition) * S * '.'
LineComment <- S * '#' * @'\n'
Version <- "version" * S * >(*Digit):
if parseInt($1) != 1: fail()
@ -140,7 +144,7 @@ const parser = peg("Schema", p: ParseState):
var node = initRecord(toSymbol("and"), toPreserve takeStackAt())
pushStack node
Pattern <- SimplePattern | CompoundPattern
Pattern <- ?Annotation * (SimplePattern | CompoundPattern)
SimplePattern <-
AnyPattern |
@ -263,8 +267,6 @@ const parser = peg("Schema", p: ParseState):
Comment <- '#' * @'\n'
S <- *(Space | Comment)
symbol <- Preserves.Symbol
nonSymbolAtom <-
@ -278,7 +280,7 @@ const parser = peg("Schema", p: ParseState):
Value <- Preserves.Value:
discard
Annotation <- '@' * Value
Annotation <- S * '@' * Value
proc match(text: string; p: var ParseState) =
let match = parser.match(text, p)