class Mint::Parser

Included Modules

Defined in:

parser.cr
parser/file.cr
parser/location.cr
parser/top_level.cr
parsers/access.cr
parsers/argument.cr
parsers/array_destructuring.cr
parsers/array_literal.cr
parsers/await.cr
parsers/base_expression.cr
parsers/block.cr
parsers/bool_literal.cr
parsers/bracket_access.cr
parsers/builtin.cr
parsers/call.cr
parsers/case.cr
parsers/case_branch.cr
parsers/comment.cr
parsers/commented_expression.cr
parsers/component.cr
parsers/connect.cr
parsers/connect_variable.cr
parsers/constant.cr
parsers/css_definition.cr
parsers/css_font_face.cr
parsers/css_keyframes.cr
parsers/css_nested_at.cr
parsers/css_node.cr
parsers/css_selector.cr
parsers/css_selector_name.cr
parsers/dbg.cr
parsers/decode.cr
parsers/defer.cr
parsers/destructuring.cr
parsers/directives/asset.cr
parsers/directives/format.cr
parsers/directives/highlight.cr
parsers/directives/highlight_file.cr
parsers/directives/inline.cr
parsers/directives/svg.cr
parsers/discard.cr
parsers/emit.cr
parsers/encode.cr
parsers/env.cr
parsers/expression.cr
parsers/field.cr
parsers/field_access.cr
parsers/for.cr
parsers/function.cr
parsers/get.cr
parsers/here_document.cr
parsers/html_attribute.cr
parsers/html_body.cr
parsers/html_component.cr
parsers/html_element.cr
parsers/html_fragment.cr
parsers/html_style.cr
parsers/id.cr
parsers/if.cr
parsers/inline_function.cr
parsers/interpolation.cr
parsers/js.cr
parsers/locale.cr
parsers/locale_key.cr
parsers/map.cr
parsers/map_field.cr
parsers/module.cr
parsers/negated_expression.cr
parsers/next_call.cr
parsers/number_literal.cr
parsers/operation.cr
parsers/operator.cr
parsers/parenthesized_expression.cr
parsers/pipe.cr
parsers/property.cr
parsers/provider.cr
parsers/record.cr
parsers/record_update.cr
parsers/regexp_literal.cr
parsers/return.cr
parsers/route.cr
parsers/routes.cr
parsers/signal.cr
parsers/spread.cr
parsers/state.cr
parsers/state_setter.cr
parsers/statement.cr
parsers/store.cr
parsers/string_literal.cr
parsers/style.cr
parsers/suite.cr
parsers/test.cr
parsers/tuple_destructuring.cr
parsers/tuple_literal.cr
parsers/type.cr
parsers/type_definition.cr
parsers/type_definition_field.cr
parsers/type_destructuring.cr
parsers/type_variable.cr
parsers/type_variant.cr
parsers/unary_minus.cr
parsers/use.cr
parsers/value.cr
parsers/variable.cr

Constant Summary

OPERATORS = {"|>" => 0, "or" => 0, "!=" => 10, "==" => 10, "<=" => 11, "<" => 11, ">=" => 11, ">" => 11, "-" => 13, "+" => 13, "*" => 14, "/" => 14, "%" => 14, "**" => 15, "&&" => 6, "||" => 5, "!" => 16}

These are the supported operators with their precedences.

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Mint::Helpers

owns?(node : Ast::Node, parent : Ast::Node) : Bool owns?, static?(nodes : Array(Ast::Node)) : Bool
static?(node : Ast::Node | Nil) : Bool
static?
, static_value(nodes : Array(Ast::Node), separator : Char | Nil = nil) : String
static_value(node : Ast::Node | Nil) : String | Nil
static_value

Constructor Detail

def self.new(input : String, path : String) #

[View source]

Class Method Detail

def self.parse(contents, file) : Ast #

[View source]
def self.parse(file) : Ast #

[View source]
def self.parse?(contents, file) : Ast | Error #

[View source]
def self.parse_any(contents, file) : Ast #

[View source]
def self.parse_any(file) : Ast #

[View source]

Instance Method Detail

def access(expression : Ast::Node) : Ast::Access | Nil #

[View source]
def argument(*, parse_default_value : Bool = true) : Ast::Argument | Nil #

[View source]
def array_destructuring : Ast::ArrayDestructuring | Nil #

[View source]
def array_literal : Ast::ArrayLiteral | Nil #

[View source]
def ascii_letters_or_numbers(*, extra_char : Char | Nil = nil) #

Parses any number of ascii latters or numbers.


[View source]
def ascii_uppercase_and_underscore #

Parses any number of ascii uppercase latters, numbers or underscore and must start with an uppercase letter.


[View source]
def ascii_word : String #

Returns the current word (sequence of ascii lowercase letters).


[View source]
def asset_directive : Ast::Directives::Asset | Nil #

[View source]
def ast : Mint::Ast #

The abstract syntax tree.


[View source]
def await : Ast::Await | Nil #

[View source]
def base_expression : Ast::Node | Nil #

[View source]
def block(opening_bracket_error : Proc(Nil) | Nil = nil, closing_bracket_error : Proc(Nil) | Nil = nil, items_empty_error : Proc(Nil) | Nil = nil) : Ast::Block | Nil #

[View source]
def block(opening_bracket_error : Proc(Nil) | Nil = nil, closing_bracket_error : Proc(Nil) | Nil = nil, items_empty_error : Proc(Nil) | Nil = nil, & : -> Ast::Node | Nil) : Ast::Block | Nil #

[View source]
def bool_literal : Ast::BoolLiteral | Nil #

[View source]
def bracket_access(expression : Ast::Node) : Ast::BracketAccess | Nil #

[View source]
def brackets(opening_bracket_error : Proc(Nil) | Nil = nil, closing_bracket_error : Proc(Nil) | Nil = nil, empty_check : Proc(T, Nil) | Nil = nil, & : -> T | Nil) : T | Nil forall T #

Parses a block surrounded by brackets.


[View source]
def builtin : Ast::Builtin | Nil #

[View source]
def call(expression : Ast::Node) : Ast::Call | Nil #

[View source]
def case_branch(*, for_css : Bool = false) : Ast::CaseBranch | Nil #

[View source]
def case_expression(*, for_css : Bool = false) : Ast::Case | Nil #

[View source]
def char : Char #

Returns the current character.


[View source]
def char(& : Char -> Bool) #

If the character is parsed with the given block, moves the cursor forward.


[View source]
def char!(expected : Char) #

If the character is the current character, moves the cursor forward.


[View source]
def chars(& : Char -> Bool) #

Consumes characters while the yielded value is true or we reach the end of the file.


[View source]
def chars(*next_chars : Char) #

Consumes characters while the yielded value is in one of the given characters.


[View source]
def comment : Ast::Comment | Nil #

[View source]
def commented_expression : Ast::CommentedExpression | Nil #

[View source]
def component : Ast::Component | Nil #

[View source]
def connect : Ast::Connect | Nil #

[View source]
def connect_variable #

[View source]
def constant : Ast::Constant | Nil #

[View source]
def consume(& : -> Bool) : Nil #

Consumes characters until the yielded value is true.


[View source]
def css_definition : Ast::CssDefinition | Nil #

[View source]
def css_font_face : Ast::CssFontFace | Nil #

[View source]
def css_keyframes : Ast::CssKeyframes | Nil #

[View source]
def css_nested_at : Ast::CssNestedAt | Nil #

[View source]
def css_node : Ast::Node | Nil #

[View source]
def css_selector(only_definitions : Bool = false) : Ast::CssSelector | Nil #

[View source]
def css_selector_name : String | Nil #

[View source]
def dbg : Ast::Dbg | Nil #

[View source]
def decode : Ast::Decode | Nil #

[View source]
def defer : Ast::Defer | Nil #

[View source]
def destructuring : Ast::Node | Nil #

[View source]
def discard #

[View source]
def emit : Ast::Emit | Nil #

[View source]
def encode : Ast::Encode | Nil #

[View source]
def env : Ast::Env | Nil #

[View source]
def eof! : Bool #

Checks if we reached the end of the file, adds an error otherwise.


[View source]
def eof? : Bool #

Returns whether or not the cursor is at the end of the file.


[View source]
def error(name : Symbol, &) : Nil #

[View source]
def errors : Array(Error) #

The errors found.


[View source]
def expression : Ast::Node | Nil #

[View source]
def field(*, key_required : Bool = true) : Ast::Field | Nil #

[View source]
def field_access : Ast::FieldAccess | Nil #

[View source]
def file : File #

The parsed file, we save it so we can show parse errors.


[View source]
def for_expression : Ast::For | Nil #

[View source]
def format_directive : Ast::Directives::Format | Nil #

[View source]
def function : Ast::Function | Nil #

[View source]
def gather(&) : String | Nil #

Starts to parse something, if the cursor moved during, return the parsed string.


[View source]
def get : Ast::Get | Nil #

[View source]
def here_document : Ast::HereDocument | Nil #

[View source]
def highlight_directive : Ast::Directives::Highlight | Nil #

[View source]
def highlight_file_directive : Ast::Directives::HighlightFile | Nil #

[View source]
def html_attribute(with_dashes : Bool = true) : Ast::HtmlAttribute | Nil #

[View source]
def html_body(*, expected_closing_bracket : Proc(Nil), expected_closing_tag : Proc(Nil), tag : Ast::Variable | Ast::Id, with_dashes : Bool) #

[View source]
def html_component : Ast::HtmlComponent | Nil #

[View source]
def html_element : Ast::HtmlElement | Nil #

[View source]
def html_fragment : Ast::HtmlFragment | Nil #

[View source]
def html_style : Ast::HtmlStyle | Nil #

[View source]
def id(*, track : Bool = true) : Ast::Id | Nil #

[View source]
def identifier_constant : String | Nil #

Parses a constant identifier.


[View source]
def identifier_type : String | Nil #

Parses a type identifier.


[View source]
def identifier_variable : String | Nil #

Parses a variable identifier.


[View source]
def if_expression(for_css = false) : Ast::If | Nil #

[View source]
def inline_directive : Ast::Directives::Inline | Nil #

[View source]
def inline_function : Ast::InlineFunction | Nil #

[View source]
def input : Array(Char) #

The input which is an array of characters because this way it's faster in cases where the original code contains multi-byte characters.


[View source]
def interpolation : Ast::Interpolation | Nil #

[View source]
def interpolation(& : -> Ast::Node | Nil) : Ast::Interpolation | Nil #

[View source]
def js : Ast::Js | Nil #

[View source]
def keyword!(expected : String) : Bool #

Consumes a word and saves it as a keyword for syntax highlighting.


[View source]
def list(terminator : Char | Nil, separator : Char, & : -> T | Nil) : Array(T) forall T #

Parses a list of things, which ends in the terminator character and are separated by the separator character.


[View source]
def locale : Ast::Locale | Nil #

[View source]
def locale_key : Ast::LocaleKey | Nil #

[View source]
def many(parse_whitespace : Bool = true, & : -> T | Nil) : Array(T) forall T #

Parse many things separated by whitespace.


[View source]
def map : Ast::Map | Nil #

[View source]
def map_field : Ast::MapField | Nil #

[View source]
def module_definition : Ast::Module | Nil #

[View source]
def negated_expression : Ast::NegatedExpression | Nil #

[View source]
def next_call : Ast::NextCall | Nil #

[View source]
def next_char : Char #

Returns the next character.


[View source]
def number_literal : Ast::NumberLiteral | Nil #

[View source]
def oneof(& : -> T | Nil) : T | Nil forall T #

Parses a thing, if succeeds it discards all errors while parsing it.


[View source]
def operation(left : Ast::Node, operator : String, comment : Ast::Comment | Nil) : Ast::Operation | Nil #

Parses an operation, switching the operands if the precedence of the next operation is higher than the current one. The precedences can be found in the operator parser file.

Operations can be chained recursively with this method as seen below.


[View source]
def operator : Tuple(String, Ast::Comment | Nil) | Nil #

[View source]
def parenthesized_expression : Ast::ParenthesizedExpression | Nil #

[View source]
def parse : Nil #

[View source]
def parse(*, track : Bool = true, &) #

Parses a thing (an ast node). Yielding the start position so the thing getting parsed can use it. If the block returns nil or we rollback to the start position since it means the parsing has failed. track - if true we save the resulting node


[View source]
def parse_any : Nil #

[View source]
def pipe(operation : Ast::Operation) : Ast::Pipe | Ast::Operation | Nil #

This method rolls up an operation where the operator is "|>" into a single call. Every other operation is passed trough.


[View source]
def pipe(operation : Nil) : Ast::Pipe | Ast::Operation | Nil #

[View source]
def position : Location #

The position of the cursor, which is at the character we are currently parsing.


[View source]
def previous_char : Char #

Returns the previous character.


[View source]
def property : Ast::Property | Nil #

[View source]
def provider : Ast::Provider | Nil #

[View source]
def raw(terminator : Char, stop_on_interpolation : Bool = true) : String | Nil #

Parses a raw part of the input until we reach the terminator or an interpolation (if it's needed).


[View source]
def raw(token : String) : String | Nil #

Parses a raw part of the input until we reach the terminator or an interpolation.


[View source]
def raw(& : -> Bool) : String | Nil #

Parses a raw part of the input until we reach the terminator or an interpolation.


[View source]
def record(*, skip_empty : Bool = true) : Ast::Record | Nil #

[View source]
def record_update : Ast::RecordUpdate | Nil #

[View source]
def regexp_literal : Ast::RegexpLiteral | Nil #

[View source]
def return_call : Ast::ReturnCall | Nil #

[View source]
def route : Ast::Route | Nil #

[View source]
def routes : Ast::Routes | Nil #

[View source]
def signal : Ast::Signal | Nil #

[View source]
def spread #

[View source]
def state : Ast::State | Nil #

[View source]
def state_setter : Ast::StateSetter | Nil #

[View source]
def statement : Ast::Statement | Nil #

[View source]
def step #

Moves the cursor forward by one character.


[View source]
def store : Ast::Store | Nil #

[View source]
def string_literal(*, with_interpolation : Bool = true) : Ast::StringLiteral | Nil #

[View source]
def style : Ast::Style | Nil #

[View source]
def suite : Ast::Suite | Nil #

[View source]
def svg_directive : Ast::Directives::Svg | Nil #

[View source]
def test : Ast::Test | Nil #

[View source]
def tuple_destructuring : Ast::TupleDestructuring | Nil #

[View source]
def tuple_literal : Ast::TupleLiteral | Nil #

[View source]
def type : Ast::Type | Nil #

[View source]
def type_definition : Ast::TypeDefinition | Nil #

[View source]
def type_definition_field(*, raise_on_colon : Bool = true) : Ast::TypeDefinitionField | Nil #

[View source]
def type_destructuring : Ast::TypeDestructuring | Nil #

[View source]
def type_variable : Ast::TypeVariable | Nil #

[View source]
def type_variant : Ast::TypeVariant | Nil #

[View source]
def unary_minus : Ast::UnaryMinus | Nil #

[View source]
def use : Ast::Use | Nil #

[View source]
def value(subject : Symbol = :all) : Ast::Variable | Nil #

[View source]
def variable(*, track = true, extra_chars = [] of Char) : Ast::Variable | Nil #

[View source]
def variable_constant(*, track = true) : Ast::Variable | Nil #

[View source]
def whitespace : Nil #

Consumes all available whitespace.


[View source]
def whitespace! : Bool #

Consumes all available whitespace and returns true / false whether there were any.


[View source]
def whitespace? : Bool #

Returns whether the current character is a whitespace.


[View source]
def word : String | Nil #

Returns the word (non whitespace sequence) a the cursor.


[View source]
def word!(expected : String) : Bool #

Consumes a word and steps the cursor forward if successful.


[View source]
def word?(word) : Bool #

Returns whether or not the word is at the current position.


[View source]