switch from tree-sitter to regex
parent
6990b59b9c
commit
cee73f0583
|
@ -194,12 +194,12 @@ dependencies = [
|
|||
"clap",
|
||||
"crossbeam",
|
||||
"ignore",
|
||||
"lazy_static",
|
||||
"pathdiff",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"tree-sitter",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -474,26 +474,6 @@ dependencies = [
|
|||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.0.1"
|
||||
|
@ -512,16 +492,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d18dcb776d3affaba6db04d11d645946d34a69b3172e588af96ce9fecd20faac"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.7.0"
|
||||
|
|
|
@ -11,12 +11,12 @@ anyhow = "1.0"
|
|||
clap = "3.0.0-beta.2"
|
||||
crossbeam = "0.8"
|
||||
ignore = "0.4"
|
||||
lazy_static = "1.4"
|
||||
pathdiff = "0.1"
|
||||
regex = "1.0"
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
toml = "0.5"
|
||||
tree-sitter = "0.17"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "*"
|
||||
|
|
21
build.rs
21
build.rs
|
@ -1,21 +0,0 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
// https://doc.rust-lang.org/cargo/reference/build-scripts.html
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
let dir: PathBuf = ["vendor", "tree-sitter-elm", "src"].iter().collect();
|
||||
|
||||
println!("cargo:rerun-if-changed=vendor/tree-sitter-elm/src/parser.c");
|
||||
cc::Build::new()
|
||||
.include(&dir)
|
||||
.file(dir.join("parser.c"))
|
||||
.compile("tree-sitter-elm");
|
||||
|
||||
println!("cargo:rerun-if-changed=vendor/tree-sitter-elm/src/scanner.cc");
|
||||
cc::Build::new()
|
||||
.include(&dir)
|
||||
.cpp(true)
|
||||
.file(dir.join("scanner.cc"))
|
||||
.compile("tree_sitter_elm_scanner")
|
||||
}
|
|
@ -3,8 +3,5 @@
|
|||
let
|
||||
naersk = pkgs.callPackage sources.naersk { };
|
||||
gitignore = import sources.gitignore { };
|
||||
in naersk.buildPackage {
|
||||
src = gitignore.gitignoreSource ./.;
|
||||
buildInputs = if pkgs.stdenv.isDarwin then [ pkgs.xcbuild ] else [ ];
|
||||
}
|
||||
in naersk.buildPackage (gitignore.gitignoreSource ./.)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
git subtree pull --squash --prefix vendor/tree-sitter-elm https://github.com/Razzeee/tree-sitter-elm master
|
||||
git subtree pull --squash --prefix vendor/elm-spa-example https://github.com/rtfeldman/elm-spa-example master
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use crossbeam::channel;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use serde::Serialize;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use thiserror::Error;
|
||||
|
||||
static IMPORT_QUERY: &str = "(import_clause (import) (upper_case_qid)@import)";
|
||||
|
||||
pub struct ImportFinder {
|
||||
roots: BTreeSet<PathBuf>,
|
||||
|
@ -38,10 +38,6 @@ impl ImportFinder {
|
|||
.context("could not build extensions to scan for")?;
|
||||
builder.types(types);
|
||||
|
||||
let query = tree_sitter::Query::new(get_language(), IMPORT_QUERY)
|
||||
.map_err(TreeSitterError::QueryError)
|
||||
.context("could not instantiate the import query")?;
|
||||
|
||||
let mut out: BTreeMap<String, BTreeSet<FoundImport>> = BTreeMap::new();
|
||||
|
||||
let (parent_results_sender, results_receiver) = channel::unbounded();
|
||||
|
@ -51,10 +47,6 @@ impl ImportFinder {
|
|||
let results_sender = parent_results_sender.clone();
|
||||
let error_sender = parent_error_sender.clone();
|
||||
|
||||
let mut parser = get_parser().unwrap();
|
||||
|
||||
let query = &query;
|
||||
|
||||
Box::new(move |maybe_dir_entry| {
|
||||
let dir_entry = match maybe_dir_entry.context("could not read an entry from a root")
|
||||
{
|
||||
|
@ -71,7 +63,18 @@ impl ImportFinder {
|
|||
return ignore::WalkState::Continue;
|
||||
}
|
||||
|
||||
let source = match fs::read(dir_entry.path()).context("could not read an Elm file")
|
||||
let source_bytes =
|
||||
match fs::read(dir_entry.path()).context("could not read an Elm file") {
|
||||
Ok(s) => s,
|
||||
Err(err) => {
|
||||
#[allow(unused_must_use)]
|
||||
let _ = error_sender.send(err);
|
||||
return ignore::WalkState::Quit;
|
||||
}
|
||||
};
|
||||
|
||||
let source = match std::str::from_utf8(&source_bytes)
|
||||
.context("could not read the source as utf8")
|
||||
{
|
||||
Ok(s) => s,
|
||||
Err(err) => {
|
||||
|
@ -81,42 +84,31 @@ impl ImportFinder {
|
|||
}
|
||||
};
|
||||
|
||||
let parsed = match parser.parse(&source, None) {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
#[allow(unused_must_use)]
|
||||
let _ = error_sender
|
||||
.send(anyhow!("could not parse {:}", dir_entry.path().display()));
|
||||
return ignore::WalkState::Quit;
|
||||
}
|
||||
};
|
||||
lazy_static! {
|
||||
// TODO: maybe faster to use `([^ ]+)` for the match
|
||||
static ref IMPORT_RE: Regex = Regex::new(r"^import +([A-Z][A-Za-z0-9_\.]*)").unwrap();
|
||||
}
|
||||
|
||||
let mut cursor = tree_sitter::QueryCursor::new();
|
||||
|
||||
for match_ in cursor.matches(&query, parsed.root_node(), |_| []) {
|
||||
for capture in match_.captures {
|
||||
let import = match capture
|
||||
.node
|
||||
.utf8_text(&source)
|
||||
.context("could not convert a match to a source string")
|
||||
{
|
||||
Ok(i) => i,
|
||||
#[allow(unused_must_use)]
|
||||
Err(err) => {
|
||||
error_sender.send(err);
|
||||
return ignore::WalkState::Quit;
|
||||
}
|
||||
};
|
||||
// perf idea; keep track of if we've finished the import list and
|
||||
// bail on any further lines once we get there. Since imports
|
||||
// are forbidden after the block at the top of the module, we
|
||||
// shouldn't miss anything by skipping the rest of the lines
|
||||
// in each file!
|
||||
|
||||
for (line_number, line) in source.lines().enumerate() {
|
||||
if let Some(import_module) = IMPORT_RE.captures(line).and_then(|m| m.get(1)) {
|
||||
if let Err(err) = results_sender.send(FoundImport {
|
||||
import: import.to_string(),
|
||||
path: dir_entry.path().to_path_buf(),
|
||||
position: capture.node.start_position(),
|
||||
import: import_module.as_str().to_string(),
|
||||
position: Position {
|
||||
row: line_number + 1,
|
||||
column: import_module.start(),
|
||||
},
|
||||
}) {
|
||||
#[allow(unused_must_use)]
|
||||
let _ = error_sender.send(err.into());
|
||||
return ignore::WalkState::Quit;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,34 +149,11 @@ impl ImportFinder {
|
|||
pub struct FoundImport {
|
||||
pub import: String,
|
||||
pub path: PathBuf,
|
||||
pub position: tree_sitter::Point,
|
||||
pub position: Position,
|
||||
}
|
||||
|
||||
// tree sitter
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_elm() -> tree_sitter::Language;
|
||||
}
|
||||
|
||||
fn get_language() -> tree_sitter::Language {
|
||||
unsafe { tree_sitter_elm() }
|
||||
}
|
||||
|
||||
fn get_parser() -> Result<tree_sitter::Parser, TreeSitterError> {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
|
||||
parser
|
||||
.set_language(get_language())
|
||||
.map_err(TreeSitterError::LanguageError)?;
|
||||
|
||||
Ok(parser)
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
enum TreeSitterError {
|
||||
#[error("language error: {0}")]
|
||||
LanguageError(tree_sitter::LanguageError),
|
||||
|
||||
#[error("query error: {0:?}")]
|
||||
QueryError(tree_sitter::QueryError),
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize)]
|
||||
pub struct Position {
|
||||
pub row: usize,
|
||||
pub column: usize,
|
||||
}
|
||||
|
|
32
src/store.rs
32
src/store.rs
|
@ -1,6 +1,5 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt::{self, Display};
|
||||
use std::fs;
|
||||
|
@ -183,7 +182,7 @@ impl Store {
|
|||
.map(|found| found.path.to_owned())
|
||||
.collect::<BTreeSet<PathBuf>>();
|
||||
|
||||
let mut to_positions: BTreeMap<&PathBuf, tree_sitter::Point> = BTreeMap::new();
|
||||
let mut to_positions: BTreeMap<&PathBuf, importfinder::Position> = BTreeMap::new();
|
||||
|
||||
for import in found_imports.iter() {
|
||||
to_positions.insert(&import.path, import.position);
|
||||
|
@ -192,7 +191,7 @@ impl Store {
|
|||
for file in new_usages.difference(&existing.usages) {
|
||||
out.push(CheckResult {
|
||||
file: file.to_path_buf(),
|
||||
position: to_positions.get(file).map(|p| Point(*p)),
|
||||
position: to_positions.get(file).copied(),
|
||||
import: import.to_string(),
|
||||
error_location: ErrorLocation::InElmSource {
|
||||
hint: existing.hint.as_ref(),
|
||||
|
@ -230,32 +229,11 @@ impl Store {
|
|||
#[derive(Debug, Serialize)]
|
||||
pub struct CheckResult<'a> {
|
||||
file: PathBuf,
|
||||
position: Option<Point>,
|
||||
position: Option<importfinder::Position>,
|
||||
import: String,
|
||||
error_location: ErrorLocation<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Point(tree_sitter::Point);
|
||||
|
||||
impl Serialize for Point {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut state = serializer.serialize_struct("Color", 2)?;
|
||||
state.serialize_field("row", &self.0.row)?;
|
||||
state.serialize_field("column", &self.0.column)?;
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Point {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}:{}", self.0.row, self.0.column)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum ErrorLocation<'a> {
|
||||
|
@ -279,7 +257,7 @@ impl Display for CheckResult<'_> {
|
|||
};
|
||||
|
||||
let position_string = match &self.position {
|
||||
Some(position) => format!(":{}", position),
|
||||
Some(position) => format!(":{}:{}", position.row, position.column),
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
# https://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.txt]
|
||||
indent_size = 4
|
||||
|
||||
[*.md]
|
||||
insert_final_newline = false
|
||||
trim_trailing_whitespace = false
|
|
@ -1 +0,0 @@
|
|||
/src/** linguist-vendored
|
|
@ -1 +0,0 @@
|
|||
github: [razzeee]
|
|
@ -1,30 +0,0 @@
|
|||
name: Test full Linux
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
node-version: [10]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Npm install
|
||||
run: |
|
||||
npm i
|
||||
- name: Unit tests
|
||||
run: |
|
||||
npx tree-sitter test
|
||||
- name: Test examples
|
||||
continue-on-error: true
|
||||
run: |
|
||||
script/parse-examples-full
|
|
@ -1,29 +0,0 @@
|
|||
name: Test OSX and Linux
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest]
|
||||
node-version: [10, 12, 14]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Npm install
|
||||
run: |
|
||||
npm i
|
||||
- name: Unit tests
|
||||
run: |
|
||||
npx tree-sitter test
|
||||
- name: Test examples
|
||||
run: |
|
||||
script/parse-examples
|
|
@ -1,13 +0,0 @@
|
|||
package-lock.json
|
||||
node_modules
|
||||
build
|
||||
*.log
|
||||
prebuilds
|
||||
.idea
|
||||
.vscode/ipch
|
||||
|
||||
# Examples generated during automated tests
|
||||
examples/**
|
||||
examples-full/**
|
||||
!examples/Basic.elm
|
||||
!examples/Test.elm
|
|
@ -1,8 +0,0 @@
|
|||
.vscode
|
||||
test
|
||||
elm-stuff
|
||||
examples
|
||||
examples-full
|
||||
build
|
||||
prebuilds
|
||||
script
|
|
@ -1,33 +0,0 @@
|
|||
language: node_js
|
||||
|
||||
sudo: false
|
||||
|
||||
node_js:
|
||||
- "10"
|
||||
|
||||
os:
|
||||
- linux
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: osx
|
||||
osx_image: xcode9.2
|
||||
- os: linux
|
||||
env: CXX=clang++
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- /^v.*$/
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
script: npm run prebuild && npm run prebuild:upload -u ${PREBUILD_UPLOAD}
|
||||
skip_cleanup: true
|
||||
on:
|
||||
all_branches: true
|
||||
tags: true
|
||||
|
||||
env:
|
||||
global:
|
||||
secure: "NTNcwplBIpGejo1ciZlkVFLGJ14nbvRf42/evwUU61gvuMe0xrCSCgoEUTL9vNJUBotG2WqwZnlfScop1Ag5E/9H/jFvJ/1UoJ99Zs+b0A+vOPgMTXjYqW+GYfAC/3HvQPDq+32Xe0a0Tq+PxuKMu0jskO1vspQMRvcYaglIkCGIO6uzwiolViTehVhdhZw1gjv+L37cXsBmccXI9j9TsYe+XceUOqi3/efik6gPcH1KJZGa5jdobVmUBhV524drzO51+q5eigAcUUP0Z8IhXrjAvB50C1Y/Opao8AYhc2IHCx6CEu6T2IeAjXaFghFt4Z+g2fzJgkdyO4ap4lweuQ/e4MHm5jBBVkBAORqtsukz/vJhQOoe4Nu9kLPUl+biW2NS3Tj+Usqb9tuSmyiw5EFeCDhMcg3M9cTLIs4ZibgYnUN/7IjsLsnTYrQ1Wht2rabn+KOfjatkVEJMnYFrizsQo0AQ7edi6X9ncPUNAViQTvpyPxknMWGEdyva4YWUcuH7SxsDqQtEeTqNMXJ+FglRuZzzDIXRn6FaxUUTpBFtuj8jblL1C9f2UvlUrmyqDJ5bBoFmeRmffbr/u357TiQybQQyQ3GroSm/KGPQjSoQFMGCgKAQv64Y/pfgLgw5PbUf5agjNNbxcJoeCFT2ceGOP8ucwHzACCTng6ZtbDU="
|
|
@ -1,42 +0,0 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "parse",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "build",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "parse-1",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "parse-asset",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "parse-article",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "parse-basic",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "parse-test",
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
1. Increase the version number in the package.json
|
||||
2. Push the code to master
|
||||
3. Run `npm publish`
|
||||
4. Create a release on github with the name being the version number from before prefixed with `v` for e.g. `v1.1.0`
|
||||
5. Enjoy, builds should appear on that release as soon as the CI is done running them.
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Kolja Lampe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -1,32 +0,0 @@
|
|||
[![Build Status](https://travis-ci.org/Razzeee/tree-sitter-elm.svg?branch=master)](https://travis-ci.org/Razzeee/tree-sitter-elm)
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/tif3gafcxp85swih/branch/master?svg=true)](https://ci.appveyor.com/project/Razzeee/tree-sitter-elm/branch/master)
|
||||
|
||||
# Elm tree sitter
|
||||
|
||||
## Why am I doing this?
|
||||
|
||||
I believe that Elm would greatly benefit from better tooling, the ultimate goal is to write a language server integration. This is a possible building block for that.
|
||||
|
||||
What it brings to the table:
|
||||
|
||||
- Very fast parsing, should enable parsing on each keystroke
|
||||
- Resilient, even if you use wrong syntax, most of the file should still be recognized alright
|
||||
- Should also be useful to the elm atom maintainers, as atom is using tree sitter as the new default for code highlighting (our ast might be too expressive). Highlight implementation still needs to be done if wanted.
|
||||
|
||||
## What is this tested with?
|
||||
|
||||
This is tested against the tests included in the repo and:
|
||||
|
||||
- [elm-spa-example](https://github.com/rtfeldman/elm-spa-example)
|
||||
- All core elm packets from [here](https://github.com/elm)
|
||||
|
||||
So it should work fine for a fair amount of code. What's not tested right now is behavior in error cases.
|
||||
|
||||
## Thanks
|
||||
|
||||
Very very big thanks goes out to @klazuka and the people of [intellij-elm](https://github.com/klazuka/intellij-elm/) as I basically stole [how they're creating their parser](https://github.com/klazuka/intellij-elm/blob/master/src/main/grammars/ElmParser.bnf) minus the GLSL implementation.
|
||||
|
||||
## Want to help?
|
||||
|
||||
Help writing some tests or simply find valid elm files, that fail parsing.
|
||||
Test are located in the `test` folder and separated in parser tests and highlighting tests.
|
|
@ -1,28 +0,0 @@
|
|||
image: Visual Studio 2017
|
||||
|
||||
environment:
|
||||
NODEJS_VERSION: "10"
|
||||
PREBUILD_UPLOAD:
|
||||
secure: /JesINEpGYP12bsjCPZEozyGOBGXj48nVKYqcS7kHO+aiL8+R/ko8vmh3mo5aQvw
|
||||
|
||||
platform:
|
||||
- x64
|
||||
- x86
|
||||
|
||||
install:
|
||||
- ps: Install-Product node $env:NODEJS_VERSION $env:Platform
|
||||
- node --version
|
||||
- npm --version
|
||||
- npm install
|
||||
|
||||
test_script:
|
||||
- npm run test-windows
|
||||
|
||||
build: off
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- /^v.*$/
|
||||
|
||||
deploy_script: IF "%APPVEYOR_REPO_TAG%" == "true" (npm run prebuild && npm run prebuild:upload -u %PREBUILD_UPLOAD%)
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_elm_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
],
|
||||
"sources": [
|
||||
"src/parser.c",
|
||||
"src/binding.cc",
|
||||
"src/scanner.cc"
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
module Main exposing (Msg(..), main, update, view)
|
||||
|
||||
import Browser
|
||||
import Html exposing (Html, button, div, text)
|
||||
import Html.Events exposing (onClick)
|
||||
|
||||
|
||||
main =
|
||||
Browser.sandbox { init = 0, update = update, view = view }
|
||||
|
||||
|
||||
type Msg
|
||||
= Increment
|
||||
| Decrement
|
||||
|
||||
|
||||
update msg model =
|
||||
case msg of
|
||||
Increment ->
|
||||
model + 1
|
||||
|
||||
Decrement ->
|
||||
model - 1
|
||||
|
||||
|
||||
view model =
|
||||
div []
|
||||
[ button [ onClick Decrement ] [ text "-" ]
|
||||
, div [] [ text (String.fromInt model) ]
|
||||
, button [ onClick Increment ] [ text "+" ]
|
||||
]
|
|
@ -1,8 +0,0 @@
|
|||
enum key dict =
|
||||
custom key <| \stringList ->
|
||||
case stringList of
|
||||
[str] ->
|
||||
Dict.get str dict
|
||||
|
||||
_ ->
|
||||
Nothing
|
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -1,13 +0,0 @@
|
|||
try {
|
||||
module.exports = require("./build/Release/tree_sitter_elm_binding");
|
||||
} catch (error) {
|
||||
try {
|
||||
module.exports = require("./build/Debug/tree_sitter_elm_binding");
|
||||
} catch (_) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("./src/node-types.json");
|
||||
} catch (_) {}
|
|
@ -1,42 +0,0 @@
|
|||
{
|
||||
"name": "tree-sitter-elm",
|
||||
"version": "4.3.1",
|
||||
"description": "Tree sitter definitions for elm",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"lexer"
|
||||
],
|
||||
"author": "Razze",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.14.2",
|
||||
"prebuild-install": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@asgerf/dts-tree-sitter": "^0.1.0",
|
||||
"prebuild": "^10.0.1",
|
||||
"tree-sitter-cli": "^0.17.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tree-sitter generate && node-gyp build --debug",
|
||||
"install": "prebuild-install || node-gyp rebuild",
|
||||
"prebuild": "prebuild -r electron --all --strip --verbose",
|
||||
"prebuild:upload": "prebuild --upload-all",
|
||||
"parse-basic": "tree-sitter parse ./examples/Basic.elm",
|
||||
"parse-test": "tree-sitter parse --debug ./examples/test.elm",
|
||||
"test": "tree-sitter test && script/parse-examples",
|
||||
"test-full": "tree-sitter test && script/parse-examples-full",
|
||||
"test-windows": "tree-sitter test",
|
||||
"test-only": "tree-sitter test"
|
||||
},
|
||||
"repository": "https://github.com/razzeee/tree-sitter-elm",
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.elm",
|
||||
"file-types": [
|
||||
"elm"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,67 +0,0 @@
|
|||
; Keywords
|
||||
[
|
||||
"if"
|
||||
"then"
|
||||
"else"
|
||||
"let"
|
||||
"in"
|
||||
] @keyword.control.elm
|
||||
(case) @keyword.control.elm
|
||||
(of) @keyword.control.elm
|
||||
|
||||
(colon) @keyword.other.elm
|
||||
(pipe) @keyword.other.elm
|
||||
(backslash) @keyword.other.elm
|
||||
(as) @keyword.other.elm
|
||||
(port) @keyword.other.elm
|
||||
(exposing) @keyword.other.elm
|
||||
(alias) @keyword.other.elm
|
||||
(infix) @keyword.other.elm
|
||||
|
||||
(arrow) @keyword.operator.arrow.elm
|
||||
|
||||
(port) @keyword.other.port.elm
|
||||
|
||||
(type_annotation(lower_case_identifier) @entity.name.function.elm)
|
||||
(port_annotation(lower_case_identifier) @entity.name.function.elm)
|
||||
|
||||
(operator_identifier) @keyword.operator.elm
|
||||
(eq) @keyword.operator.assignment.elm
|
||||
|
||||
|
||||
(record_type(left_brace) @punctuation.section.braces.begin)
|
||||
(record_type(right_brace) @punctuation.section.braces.end)
|
||||
|
||||
|
||||
(import) @meta.import.elm
|
||||
(module) @keyword.other.elm
|
||||
|
||||
(number_constant_expr) @constant.numeric.elm
|
||||
|
||||
(comma) @punctuation.separator.comma.elm
|
||||
|
||||
(type) @keyword.type.elm
|
||||
(type_declaration(upper_case_identifier) @storage.type.elm)
|
||||
(union_variant(upper_case_identifier) @constant.type-constructor.elm)
|
||||
|
||||
; comments
|
||||
(line_comment) @comment.line.double-dash.elm
|
||||
(block_comment) @comment.block.elm
|
||||
|
||||
; strings
|
||||
(string_escape) @constant.character.escape.elm
|
||||
|
||||
(open_quote) @punctuation.definition.string.begin.elm
|
||||
(close_quote) @punctuation.definition.string.end.elm
|
||||
(regular_string_part) @string.elm
|
||||
|
||||
(open_char) @punctuation.definition.char.begin.elm
|
||||
(close_char) @punctuation.definition.char.end.elm
|
||||
|
||||
|
||||
; glsl
|
||||
(glsl_begin) @entity.glsl.bracket.elm
|
||||
|
||||
(glsl_content) @source.glsl
|
||||
|
||||
(glsl_end) @entity.glsl.bracket.elm
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
(value_declaration) @local.scope
|
||||
(type_alias_declaration) @local.scope
|
||||
(type_declaration) @local.scope
|
||||
(type_annotation) @local.scope
|
||||
(port_annotation) @local.scope
|
||||
(infix_declaration) @local.scope
|
||||
(let_in_expr) @local.scope
|
||||
|
||||
(function_declaration_left (lower_pattern (lower_case_identifier)) @local.definition)
|
||||
(function_declaration_left (lower_case_identifier) @local.definition)
|
||||
|
||||
(value_expr(value_qid(upper_case_identifier)) @local.reference)
|
||||
(value_expr(value_qid(lower_case_identifier)) @local.reference)
|
||||
(type_ref (upper_case_qid) @local.reference)
|
Binary file not shown.
|
@ -1,18 +0,0 @@
|
|||
[
|
||||
"rtfeldman/elm-spa-example",
|
||||
"andys8/vim-emulation",
|
||||
"DoctypeRosenthal/mindmap",
|
||||
"RalfNorthman/adding-boxes",
|
||||
"mosmos21/elm-todo",
|
||||
"wolmir/conta-invaders",
|
||||
"ryannhg/love-your-humans",
|
||||
"smith-30/elm-login",
|
||||
"jxxcarlson/elm-shared-state",
|
||||
"doubledup/initiative_tracker",
|
||||
"RaoKrishna/elm-poc",
|
||||
"visotype/state-machine",
|
||||
"Chadtech/elm-europe-2019-talk",
|
||||
"mathiajusth/gravity",
|
||||
"Vynlar/time-tracker",
|
||||
"xbmc/elm-chorus"
|
||||
]
|
|
@ -1,14 +0,0 @@
|
|||
[
|
||||
"HAN-ASD-DT/priority-queue",
|
||||
"HAN-ASD-DT/rsa",
|
||||
"abradley2/form-controls",
|
||||
"abradley2/form-fields",
|
||||
"altjsus/elm-airtable",
|
||||
"nik-garmash/elm-test",
|
||||
"not1602/elm-feather",
|
||||
"ozyinc/elm-sortable-table-with-row-id",
|
||||
"peterszerzo/elm-natural-ui",
|
||||
"m-mullins/elm-console",
|
||||
"nathanjohnson320/elm-ui-components",
|
||||
"proda-ai/elm-logger"
|
||||
]
|
|
@ -1,5 +0,0 @@
|
|||
examples-full/elm-browser/examples/drag.elm
|
||||
examples-full/elm-ui/tests-rendering/automation/templates/Run.elm
|
||||
examples-full/Chadtech/elm-imperative-porting/examples/find-primes.elm
|
||||
examples-full/ianmackenzie/elm-geometry-prerelease/src/Geometry/Examples/Expect.elm
|
||||
examples-full/ianmackenzie/elm-geometry-prerelease/doc/interactive/EllipticalArc2d/FromEndpoints.elm
|
|
@ -1,2 +0,0 @@
|
|||
examples/elm-browser/examples/drag.elm
|
||||
examples/elm-ui/tests-rendering/automation/templates/Run.elm
|
|
@ -1,69 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
function checkout_at() {
|
||||
repo=$1; url=$2; sha=$3
|
||||
if [ ! -d "$repo" ]; then
|
||||
git clone "https://github.com/$url" "$repo"
|
||||
fi
|
||||
|
||||
pushd "$repo"
|
||||
git fetch && git reset --hard "$sha"
|
||||
popd
|
||||
}
|
||||
|
||||
checkout_at "examples/elm-spa-example" "rtfeldman/elm-spa-example" "c8c3201ec0488f17c1245e1fd2293ba5bc0748d5"
|
||||
checkout_at "examples/elm-browser" "elm/browser" "1d28cd625b3ce07be6dfad51660bea6de2c905f2"
|
||||
checkout_at "examples/elm-bytes" "elm/bytes" "2bce2aeda4ef18c3dcccd84084647d22a7af36a6"
|
||||
checkout_at "examples/elm-core" "elm/core" "22eefd207e7a63daab215ae497f683ff2319c2ca"
|
||||
checkout_at "examples/elm-file" "elm/file" "e4ca3864c93a5e766e24ed6916174753567b2f59"
|
||||
checkout_at "examples/elm-html" "elm/html" "94c079007f8a7ed282d5b53f4a49101dd0b6cf99"
|
||||
checkout_at "examples/elm-http" "elm/http" "81b6fdc67d8e5fb25644fd79e6b0edbe2e14e474"
|
||||
checkout_at "examples/elm-json" "elm/json" "af344039e8c014b06ed0f73ac3ffd22c60d30876"
|
||||
checkout_at "examples/elm-parser" "elm/parser" "7506b07eaa93a93d13b508b948c016105b0953c8"
|
||||
checkout_at "examples/elm-project-metadata-utils" "elm/project-metadata-utils" "b075be15046e151e36a79950412c4cb703605aeb"
|
||||
checkout_at "examples/elm-random" "elm/random" "ecf97bb43f0d5cd75243428f69f45323957bda25"
|
||||
checkout_at "examples/elm-regex" "elm/regex" "8810c41fb17ddf89165665489be213f44070bc4a"
|
||||
checkout_at "examples/elm-svg" "elm/svg" "08bd432990862bab5b840654dd437fbb2e6176e7"
|
||||
checkout_at "examples/elm-time" "elm/time" "dc3b75b7366e59b99962706f7bf064d3634a4bba"
|
||||
checkout_at "examples/elm-url" "elm/url" "8602f4b48653ca93b6991fe2c6a764523cd1d462"
|
||||
checkout_at "examples/elm-virtual-dom" "elm/virtual-dom" "5a5bcf48720bc7d53461b3cd42a9f19f119c5503"
|
||||
checkout_at "examples/elm-ui" "mdgriffith/elm-ui" "7aa0e015499d4975a4dda02c2629ee21ec18eac3"
|
||||
checkout_at "examples/elm-markup" "mdgriffith/elm-markup" "e4b88aa04c7e9bafd02b5436c311cf07e255dab1"
|
||||
checkout_at "examples/elm-visualization" "gampleman/elm-visualization" "68631a3dbf840d30bc642e605a49ccd8040504f6"
|
||||
|
||||
|
||||
skipped_files=()
|
||||
all_examples=$(find examples -name '*.elm')
|
||||
known_failures=$(cat script/known-failures.txt)
|
||||
examples_to_parse=$(
|
||||
for example in $all_examples; do
|
||||
if [[ ! $known_failures == *$example* ]]; then
|
||||
echo $example
|
||||
else
|
||||
skipped_files+=($example)
|
||||
fi
|
||||
done
|
||||
)
|
||||
|
||||
start=`date +%s.%N`
|
||||
tree_sitter_report=$(echo $examples_to_parse | xargs -n 1000 npx tree-sitter parse -q)
|
||||
end=`date +%s.%N`
|
||||
|
||||
ret_code=$?
|
||||
|
||||
echo -e "-----------------------------------------------------------------\n$tree_sitter_report \n -----------------------------------------------------------------\n"
|
||||
|
||||
errors=$( echo "$tree_sitter_report" | sed '/^\s*$/d' | wc -l )
|
||||
|
||||
skipped=$( echo ${#skipped_files[@]} )
|
||||
tried_to_parse=$( echo "$examples_to_parse" | wc -w )
|
||||
parsed=$(bc -l <<< "$tried_to_parse-$errors")
|
||||
total=$((tried_to_parse+skipped))
|
||||
percent=$(bc -l <<< "100*$parsed/$total")
|
||||
runtime=$( echo "$end - $start" | bc -l )
|
||||
|
||||
printf "Successfully parsed %d of %d files (%.2f%%)\nSkipped: %d Failed: %d\nTook: %s\n" $parsed $total $percent $skipped $errors $runtime
|
||||
|
||||
exit $ret_code
|
|
@ -1,67 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
function checkout() {
|
||||
repo=$1; url=$2;
|
||||
if [ ! -d "$repo" ]; then
|
||||
git clone "https://github.com/$url" "$repo"
|
||||
fi
|
||||
|
||||
pushd "$repo"
|
||||
git fetch && git reset --hard HEAD
|
||||
popd
|
||||
}
|
||||
|
||||
echo "Getting libs"
|
||||
libs_to_parse=$(grep -Po '"name":.*?[^\\]",' ./script/search.json | perl -pe 's/"name": "//; s/^"//; s/",$//')
|
||||
libs_not_to_parse=$(grep -Po '".+"' ./script/error-packages.json | perl -pe 's/^"//; s/"$//')
|
||||
|
||||
for lib in $libs_to_parse; do
|
||||
if [[ ! $libs_not_to_parse == *$lib* ]]; then
|
||||
echo $lib
|
||||
checkout "examples-full/$lib" "$lib"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Getting applications"
|
||||
applications_to_parse=$(grep -Po '".+"' ./script/applications.json | perl -pe 's/^"//; s/"$//')
|
||||
|
||||
for project in $applications_to_parse; do
|
||||
echo $project
|
||||
checkout "examples-full/$project" "$project"
|
||||
done
|
||||
|
||||
skipped_files=()
|
||||
all_examples=$(find examples-full -name '*.elm')
|
||||
known_failures=$(cat script/known-failures.txt)
|
||||
examples_to_parse=$(
|
||||
for example in $all_examples; do
|
||||
if [[ ! $known_failures == *$example* ]]; then
|
||||
echo $example
|
||||
else
|
||||
skipped_files+=($example)
|
||||
fi
|
||||
done
|
||||
)
|
||||
|
||||
start=`date +%s.%N`
|
||||
tree_sitter_report=$(echo $examples_to_parse | xargs -n 1000 npx tree-sitter parse -q)
|
||||
end=`date +%s.%N`
|
||||
|
||||
ret_code=$?
|
||||
|
||||
echo -e "-----------------------------------------------------------------\n$tree_sitter_report \n -----------------------------------------------------------------\n"
|
||||
|
||||
errors=$( echo "$tree_sitter_report" | sed '/^\s*$/d' | wc -l )
|
||||
|
||||
skipped=$( echo ${#skipped_files[@]} )
|
||||
tried_to_parse=$( echo "$examples_to_parse" | wc -w )
|
||||
parsed=$(bc -l <<< "$tried_to_parse-$errors")
|
||||
total=$((tried_to_parse+skipped))
|
||||
percent=$(bc -l <<< "100*$parsed/$total" )
|
||||
runtime=$( echo "$end - $start" | bc -l )
|
||||
|
||||
printf "Successfully parsed %d of %d files (%.2f%%)\nSkipped: %d Failed: %d\nTook: %s\n" $parsed $total $percent $skipped $errors $runtime
|
||||
|
||||
exit $ret_code
|
File diff suppressed because it is too large
Load Diff
|
@ -1,28 +0,0 @@
|
|||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_elm();
|
||||
|
||||
namespace {
|
||||
|
||||
NAN_METHOD(New) {}
|
||||
|
||||
void Init(Local<Object> exports, Local<Object> module) {
|
||||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
||||
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
||||
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
|
||||
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
||||
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_elm());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("elm").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_elm_binding, Init)
|
||||
|
||||
} // namespace
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,481 +0,0 @@
|
|||
#include <tree_sitter/parser.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cwctype>
|
||||
#include <cstring>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
enum TokenType
|
||||
{
|
||||
VIRTUAL_END_DECL,
|
||||
VIRTUAL_OPEN_SECTION,
|
||||
VIRTUAL_END_SECTION,
|
||||
MINUS_WITHOUT_TRAILING_WHITESPACE,
|
||||
BLOCK_COMMENT,
|
||||
LINE_COMMENT,
|
||||
OPEN_QUOTE,
|
||||
CLOSE_QUOTE,
|
||||
OPEN_QUOTE_MULTILINE,
|
||||
CLOSE_QUOTE_MULTILINE,
|
||||
GLSL_CONTENT
|
||||
};
|
||||
|
||||
struct Scanner
|
||||
{
|
||||
Scanner() {}
|
||||
|
||||
unsigned serialize(char *buffer)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
size_t stack_size = runback.size();
|
||||
if (stack_size > UINT8_MAX)
|
||||
stack_size = UINT8_MAX;
|
||||
buffer[i++] = stack_size;
|
||||
|
||||
memcpy(&buffer[i], runback.data(), stack_size);
|
||||
i += stack_size;
|
||||
|
||||
buffer[i++] = indent_length;
|
||||
buffer[i++] = in_string;
|
||||
|
||||
vector<uint16_t>::iterator
|
||||
iter = indent_length_stack.begin() + 1,
|
||||
end = indent_length_stack.end();
|
||||
|
||||
for (; iter != end && i < TREE_SITTER_SERIALIZATION_BUFFER_SIZE; ++iter)
|
||||
{
|
||||
buffer[i++] = *iter;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void deserialize(const char *buffer, unsigned length)
|
||||
{
|
||||
runback.clear();
|
||||
indent_length_stack.clear();
|
||||
indent_length_stack.push_back(0);
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
size_t runback_count = (uint8_t)buffer[i++];
|
||||
runback.resize(runback_count);
|
||||
memcpy(runback.data(), &buffer[i], runback_count);
|
||||
i += runback_count;
|
||||
indent_length = buffer[i++];
|
||||
in_string = buffer[i++];
|
||||
for (; i < length; i++)
|
||||
{
|
||||
indent_length_stack.push_back(buffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void advance(TSLexer *lexer)
|
||||
{
|
||||
lexer->advance(lexer, false);
|
||||
}
|
||||
|
||||
void skip(TSLexer *lexer)
|
||||
{
|
||||
lexer->advance(lexer, true);
|
||||
}
|
||||
|
||||
bool isElmSpace(TSLexer *lexer)
|
||||
{
|
||||
return lexer->lookahead == ' ' || lexer->lookahead == '\r' || lexer->lookahead == '\n';
|
||||
}
|
||||
|
||||
bool scan_comment(TSLexer *lexer)
|
||||
{
|
||||
lexer->mark_end(lexer);
|
||||
if (lexer->lookahead != '{')
|
||||
return false;
|
||||
|
||||
advance(lexer);
|
||||
if (lexer->lookahead != '-')
|
||||
return false;
|
||||
|
||||
advance(lexer);
|
||||
|
||||
while (true)
|
||||
{
|
||||
switch (lexer->lookahead)
|
||||
{
|
||||
case '{':
|
||||
scan_comment(lexer);
|
||||
break;
|
||||
case '-':
|
||||
advance(lexer);
|
||||
if (lexer->lookahead == '}')
|
||||
{
|
||||
advance(lexer);
|
||||
runback.clear();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case '\0':
|
||||
return true;
|
||||
default:
|
||||
advance(lexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool scan_quote(TSLexer *lexer, TokenType quoteToken, TokenType quoteTokenMultiline, bool closingQuote)
|
||||
{
|
||||
uint8_t newInString = closingQuote ? 0 : 1;
|
||||
uint8_t newInStringMultiline = closingQuote ? 0 : 2;
|
||||
|
||||
if (lexer->lookahead == '"')
|
||||
{
|
||||
advance(lexer);
|
||||
lexer->mark_end(lexer);
|
||||
if (lexer->lookahead == '"')
|
||||
{
|
||||
advance(lexer);
|
||||
|
||||
if (lexer->lookahead == '"')
|
||||
{
|
||||
advance(lexer);
|
||||
lexer->result_symbol = quoteTokenMultiline;
|
||||
in_string = newInStringMultiline;
|
||||
lexer->mark_end(lexer);
|
||||
return true;
|
||||
}
|
||||
else if (in_string != 2)
|
||||
{
|
||||
lexer->result_symbol = quoteToken;
|
||||
in_string = newInString;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (in_string != 2)
|
||||
{
|
||||
|
||||
lexer->result_symbol = quoteToken;
|
||||
in_string = newInString;
|
||||
lexer->mark_end(lexer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int checkForIn(TSLexer *lexer, const bool *valid_symbols)
|
||||
{
|
||||
// Are we at the end of a let (in) declaration
|
||||
if (valid_symbols[VIRTUAL_END_SECTION] && lexer->lookahead == 'i')
|
||||
{
|
||||
skip(lexer);
|
||||
|
||||
if (lexer->lookahead == 'n')
|
||||
{
|
||||
skip(lexer);
|
||||
if (isElmSpace(lexer) || lexer->lookahead == 0)
|
||||
{
|
||||
return 2; // Success
|
||||
}
|
||||
return 1; //Partial
|
||||
}
|
||||
return 1; //Partial
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool scan(TSLexer *lexer, const bool *valid_symbols)
|
||||
{
|
||||
// First handle eventual runback tokens, we saved on a previous scan op
|
||||
if (!runback.empty() && runback.back() == 0 && valid_symbols[VIRTUAL_END_DECL])
|
||||
{
|
||||
runback.pop_back();
|
||||
lexer->result_symbol = VIRTUAL_END_DECL;
|
||||
return true;
|
||||
}
|
||||
if (!runback.empty() && runback.back() == 1 && valid_symbols[VIRTUAL_END_SECTION])
|
||||
{
|
||||
runback.pop_back();
|
||||
lexer->result_symbol = VIRTUAL_END_SECTION;
|
||||
return true;
|
||||
}
|
||||
runback.clear();
|
||||
|
||||
// Check if we have newlines and how much indentation
|
||||
bool has_newline = false;
|
||||
bool found_in = false;
|
||||
lexer->mark_end(lexer);
|
||||
while (true)
|
||||
{
|
||||
if (lexer->lookahead == ' ')
|
||||
{
|
||||
skip(lexer);
|
||||
|
||||
if (lexer->lookahead == '\n')
|
||||
{
|
||||
skip(lexer);
|
||||
has_newline = true;
|
||||
indent_length = 0;
|
||||
while (true)
|
||||
{
|
||||
if (lexer->lookahead == ' ')
|
||||
{
|
||||
indent_length++;
|
||||
skip(lexer);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (checkForIn(lexer, valid_symbols) == 2)
|
||||
{
|
||||
lexer->result_symbol = VIRTUAL_END_SECTION;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lexer->lookahead == '\n')
|
||||
{
|
||||
skip(lexer);
|
||||
has_newline = true;
|
||||
indent_length = 0;
|
||||
while (true)
|
||||
{
|
||||
if (lexer->lookahead == ' ')
|
||||
{
|
||||
indent_length++;
|
||||
skip(lexer);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (lexer->lookahead == '\r')
|
||||
{
|
||||
skip(lexer);
|
||||
indent_length = 0;
|
||||
has_newline = true;
|
||||
}
|
||||
else if (lexer->lookahead == 0)
|
||||
{
|
||||
if (valid_symbols[VIRTUAL_END_DECL])
|
||||
{
|
||||
lexer->result_symbol = VIRTUAL_END_DECL;
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (isElmSpace(lexer))
|
||||
{
|
||||
skip(lexer);
|
||||
}
|
||||
|
||||
if (has_newline && checkForIn(lexer, valid_symbols) == 2)
|
||||
{
|
||||
found_in = true;
|
||||
}
|
||||
|
||||
// Handle minus without a whitespace for negate and line comments as both start with '-'
|
||||
if (valid_symbols[MINUS_WITHOUT_TRAILING_WHITESPACE] || valid_symbols[LINE_COMMENT])
|
||||
{
|
||||
if (in_string == 0 && lexer->lookahead == '-')
|
||||
{
|
||||
advance(lexer);
|
||||
auto lookahead = lexer->lookahead;
|
||||
if ((lookahead >= 'a' && lookahead <= 'z') || (lookahead >= 'A' && lookahead <= 'Z') || lookahead == '(')
|
||||
{
|
||||
lexer->result_symbol = MINUS_WITHOUT_TRAILING_WHITESPACE;
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (in_string == 0 && lexer->lookahead == '-') // Handle line comment if we're not in a string
|
||||
{
|
||||
advance(lexer);
|
||||
lexer->result_symbol = LINE_COMMENT;
|
||||
// Take everything until the line or the file ends
|
||||
while (lexer->lookahead != '\n' && lexer->lookahead != '\0')
|
||||
{
|
||||
advance(lexer);
|
||||
}
|
||||
runback.clear();
|
||||
lexer->mark_end(lexer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Open section if the grammar lets us but only push to indent stack if we go further down in the stack
|
||||
if (valid_symbols[VIRTUAL_OPEN_SECTION])
|
||||
{
|
||||
if (indent_length > indent_length_stack.back())
|
||||
{
|
||||
indent_length_stack.push_back(indent_length);
|
||||
}
|
||||
lexer->result_symbol = VIRTUAL_OPEN_SECTION;
|
||||
return true;
|
||||
}
|
||||
else if (has_newline)
|
||||
{
|
||||
// We had a newline now it's time to check if we need to add multiple tokens to get back up to the right level
|
||||
runback.clear();
|
||||
|
||||
while (indent_length <= indent_length_stack.back())
|
||||
{
|
||||
if (indent_length == indent_length_stack.back())
|
||||
{
|
||||
if (found_in)
|
||||
{
|
||||
runback.push_back(1);
|
||||
found_in = false;
|
||||
break;
|
||||
}
|
||||
runback.push_back(0);
|
||||
break;
|
||||
}
|
||||
else if (indent_length < indent_length_stack.back())
|
||||
{
|
||||
indent_length_stack.pop_back();
|
||||
runback.push_back(1);
|
||||
found_in = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Needed for some of the more weird cases where let is in the same line as everything before the in in the next line
|
||||
if (found_in)
|
||||
{
|
||||
runback.push_back(1);
|
||||
found_in = false;
|
||||
}
|
||||
// Our list is the wrong way around, reverse it
|
||||
std::reverse(runback.begin(), runback.end());
|
||||
// Handle the first runback token if we have them, if there are more they will be handled on the next scan operation
|
||||
if (!runback.empty() && runback.back() == 0 && valid_symbols[VIRTUAL_END_DECL])
|
||||
{
|
||||
runback.pop_back();
|
||||
lexer->result_symbol = VIRTUAL_END_DECL;
|
||||
return true;
|
||||
}
|
||||
else if (!runback.empty() && runback.back() == 1 && valid_symbols[VIRTUAL_END_SECTION])
|
||||
{
|
||||
runback.pop_back();
|
||||
lexer->result_symbol = VIRTUAL_END_SECTION;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle block comments if we're not in a string
|
||||
if (in_string == 0 && valid_symbols[BLOCK_COMMENT] && scan_comment(lexer))
|
||||
{
|
||||
lexer->mark_end(lexer);
|
||||
lexer->result_symbol = BLOCK_COMMENT;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle string quotes for multiline and normal strings
|
||||
if (in_string == 0 && (valid_symbols[OPEN_QUOTE] || valid_symbols[OPEN_QUOTE_MULTILINE]))
|
||||
{
|
||||
return scan_quote(lexer, OPEN_QUOTE, OPEN_QUOTE_MULTILINE, false);
|
||||
}
|
||||
if (in_string != 0 && (valid_symbols[CLOSE_QUOTE] || valid_symbols[CLOSE_QUOTE_MULTILINE]))
|
||||
{
|
||||
return scan_quote(lexer, CLOSE_QUOTE, CLOSE_QUOTE_MULTILINE, true);
|
||||
}
|
||||
|
||||
if (in_string == 0 && valid_symbols[GLSL_CONTENT])
|
||||
{
|
||||
lexer->result_symbol = GLSL_CONTENT;
|
||||
while (true)
|
||||
{
|
||||
switch (lexer->lookahead)
|
||||
{
|
||||
case '|':
|
||||
lexer->mark_end(lexer);
|
||||
advance(lexer);
|
||||
if (lexer->lookahead == ']')
|
||||
{
|
||||
advance(lexer);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case '\0':
|
||||
lexer->mark_end(lexer);
|
||||
return true;
|
||||
default:
|
||||
advance(lexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// The indention of the current line
|
||||
uint32_t indent_length;
|
||||
// Our indentation stack
|
||||
vector<uint16_t> indent_length_stack;
|
||||
// Stack of 0 - for possible VIRTUAL_END_DECL or 1 - for possible VIRTUAL_END_SECTION
|
||||
vector<uint8_t> runback;
|
||||
// 0 - Not in a string | 1 - in a normal string | 2 - in a multiline string
|
||||
uint8_t in_string = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void *tree_sitter_elm_external_scanner_create()
|
||||
{
|
||||
return new Scanner();
|
||||
}
|
||||
|
||||
bool tree_sitter_elm_external_scanner_scan(void *payload, TSLexer *lexer,
|
||||
const bool *valid_symbols)
|
||||
{
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
return scanner->scan(lexer, valid_symbols);
|
||||
}
|
||||
|
||||
unsigned tree_sitter_elm_external_scanner_serialize(void *payload, char *buffer)
|
||||
{
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
return scanner->serialize(buffer);
|
||||
}
|
||||
|
||||
void tree_sitter_elm_external_scanner_deserialize(void *payload, const char *buffer, unsigned length)
|
||||
{
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
scanner->deserialize(buffer, length);
|
||||
}
|
||||
|
||||
void tree_sitter_elm_external_scanner_destroy(void *payload)
|
||||
{
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
delete scanner;
|
||||
}
|
||||
}
|
|
@ -1,238 +0,0 @@
|
|||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
typedef struct {
|
||||
bool visible : 1;
|
||||
bool named : 1;
|
||||
bool supertype: 1;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
TSStateId state;
|
||||
bool extra : 1;
|
||||
bool repetition : 1;
|
||||
} shift;
|
||||
struct {
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint8_t child_count;
|
||||
uint8_t production_id;
|
||||
} reduce;
|
||||
} params;
|
||||
TSParseActionType type : 4;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable : 1;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
const char **symbol_names;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const uint16_t *parse_table;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
const TSLexMode *lex_modes;
|
||||
const TSSymbol *alias_sequences;
|
||||
uint16_t max_alias_sequence_length;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
uint32_t field_count;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const char **field_names;
|
||||
uint32_t large_state_count;
|
||||
const uint16_t *small_parse_table;
|
||||
const uint32_t *small_parse_table_map;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
uint32_t state_count;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{ \
|
||||
{ \
|
||||
.params = { \
|
||||
.shift = { \
|
||||
.state = state_value \
|
||||
} \
|
||||
}, \
|
||||
.type = TSParseActionTypeShift \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{ \
|
||||
{ \
|
||||
.params = { \
|
||||
.shift = { \
|
||||
.state = state_value, \
|
||||
.repetition = true \
|
||||
} \
|
||||
}, \
|
||||
.type = TSParseActionTypeShift \
|
||||
} \
|
||||
}
|
||||
|
||||
#define RECOVER() \
|
||||
{ \
|
||||
{ .type = TSParseActionTypeRecover } \
|
||||
}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{ \
|
||||
{ \
|
||||
.params = { \
|
||||
.shift = { \
|
||||
.extra = true \
|
||||
} \
|
||||
}, \
|
||||
.type = TSParseActionTypeShift \
|
||||
} \
|
||||
}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{ \
|
||||
{ \
|
||||
.params = { \
|
||||
.reduce = { \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}, \
|
||||
.type = TSParseActionTypeReduce \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{ \
|
||||
{ .type = TSParseActionTypeAccept } \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
|
@ -1,113 +0,0 @@
|
|||
=====================================
|
||||
Annotation for func returning multiple
|
||||
=====================================
|
||||
main : Program Value Model Msg
|
||||
main =
|
||||
Api.application Viewer.decoder
|
||||
{ init = init
|
||||
, onUrlChange = ChangedUrl
|
||||
, onUrlRequest = ClickedLink
|
||||
, subscriptions = subscriptions
|
||||
, update = update
|
||||
, view = view
|
||||
}
|
||||
---
|
||||
|
||||
(file
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(record_expr
|
||||
(left_brace) (field (lower_case_identifier) (eq) (value_expr (value_qid (lower_case_identifier))))
|
||||
(comma) (field (lower_case_identifier) (eq) (value_expr (upper_case_qid (upper_case_identifier))))
|
||||
(comma) (field (lower_case_identifier) (eq) (value_expr (upper_case_qid (upper_case_identifier))))
|
||||
(comma) (field (lower_case_identifier) (eq) (value_expr (value_qid (lower_case_identifier))))
|
||||
(comma) (field (lower_case_identifier) (eq) (value_expr (value_qid (lower_case_identifier))))
|
||||
(comma) (field (lower_case_identifier) (eq) (value_expr (value_qid (lower_case_identifier))))
|
||||
(right_brace)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Annotation for func with parameters returning tuple
|
||||
=====================================
|
||||
init : Maybe Viewer -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||
init maybeViewer url navKey =
|
||||
changeRouteTo (Route.fromUrl url)
|
||||
(Redirect (Session.fromViewer navKey maybeViewer))
|
||||
---
|
||||
|
||||
(file
|
||||
(type_annotation
|
||||
(lower_case_identifier) (colon)
|
||||
(type_expression
|
||||
(type_ref (upper_case_qid (upper_case_identifier)) (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
(arrow) (type_ref (upper_case_qid (upper_case_identifier)))
|
||||
(arrow) (type_ref (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)))
|
||||
(arrow) (tuple_type (left_parenthesis) (type_expression (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
(comma) (type_expression (type_ref (upper_case_qid (upper_case_identifier)) (type_ref (upper_case_qid (upper_case_identifier))))) (right_parenthesis))
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))) (eq)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier)))
|
||||
(parenthesized_expr (left_parenthesis)
|
||||
(function_call_expr (value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier))))
|
||||
(right_parenthesis))
|
||||
(parenthesized_expr (left_parenthesis) (function_call_expr (value_expr (upper_case_qid (upper_case_identifier)))
|
||||
(parenthesized_expr (left_parenthesis) (function_call_expr (value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier))))
|
||||
(right_parenthesis)))
|
||||
(right_parenthesis))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Annotation with trailing whitespace
|
||||
=====================================
|
||||
test : Int
|
||||
test =
|
||||
1
|
||||
---
|
||||
|
||||
(file
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
)
|
|
@ -1,80 +0,0 @@
|
|||
=====================================
|
||||
Function containing an anonymous function
|
||||
=====================================
|
||||
func =
|
||||
(\_ -> get h w)
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(parenthesized_expr
|
||||
(left_parenthesis)
|
||||
(anonymous_function_expr
|
||||
(backslash)
|
||||
(pattern (anything_pattern (underscore)))
|
||||
(arrow)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Function containing an anonymous function that's called
|
||||
=====================================
|
||||
f6 = (\a -> a) 1
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(parenthesized_expr
|
||||
(left_parenthesis)
|
||||
(anonymous_function_expr (backslash) (pattern (lower_pattern (lower_case_identifier))) (arrow) (value_expr (value_qid (lower_case_identifier))))
|
||||
(right_parenthesis)
|
||||
)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Function containing an anonymous function without braces
|
||||
=====================================
|
||||
f6 = \a -> a
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(anonymous_function_expr (backslash) (pattern (lower_pattern (lower_case_identifier))) (arrow) (value_expr (value_qid (lower_case_identifier))))
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Function containing a pipe into an anonymous function without braces
|
||||
=====================================
|
||||
f1 =
|
||||
1 |> \a -> a
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(bin_op_expr (number_constant_expr (number_literal))
|
||||
(operator (operator_identifier))
|
||||
(anonymous_function_expr (backslash) (pattern (lower_pattern (lower_case_identifier))) (arrow) (value_expr (value_qid (lower_case_identifier))))
|
||||
)
|
||||
)
|
||||
)
|
File diff suppressed because it is too large
Load Diff
|
@ -1,481 +0,0 @@
|
|||
=====================================
|
||||
Case with one branch
|
||||
=====================================
|
||||
|
||||
update msg =
|
||||
case msg of
|
||||
Nothing ->
|
||||
Nothing
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier) (lower_pattern (lower_case_identifier)))
|
||||
(eq)
|
||||
(case_of_expr (case) (value_expr (value_qid (lower_case_identifier))) (of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
=====================================
|
||||
Case with one branch and comment
|
||||
=====================================
|
||||
|
||||
update msg value =
|
||||
case value of
|
||||
S ->
|
||||
value -- Debug
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier) (lower_pattern (lower_case_identifier)) (lower_pattern (lower_case_identifier)))
|
||||
(eq)
|
||||
(case_of_expr (case) (value_expr (value_qid (lower_case_identifier))) (of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (value_qid (lower_case_identifier)))))) (line_comment)
|
||||
)
|
||||
|
||||
|
||||
|
||||
=====================================
|
||||
Case with two branches
|
||||
=====================================
|
||||
|
||||
update msg model =
|
||||
case msg of
|
||||
Increment ->
|
||||
model + 1
|
||||
|
||||
Decrement ->
|
||||
model - 1
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier) (lower_pattern (lower_case_identifier)) (lower_pattern (lower_case_identifier)))
|
||||
(eq)
|
||||
(case_of_expr (case) (value_expr (value_qid (lower_case_identifier))) (of)
|
||||
|
||||
(case_of_branch (pattern (union_pattern (upper_case_qid (upper_case_identifier)))) (arrow)
|
||||
(bin_op_expr (value_expr (value_qid (lower_case_identifier))) (operator (operator_identifier)) (number_constant_expr (number_literal))))
|
||||
|
||||
(case_of_branch (pattern (union_pattern (upper_case_qid (upper_case_identifier)))) (arrow)
|
||||
(bin_op_expr (value_expr (value_qid (lower_case_identifier))) (operator (operator_identifier)) (number_constant_expr (number_literal))))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Case with anonymous function
|
||||
=====================================
|
||||
|
||||
enum =
|
||||
\stringList ->
|
||||
case stringList of
|
||||
[ str ] ->
|
||||
get str dict
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(anonymous_function_expr
|
||||
(backslash)
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(arrow)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern
|
||||
(list_pattern
|
||||
(left_square_bracket)
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(right_square_bracket)
|
||||
)
|
||||
)
|
||||
(arrow)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (anything_pattern (underscore)))
|
||||
(arrow)
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
=====================================
|
||||
Case with three branches
|
||||
=====================================
|
||||
|
||||
src : Avatar -> Attribute msg
|
||||
src (Avatar maybeUrl)=
|
||||
case maybeUrl of
|
||||
Nothing ->
|
||||
Asset.src Asset.defaultAvatar
|
||||
|
||||
Just "" ->
|
||||
Asset.src Asset.defaultAvatar
|
||||
|
||||
Just url ->
|
||||
Html.Attributes.src url
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
(arrow)
|
||||
(type_ref
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(type_variable (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(left_parenthesis)
|
||||
(pattern
|
||||
(union_pattern
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
(right_parenthesis)
|
||||
)
|
||||
(eq)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern
|
||||
(union_pattern
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(string_constant_expr (open_quote) (close_quote))
|
||||
)
|
||||
)
|
||||
(arrow)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern
|
||||
(union_pattern
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
(arrow)
|
||||
(function_call_expr
|
||||
(value_expr
|
||||
(value_qid
|
||||
(upper_case_identifier)
|
||||
(dot)
|
||||
(upper_case_identifier)
|
||||
(dot)
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
|
||||
=====================================
|
||||
Function statement with nested case
|
||||
=====================================
|
||||
|
||||
map3 func ma mb mc =
|
||||
case ma of
|
||||
Nothing ->
|
||||
Nothing
|
||||
|
||||
Just a ->
|
||||
case mb of
|
||||
Nothing ->
|
||||
Nothing
|
||||
|
||||
Just b ->
|
||||
b
|
||||
|
||||
|
||||
map4 func ma mb mc md =
|
||||
case ma of
|
||||
Nothing ->
|
||||
Nothing
|
||||
|
||||
Just a ->
|
||||
a
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
(eq)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier)) (lower_pattern (lower_case_identifier))))
|
||||
(arrow)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier)) (lower_pattern (lower_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
(eq)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier)) (lower_pattern (lower_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Case int result
|
||||
=====================================
|
||||
|
||||
toIntResult s =
|
||||
case String.toInt s of
|
||||
Just i ->
|
||||
Ok i
|
||||
Nothing ->
|
||||
Err <| "could not convert string '" ++ s ++ "' to an Int"
|
||||
---
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
(eq)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(function_call_expr
|
||||
(value_expr
|
||||
(value_qid (upper_case_identifier) (dot) (lower_case_identifier))
|
||||
)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern
|
||||
(union_pattern
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
(arrow)
|
||||
(function_call_expr
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern
|
||||
(union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(bin_op_expr
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
(operator (operator_identifier))
|
||||
(string_constant_expr (open_quote) (regular_string_part) (close_quote))
|
||||
(operator (operator_identifier))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(operator (operator_identifier))
|
||||
(string_constant_expr (open_quote) (regular_string_part) (close_quote))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
|
||||
=====================================
|
||||
Case with list
|
||||
=====================================
|
||||
enum key dict =
|
||||
custom key <| \stringList ->
|
||||
case stringList of
|
||||
[str] ->
|
||||
Dict.get str dict
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
|
||||
---
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
(eq)
|
||||
(bin_op_expr
|
||||
(function_call_expr
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)))
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier))))
|
||||
(operator
|
||||
(operator_identifier))
|
||||
(anonymous_function_expr
|
||||
(backslash)
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(arrow)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr
|
||||
(value_qid (lower_case_identifier))
|
||||
)
|
||||
(of)
|
||||
(case_of_branch
|
||||
(pattern
|
||||
(list_pattern
|
||||
(left_square_bracket)
|
||||
(pattern
|
||||
(lower_pattern
|
||||
(lower_case_identifier)))
|
||||
(right_square_bracket)))
|
||||
(arrow)
|
||||
(function_call_expr
|
||||
(value_expr
|
||||
(value_qid
|
||||
(upper_case_identifier)
|
||||
(dot)
|
||||
(lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
(case_of_branch
|
||||
(pattern
|
||||
(anything_pattern (underscore))
|
||||
)
|
||||
(arrow) (value_expr (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
=====================================
|
||||
One line comment without linebreak
|
||||
=====================================
|
||||
--
|
||||
---
|
||||
|
||||
(file
|
||||
(line_comment)
|
||||
)
|
||||
=====================================
|
||||
One line comments
|
||||
=====================================
|
||||
|
||||
-- MODEL
|
||||
-- update
|
||||
-- more words
|
||||
-- note: (isOkay x || any isOkay xs) would not get TCO
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(line_comment)
|
||||
(line_comment)
|
||||
(line_comment)
|
||||
(line_comment)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Block comments
|
||||
=====================================
|
||||
|
||||
{- one line -}
|
||||
{- a multiline comment
|
||||
how nice
|
||||
-}
|
||||
{-| Returns a dictionary mapping `ScreenId` to its problems, if any.
|
||||
-}
|
||||
{--}
|
||||
-- add x y = x + y
|
||||
--}
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(block_comment)
|
||||
(block_comment)
|
||||
(block_comment)
|
||||
(block_comment)
|
||||
(line_comment)
|
||||
(line_comment)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Complex Block comment
|
||||
=====================================
|
||||
|
||||
{-| Works just like [`Parser.Nestable`](Parser#nestable) to help distinguish
|
||||
between unnestable `/*` `*/` comments like in JS and nestable `{-` `-}`
|
||||
comments like in Elm.
|
||||
-}
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(block_comment)
|
||||
)
|
|
@ -1,259 +0,0 @@
|
|||
=====================================
|
||||
Complete function example
|
||||
=====================================
|
||||
|
||||
{-| An animation frame triggers about 60 times per second. Get the POSIX time
|
||||
on each frame. (See [`elm/time`](/packages/elm/time/latest) for more info on
|
||||
POSIX times.)
|
||||
|
||||
**Note:** Browsers have their own render loop, repainting things as fast as
|
||||
possible. If you want smooth animations in your application, it is helpful to
|
||||
sync up with the browsers natural refresh rate. This hooks into JavaScript's
|
||||
`requestAnimationFrame` function.
|
||||
-}
|
||||
onAnimationFrame : (Time.Posix -> msg) -> Sub msg
|
||||
onAnimationFrame =
|
||||
AM.onAnimationFrame
|
||||
---
|
||||
|
||||
(file
|
||||
(block_comment)
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(left_parenthesis)
|
||||
(type_expression
|
||||
(type_ref
|
||||
(upper_case_qid
|
||||
(upper_case_identifier)
|
||||
(dot)
|
||||
(upper_case_identifier)
|
||||
)
|
||||
)
|
||||
(arrow)
|
||||
(type_variable (lower_case_identifier))
|
||||
)
|
||||
(right_parenthesis)
|
||||
(arrow)
|
||||
(type_ref
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(type_variable (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Complete counter example
|
||||
=====================================
|
||||
|
||||
module Main exposing (Msg(..), main, update, view)
|
||||
|
||||
import Browser
|
||||
import Html exposing (Html, button, div, text)
|
||||
import Html.Events exposing (onClick)
|
||||
|
||||
|
||||
main =
|
||||
Browser.sandbox { init = 0, update = update, view = view }
|
||||
|
||||
|
||||
type Msg
|
||||
= Increment
|
||||
| Decrement
|
||||
|
||||
|
||||
update msg model =
|
||||
case msg of
|
||||
Increment ->
|
||||
model + 1
|
||||
|
||||
Decrement ->
|
||||
model - 1
|
||||
|
||||
{- Test comment -}
|
||||
view model =
|
||||
div []
|
||||
[ button [ onClick Decrement ] [ text "-" ]
|
||||
, div [] [ text (String.fromInt model) ]
|
||||
, button [ onClick Increment ] [ text "+" ]
|
||||
]
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module) (upper_case_qid (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_type (upper_case_identifier) (exposed_union_constructors (left_parenthesis) (double_dot) (right_parenthesis)))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause (import) (upper_case_qid (upper_case_identifier)))
|
||||
|
||||
(import_clause (import) (upper_case_qid (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_type (upper_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause (import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(record_expr
|
||||
(left_brace)
|
||||
(field (lower_case_identifier) (eq) (number_constant_expr (number_literal)))
|
||||
(comma)
|
||||
(field
|
||||
(lower_case_identifier)
|
||||
(eq)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
(comma)
|
||||
(field
|
||||
(lower_case_identifier)
|
||||
(eq)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
(right_brace)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(type_declaration (type) (upper_case_identifier) (eq) (union_variant (upper_case_identifier)) (pipe) (union_variant (upper_case_identifier)))
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier))
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
(eq)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(bin_op_expr (value_expr (value_qid (lower_case_identifier))) (operator (operator_identifier)) (number_constant_expr (number_literal)))
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(bin_op_expr (value_expr (value_qid (lower_case_identifier))) (operator (operator_identifier)) (number_constant_expr (number_literal)))
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
(block_comment)
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier))
|
||||
)
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(list_expr (left_square_bracket) (right_square_bracket))
|
||||
(list_expr
|
||||
(left_square_bracket)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(list_expr
|
||||
(left_square_bracket)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (value_expr (upper_case_qid (upper_case_identifier))))
|
||||
(right_square_bracket)
|
||||
)
|
||||
(list_expr
|
||||
(left_square_bracket)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(string_constant_expr (open_quote) (regular_string_part) (close_quote))
|
||||
)
|
||||
(right_square_bracket)
|
||||
)
|
||||
)
|
||||
(comma)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(list_expr (left_square_bracket) (right_square_bracket))
|
||||
(list_expr
|
||||
(left_square_bracket)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(parenthesized_expr
|
||||
(left_parenthesis)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
(right_square_bracket)
|
||||
)
|
||||
)
|
||||
(comma)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(list_expr
|
||||
(left_square_bracket)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (value_expr (upper_case_qid (upper_case_identifier))))
|
||||
(right_square_bracket)
|
||||
)
|
||||
(list_expr
|
||||
(left_square_bracket)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (string_constant_expr (open_quote) (regular_string_part) (close_quote)))
|
||||
(right_square_bracket)
|
||||
)
|
||||
)
|
||||
(right_square_bracket)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
|
@ -1,28 +0,0 @@
|
|||
=====================================
|
||||
Multiple field accessors
|
||||
=====================================
|
||||
|
||||
func model =
|
||||
model.field.second.third
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern
|
||||
(lower_case_identifier)))
|
||||
(eq)
|
||||
(field_access_expr
|
||||
(field_access_expr
|
||||
(field_access_expr
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)))
|
||||
(dot)
|
||||
(lower_case_identifier))
|
||||
(dot)
|
||||
(lower_case_identifier))
|
||||
(dot)
|
||||
(lower_case_identifier))))
|
|
@ -1,70 +0,0 @@
|
|||
=====================================
|
||||
Simple glsl function
|
||||
=====================================
|
||||
|
||||
textures_skies_tim_hell_fragment_1 =
|
||||
[glsl|
|
||||
precision mediump float;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
varying vec2 vLightmapCoord;
|
||||
varying vec4 vColor;
|
||||
uniform sampler2D texture;
|
||||
uniform float time;
|
||||
void main
|
||||
(void) {
|
||||
vec4 textureColor = texture2D(texture, vTextureCoord.st);
|
||||
vec3 rgb = textureColor.rgb;
|
||||
// alphaGen
|
||||
float alpha = textureColor.a;
|
||||
gl_FragColor = vec4(rgb, alpha);
|
||||
}
|
||||
|]
|
||||
|
||||
---
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(glsl_code_expr
|
||||
(glsl_begin)
|
||||
(glsl_content)
|
||||
(glsl_end)
|
||||
)
|
||||
)
|
||||
)
|
||||
=====================================
|
||||
Simple glsl function no end
|
||||
=====================================
|
||||
|
||||
textures_skies_tim_hell_fragment_1 =
|
||||
[glsl|
|
||||
precision mediump float;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
varying vec2 vLightmapCoord;
|
||||
varying vec4 vColor;
|
||||
uniform sampler2D texture;
|
||||
uniform float time;
|
||||
void main
|
||||
(void) {
|
||||
vec4 textureColor = texture2D(texture, vTextureCoord.st);
|
||||
vec3 rgb = textureColor.rgb;
|
||||
// alphaGen
|
||||
float alpha = textureColor.a;
|
||||
gl_FragColor = vec4(rgb, alpha);
|
||||
}
|
||||
|
||||
---
|
||||
(file
|
||||
(ERROR
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(glsl_begin)
|
||||
(glsl_content)
|
||||
)
|
||||
)
|
|
@ -1,208 +0,0 @@
|
|||
=====================================
|
||||
Import statements
|
||||
=====================================
|
||||
|
||||
import Browser
|
||||
import Html.Events
|
||||
import Html.Events.Test
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier))
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier))
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier) (dot) (upper_case_identifier))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Import statements with exposing
|
||||
=====================================
|
||||
|
||||
import Html.Events exposing (onClick)
|
||||
import Html.Events exposing (..)
|
||||
import Html.Events exposing (onClick, onDoubleClick)
|
||||
import Html exposing (Html, button, div, text)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_value (lower_case_identifier)) (right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (double_dot) (right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_value (lower_case_identifier)) (comma) (exposed_value (lower_case_identifier)) (right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_type (upper_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Import statements prefixed with module and docs
|
||||
=====================================
|
||||
|
||||
module Asset exposing (Image, defaultAvatar, error, loading, src)
|
||||
|
||||
{-| Assets, such as images, videos, and audio. (We only have images for now.)
|
||||
|
||||
We should never expose asset URLs directly; this module should be in charge of
|
||||
all of them. One source of truth!
|
||||
|
||||
-}
|
||||
|
||||
import Html exposing (Attribute, Html)
|
||||
import Html.Attributes as Attr
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module) (upper_case_qid (upper_case_identifier))
|
||||
(exposing_list (exposing) (left_parenthesis) (exposed_type (upper_case_identifier))
|
||||
(comma) (exposed_value (lower_case_identifier)) (comma) (exposed_value (lower_case_identifier))
|
||||
(comma) (exposed_value (lower_case_identifier)) (comma) (exposed_value (lower_case_identifier))
|
||||
(right_parenthesis)))
|
||||
|
||||
|
||||
(block_comment)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_type (upper_case_identifier)) (comma) (exposed_type (upper_case_identifier)) (right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (as_clause (as) (upper_case_identifier))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Import statements with as clause
|
||||
=====================================
|
||||
|
||||
import Dict.Any as AnyDict exposing (AnyDict)
|
||||
import Remedy.ScreenId as ScreenId exposing (ScreenId)
|
||||
import Remedy.ScreenList as ScreenList
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (as_clause (as) (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_type (upper_case_identifier)) (right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (as_clause (as) (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_type (upper_case_identifier)) (right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
(import_clause
|
||||
(import) (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (as_clause (as) (upper_case_identifier)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Import statements with operator statement
|
||||
=====================================
|
||||
|
||||
import Url.Parser as Parser exposing ((</>), Parser, oneOf, s, string)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(import_clause
|
||||
(import)
|
||||
(upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier))
|
||||
(as_clause (as) (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_operator
|
||||
(left_parenthesis)
|
||||
(operator_identifier)
|
||||
(right_parenthesis)
|
||||
)
|
||||
(comma)
|
||||
(exposed_type (upper_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Import statements with type trying to expose all constructors
|
||||
=====================================
|
||||
|
||||
import Element exposing (DeviceClass(..))
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(import_clause
|
||||
(import)
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_type (upper_case_identifier) (exposed_union_constructors (left_parenthesis) (double_dot) (right_parenthesis)))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Import statements with type trying to expose single constructor - should fail
|
||||
=====================================
|
||||
|
||||
import Element exposing (DeviceClass(Phone))
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(import_clause
|
||||
(import)
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_type (upper_case_identifier))
|
||||
(ERROR (left_parenthesis) (upper_case_identifier) (right_parenthesis))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
)
|
|
@ -1,38 +0,0 @@
|
|||
=====================================
|
||||
Incomplete function call
|
||||
=====================================
|
||||
|
||||
view model =
|
||||
div []
|
||||
[ Html.
|
||||
]
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration (function_declaration_left (lower_case_identifier) (lower_pattern (lower_case_identifier)))
|
||||
(eq)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (list_expr (left_square_bracket) (right_square_bracket))
|
||||
(list_expr (left_square_bracket)
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
(ERROR (dot))
|
||||
(right_square_bracket)))))
|
||||
|
||||
=====================================
|
||||
Incomplete model access
|
||||
=====================================
|
||||
view model =
|
||||
div []
|
||||
[ model.
|
||||
]
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration (function_declaration_left (lower_case_identifier) (lower_pattern (lower_case_identifier)))
|
||||
(eq)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (list_expr (left_square_bracket) (right_square_bracket))
|
||||
(list_expr (left_square_bracket)
|
||||
(field_access_expr (value_expr (value_qid (lower_case_identifier))) (dot) (MISSING lower_case_identifier))
|
||||
(right_square_bracket)))))
|
|
@ -1,654 +0,0 @@
|
|||
=====================================
|
||||
Single line let
|
||||
=====================================
|
||||
|
||||
i = let x = 320 in x
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Let with block comment on last line (should be indentation sensitive - unindented)
|
||||
=====================================
|
||||
|
||||
letExample =
|
||||
let
|
||||
{ title } =
|
||||
Article.metadata article
|
||||
{-- test --}
|
||||
in
|
||||
title
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(pattern
|
||||
(record_pattern
|
||||
(left_brace)
|
||||
(lower_pattern
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(right_brace)
|
||||
)
|
||||
)
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(value_expr
|
||||
(value_qid
|
||||
(upper_case_identifier)
|
||||
(dot)
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(block_comment)
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
=====================================
|
||||
Let with line comment on last line
|
||||
=====================================
|
||||
|
||||
letExample =
|
||||
let
|
||||
{ title } =
|
||||
Article.metadata article
|
||||
-- test
|
||||
in
|
||||
title
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(pattern
|
||||
(record_pattern
|
||||
(left_brace)
|
||||
(lower_pattern
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(right_brace)
|
||||
)
|
||||
)
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(value_expr
|
||||
(value_qid
|
||||
(upper_case_identifier)
|
||||
(dot)
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(line_comment)
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Single line let with in changing line
|
||||
=====================================
|
||||
|
||||
i = let f = (\a b c d -> a + b + c + d) in
|
||||
f
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(parenthesized_expr
|
||||
(left_parenthesis)
|
||||
(anonymous_function_expr
|
||||
(backslash)
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(arrow)
|
||||
(bin_op_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(operator (operator_identifier))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(operator (operator_identifier))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(operator (operator_identifier))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Let with case
|
||||
=====================================
|
||||
|
||||
routeToString : Route -> String
|
||||
routeToString page =
|
||||
let
|
||||
pieces =
|
||||
case page of
|
||||
Home ->
|
||||
[]
|
||||
|
||||
Root ->
|
||||
[]
|
||||
in
|
||||
"#/" ++ String.join "/" pieces
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
(arrow)
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
(lower_pattern (lower_case_identifier)))
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(list_expr (left_square_bracket) (right_square_bracket))
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(list_expr (left_square_bracket) (right_square_bracket))
|
||||
)
|
||||
)
|
||||
)
|
||||
(bin_op_expr
|
||||
(string_constant_expr (open_quote) (regular_string_part) (close_quote))
|
||||
(operator (operator_identifier))
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(string_constant_expr (open_quote) (regular_string_part) (close_quote))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
=====================================
|
||||
let with two variables
|
||||
=====================================
|
||||
|
||||
isUpper =
|
||||
let
|
||||
five =
|
||||
5
|
||||
|
||||
six =
|
||||
6
|
||||
in
|
||||
abcd
|
||||
|
||||
---
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
(value_expr
|
||||
(value_qid (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
let with two variables and case
|
||||
=====================================
|
||||
|
||||
init session =
|
||||
let
|
||||
feedTab =
|
||||
case Session.cred session of
|
||||
Just cred ->
|
||||
YourFeed cred
|
||||
|
||||
Nothing ->
|
||||
GlobalFeed
|
||||
|
||||
loadTags =
|
||||
Http.toTask Tag.list
|
||||
in
|
||||
abcd
|
||||
|
||||
---
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier) (lower_pattern (lower_case_identifier))
|
||||
)
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(case_of_expr
|
||||
(case)
|
||||
(function_call_expr (value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier))) (value_expr (value_qid (lower_case_identifier))))
|
||||
(of)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier)) (lower_pattern (lower_case_identifier))))
|
||||
(arrow)
|
||||
(function_call_expr (value_expr (upper_case_qid (upper_case_identifier))) (value_expr (value_qid (lower_case_identifier))))
|
||||
)
|
||||
|
||||
(case_of_branch
|
||||
(pattern (union_pattern (upper_case_qid (upper_case_identifier))))
|
||||
(arrow)
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(function_call_expr (value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier))) (value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier))))
|
||||
)
|
||||
(value_expr
|
||||
(value_qid (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Let with type annotation
|
||||
=====================================
|
||||
|
||||
i : Int
|
||||
i =
|
||||
let
|
||||
x : Int
|
||||
x = 320
|
||||
in
|
||||
x
|
||||
---
|
||||
|
||||
(file
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Let with block comment on last line (should be indentation sensitive - indented)
|
||||
=====================================
|
||||
|
||||
letExample =
|
||||
let
|
||||
{ title } =
|
||||
Article.metadata article
|
||||
{-- test --}
|
||||
in
|
||||
title
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(pattern
|
||||
(record_pattern
|
||||
(left_brace)
|
||||
(lower_pattern
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(right_brace)
|
||||
)
|
||||
)
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(value_expr
|
||||
(value_qid
|
||||
(upper_case_identifier)
|
||||
(dot)
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(block_comment)
|
||||
(value_expr
|
||||
(value_qid
|
||||
(lower_case_identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Let in same line in in next
|
||||
=====================================
|
||||
|
||||
testLet =
|
||||
let color = "x"
|
||||
in
|
||||
color
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration (function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration (function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(string_constant_expr (open_quote) (regular_string_part) (close_quote))) (value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Let with unit in body
|
||||
=====================================
|
||||
|
||||
view =
|
||||
let
|
||||
styles =
|
||||
"x"
|
||||
in
|
||||
div
|
||||
(
|
||||
)
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(string_constant_expr (open_quote) (regular_string_part) (close_quote))
|
||||
)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (unit_expr (left_parenthesis) (right_parenthesis)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
=====================================
|
||||
Nested let with function and list in body
|
||||
=====================================
|
||||
|
||||
|
||||
main =
|
||||
let
|
||||
arcLengths =
|
||||
List.map
|
||||
(\n ->
|
||||
let
|
||||
fraction =
|
||||
toFloat n
|
||||
/ toFloat numSegments
|
||||
in
|
||||
fraction * overallArcLength
|
||||
)
|
||||
|
||||
in
|
||||
toHtml
|
||||
[]
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration
|
||||
(function_declaration_left
|
||||
(lower_case_identifier)
|
||||
)
|
||||
(eq)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(parenthesized_expr (left_parenthesis)
|
||||
(anonymous_function_expr (backslash)
|
||||
(pattern (lower_pattern (lower_case_identifier)))
|
||||
(arrow)
|
||||
(let_in_expr
|
||||
(value_declaration (function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(bin_op_expr
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
(operator (operator_identifier))
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (value_expr (value_qid (lower_case_identifier))))
|
||||
)
|
||||
)
|
||||
(bin_op_expr (value_expr (value_qid (lower_case_identifier)))
|
||||
(operator (operator_identifier))
|
||||
(value_expr (value_qid (lower_case_identifier)))))
|
||||
)
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
)
|
||||
(function_call_expr
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
(list_expr (left_square_bracket) (right_square_bracket))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
Let with comment after in
|
||||
=====================================
|
||||
|
||||
pyramidMesh =
|
||||
let
|
||||
frontLeft =
|
||||
10
|
||||
|
||||
in
|
||||
-- Comment
|
||||
frontLeft
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration (function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
(line_comment)
|
||||
(value_expr (value_qid (lower_case_identifier)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
=====================================
|
||||
Let with annotation
|
||||
=====================================
|
||||
|
||||
displayEmoji : Color
|
||||
displayEmoji =
|
||||
let native = 10
|
||||
in
|
||||
20
|
||||
|
||||
---
|
||||
|
||||
|
||||
(file
|
||||
(type_annotation
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
(value_declaration
|
||||
(function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(let_in_expr
|
||||
(value_declaration (function_declaration_left (lower_case_identifier))
|
||||
(eq)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
(number_constant_expr (number_literal))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -1,206 +0,0 @@
|
|||
=====================================
|
||||
module statement exposing all
|
||||
=====================================
|
||||
|
||||
module Main exposing (..)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (double_dot) (right_parenthesis))
|
||||
)
|
||||
|
||||
)
|
||||
=====================================
|
||||
module statement sub dir exposing all
|
||||
=====================================
|
||||
|
||||
module Page.View exposing (..)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (double_dot) (right_parenthesis))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
module statement exposing single function
|
||||
=====================================
|
||||
|
||||
module Main exposing (view)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_value (lower_case_identifier)) (right_parenthesis))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
module statement exposing multiple functions
|
||||
=====================================
|
||||
|
||||
module Main exposing (main, update, view)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier)) (right_parenthesis))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
module statement exposing type with all constructors and functions
|
||||
=====================================
|
||||
|
||||
module Main exposing (Msg(..), main, update, view)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_type (upper_case_identifier) (exposed_union_constructors (left_parenthesis) (double_dot) (right_parenthesis))) (comma)
|
||||
(exposed_value (lower_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (right_parenthesis))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
module statement exposing type with no constructors and functions
|
||||
=====================================
|
||||
|
||||
module Main exposing (Msg, main, update, view)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier)) (exposing_list (exposing) (left_parenthesis) (exposed_type (upper_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (comma)
|
||||
(exposed_value (lower_case_identifier)) (right_parenthesis))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
module statement exposing type with all constructors and functions
|
||||
=====================================
|
||||
|
||||
module Main exposing (Msg(..), main, update, view)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_type (upper_case_identifier) (exposed_union_constructors (left_parenthesis) (double_dot) (right_parenthesis)))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis))
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
module statement exposing type with one constructors and functions - not valid in elm 0.19 - should error
|
||||
=====================================
|
||||
|
||||
module Main exposing (Msg(One), main, update, view)
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration (module)
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_type (upper_case_identifier)) (ERROR (left_parenthesis) (upper_case_identifier) (right_parenthesis))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis))
|
||||
)
|
||||
)
|
||||
|
||||
=====================================
|
||||
effect module statement exposing
|
||||
=====================================
|
||||
|
||||
effect module Task where { command = MyCmd } exposing
|
||||
( Task
|
||||
, succeed, fail
|
||||
, map, map2, map3, map4, map5
|
||||
, sequence
|
||||
, andThen
|
||||
, onError, mapError
|
||||
, perform, attempt
|
||||
)
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration
|
||||
(effect)
|
||||
(module)
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(where)
|
||||
(record_expr (left_brace) (field (lower_case_identifier) (eq) (value_expr (upper_case_qid (upper_case_identifier)))) (right_brace))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_type (upper_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(comma)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
|
@ -1,41 +0,0 @@
|
|||
=====================================
|
||||
module statement exposing all
|
||||
=====================================
|
||||
|
||||
|
||||
port module Ports exposing (foo)
|
||||
|
||||
|
||||
port foo : String -> Cmd msg
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(module_declaration
|
||||
(port)
|
||||
(module)
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(exposing_list
|
||||
(exposing)
|
||||
(left_parenthesis)
|
||||
(exposed_value (lower_case_identifier))
|
||||
(right_parenthesis)
|
||||
)
|
||||
)
|
||||
(port_annotation
|
||||
(port)
|
||||
(lower_case_identifier)
|
||||
(colon)
|
||||
(type_expression
|
||||
(type_ref
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
)
|
||||
(arrow)
|
||||
(type_ref
|
||||
(upper_case_qid (upper_case_identifier))
|
||||
(type_variable (lower_case_identifier))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
|
@ -1,55 +0,0 @@
|
|||
=====================================
|
||||
Function statement with function call and inline record
|
||||
=====================================
|
||||
|
||||
main =
|
||||
Browser.sandbox
|
||||
{ init = 0
|
||||
, update = update
|
||||
, view = view }
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration (function_declaration_left (lower_case_identifier)) (eq)
|
||||
(function_call_expr (value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier)))
|
||||
(record_expr (left_brace) (field (lower_case_identifier) (eq) (number_constant_expr (number_literal)))
|
||||
(comma) (field (lower_case_identifier) (eq) (value_expr (value_qid (lower_case_identifier))))
|
||||
(comma) (field (lower_case_identifier) (eq) (value_expr (value_qid (lower_case_identifier)))) (right_brace)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Function statement with list
|
||||
=====================================
|
||||
|
||||
view model =
|
||||
div []
|
||||
[ button [ onClick Decrement ] [ text "-" ]
|
||||
, div [] [ text (String.fromInt model) ]
|
||||
, button [ onClick Increment ] [ text "+" ]
|
||||
]
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(value_declaration (function_declaration_left (lower_case_identifier) (lower_pattern (lower_case_identifier))) (eq)
|
||||
(function_call_expr (value_expr (value_qid (lower_case_identifier))) (list_expr (left_square_bracket) (right_square_bracket))
|
||||
(list_expr (left_square_bracket) (function_call_expr (value_expr (value_qid (lower_case_identifier)))
|
||||
(list_expr (left_square_bracket) (function_call_expr (value_expr (value_qid (lower_case_identifier)))
|
||||
(value_expr (upper_case_qid (upper_case_identifier)))) (right_square_bracket))
|
||||
(list_expr (left_square_bracket) (function_call_expr (value_expr (value_qid (lower_case_identifier))) (string_constant_expr (open_quote) (regular_string_part) (close_quote))) (right_square_bracket)))
|
||||
(comma) (function_call_expr (value_expr (value_qid (lower_case_identifier))) (list_expr (left_square_bracket) (right_square_bracket))
|
||||
(list_expr (left_square_bracket) (function_call_expr (value_expr (value_qid (lower_case_identifier)))
|
||||
(parenthesized_expr (left_parenthesis) (function_call_expr (value_expr (value_qid (upper_case_identifier) (dot) (lower_case_identifier))) (value_expr (value_qid (lower_case_identifier)))) (right_parenthesis))) (right_square_bracket)))
|
||||
(comma) (function_call_expr (value_expr (value_qid (lower_case_identifier))) (list_expr (left_square_bracket) (function_call_expr (value_expr (value_qid (lower_case_identifier))) (value_expr (upper_case_qid (upper_case_identifier)))) (right_square_bracket))
|
||||
(list_expr (left_square_bracket) (function_call_expr (value_expr (value_qid (lower_case_identifier))) (string_constant_expr (open_quote)
|
||||
(regular_string_part) (close_quote))) (right_square_bracket)))
|
||||
(right_square_bracket))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
|
@ -1,94 +0,0 @@
|
|||
=====================================
|
||||
Type statement
|
||||
=====================================
|
||||
|
||||
type Msg
|
||||
= Increment
|
||||
|
||||
type Msg
|
||||
= Increment
|
||||
| Decrement
|
||||
|
||||
type Msg
|
||||
= Increment
|
||||
| Decrement
|
||||
| NoOp
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(type_declaration (type) (upper_case_identifier)
|
||||
(eq) (union_variant (upper_case_identifier)))
|
||||
|
||||
|
||||
(type_declaration (type) (upper_case_identifier)
|
||||
(eq) (union_variant (upper_case_identifier))
|
||||
(pipe) (union_variant (upper_case_identifier)))
|
||||
|
||||
|
||||
(type_declaration (type) (upper_case_identifier)
|
||||
(eq) (union_variant (upper_case_identifier))
|
||||
(pipe) (union_variant (upper_case_identifier))
|
||||
(pipe) (union_variant (upper_case_identifier)))
|
||||
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Type statement with payload
|
||||
=====================================
|
||||
|
||||
type Problem
|
||||
= ContentProblem ValidationProblem
|
||||
| GenericProblem String
|
||||
| MetaProblem String
|
||||
|
||||
|
||||
type ValidationProblem
|
||||
= WithScreen ScreenId ScreenProblem
|
||||
| RequiresAtLeastOneScreen
|
||||
| ScreenListProblem ScreenList.ValidationProblem
|
||||
|
||||
|
||||
type ScreenProblem
|
||||
= WithElement Int ElementProblem
|
||||
| ScreenIsEmpty
|
||||
| ScreenIsUnreachable
|
||||
|
||||
|
||||
type ElementProblem
|
||||
= InvalidElement String
|
||||
| InvalidScreenTarget
|
||||
| InvalidScreenTargetCausesCycle
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(type_declaration (type) (upper_case_identifier)
|
||||
(eq) (union_variant (upper_case_identifier) (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
(pipe) (union_variant (upper_case_identifier) (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
(pipe) (union_variant (upper_case_identifier) (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
)
|
||||
|
||||
|
||||
(type_declaration (type) (upper_case_identifier)
|
||||
(eq) (union_variant (upper_case_identifier) (type_ref (upper_case_qid (upper_case_identifier))) (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
(pipe) (union_variant (upper_case_identifier))
|
||||
(pipe) (union_variant (upper_case_identifier) (type_ref (upper_case_qid (upper_case_identifier) (dot) (upper_case_identifier))))
|
||||
)
|
||||
|
||||
|
||||
(type_declaration (type) (upper_case_identifier)
|
||||
(eq) (union_variant (upper_case_identifier) (type_ref (upper_case_qid (upper_case_identifier))) (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
(pipe) (union_variant (upper_case_identifier))
|
||||
(pipe) (union_variant (upper_case_identifier))
|
||||
)
|
||||
|
||||
|
||||
(type_declaration (type) (upper_case_identifier)
|
||||
(eq) (union_variant (upper_case_identifier) (type_ref (upper_case_qid (upper_case_identifier))))
|
||||
(pipe) (union_variant (upper_case_identifier))
|
||||
(pipe) (union_variant (upper_case_identifier))
|
||||
)
|
||||
|
||||
)
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
=====================================
|
||||
Type alias number
|
||||
=====================================
|
||||
|
||||
type alias Number =
|
||||
Int
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(type_alias_declaration (type) (alias) (upper_case_identifier) (eq)
|
||||
(type_expression (type_ref (upper_case_qid (upper_case_identifier)))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
=====================================
|
||||
Type alias
|
||||
=====================================
|
||||
|
||||
type alias ListItem =
|
||||
{ name : String
|
||||
, value : Int
|
||||
, itemType : ListItemType
|
||||
}
|
||||
|
||||
|
||||
---
|
||||
|
||||
(file
|
||||
(type_alias_declaration (type) (alias) (upper_case_identifier) (eq)
|
||||
(type_expression (record_type
|
||||
(left_brace) (field_type (lower_case_identifier) (colon) (type_expression (type_ref (upper_case_qid (upper_case_identifier)))))
|
||||
(comma) (field_type (lower_case_identifier) (colon) (type_expression (type_ref (upper_case_qid (upper_case_identifier)))))
|
||||
(comma) (field_type (lower_case_identifier) (colon) (type_expression (type_ref (upper_case_qid (upper_case_identifier)))))
|
||||
(right_brace))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
|
@ -1,50 +0,0 @@
|
|||
module Main exposing (Msg(..), main, update, view)
|
||||
-- ^ keyword.other.elm
|
||||
-- ^ keyword.other.elm
|
||||
|
||||
import Browser
|
||||
-- ^ meta.import.elm
|
||||
import Html exposing (Html, button, div, text)
|
||||
-- ^ meta.import.elm
|
||||
import Html.Events exposing (onClick)
|
||||
-- ^ meta.import.elm
|
||||
|
||||
|
||||
main =
|
||||
Browser.sandbox { init = 0, update = update, view = view }
|
||||
|
||||
|
||||
type Msg
|
||||
-- <- @keyword.type.elm
|
||||
-- ^ @storage.type.elm
|
||||
= Increment
|
||||
-- ^ constant.type-constructor.elm
|
||||
| Decrement
|
||||
-- ^ constant.type-constructor.elm
|
||||
|
||||
update : Msg -> Model
|
||||
-- <- entity.name.function.elm
|
||||
-- ^ keyword.other.elm
|
||||
-- ^ keyword.operator.arrow.elm
|
||||
|
||||
update msg model =
|
||||
case msg of
|
||||
-- ^ keyword.control.elm
|
||||
Increment ->
|
||||
-- ^ keyword.operator.arrow.elm
|
||||
model + 1
|
||||
-- ^ keyword.operator.elm
|
||||
|
||||
Decrement ->
|
||||
model - 1
|
||||
-- ^ constant.numeric.elm
|
||||
|
||||
view model =
|
||||
-- ^ keyword.operator.assignment.elm
|
||||
div []
|
||||
[ button [ onClick Decrement ] [ text "-" ]
|
||||
-- ^ punctuation.definition.string.begin.elm
|
||||
-- ^ string.elm
|
||||
, div [] [ text (String.fromInt model) ]
|
||||
, button [ onClick Increment ] [ text "+" ]
|
||||
]
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es2016",
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/node_modules/*"]
|
||||
}
|
Loading…
Reference in New Issue