Grammar Well

Home Documentation Editor View the Source Install the Package
import * from whitespace;
import * from json;
import * from "./my-language.well";
Imports
on:import {
    let parses = 0;
export function GetParseCount(){
    return parses;
}
}on:new {
parses++;
}
Lifecycle Hooks
lexer {
    [string]
        - import singleQuoteString, doubleQuoteString
[singleQuoteString]
    - when r:{'} tag "squote" highlight "string" goto singleQuoteStringEnd

[singleQuoteStringEnd]
    - when r:{\\[\\\/bnrft]} tag "escaped"
    - when r:{\\'} tag "quoteEscape"
    - when r:{\\u[A-Fa-f\d]{4}} tag "escaped"
    - when r:{\\.} tag "badEscape"
    - when r:{[^'\\]+} tag "string" highlight "string"
    - when "'" tag "squote" highlight "string" pop

[doubleQuoteString] span {
    [start]
          - when "\""  tag "dquote" highlight "string"
    
    [span]
        - when r:{\\[\\\/bnrft]} tag "escaped" highlight "constant"
        - when r:{\\"} tag "quoteEscape"
        - when r:{\\u[A-Fa-f\d]{4}} tag "escaped" highlight "constant"
        - when r:{\\.} tag "badEscape"
        - when r:{[^"\\]+} tag "string" highlight "string"
    
    [stop]
        - when "\"" tag "dquote" highlight "string"
}
}
Lexer
grammar {
    [Start] 
        |  HelloGoodbye __ Target
[HelloGoodbye]
    | "Hello"
    | "Goodbye"


[Target] 
    | "World" 
    | r:{[a-zA-Z]+}


[__] 
    <ws>
}
Grammar

Table of Contents

Main
  • API
  • Writing Grammars
    • Imports
    • Lifecycle Hooks
    • Lexer
      • Imports
      • Matches
      • Directives
      • Spans
    • Grammar
      • Rules
      • Symbols
      • Post Processors
  • Glossary