class

Mint::Parser

Inherits Mint::Helpers < Mint::Warnable < Reference < Object

Constants

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

new(input : String, path : String)
Source

Class methods

parse(contents, file) : Ast
Source
parse(file) : Ast
Source
parse?(contents, file) : Ast | Error
Source
parse_any(contents, file) : Ast
Source
parse_any(file) : Ast
Source
parse_with_warnings(contents, file) : Tuple(Ast | Error, Array(Warning))
Source
parse_with_warnings(file) : Tuple(Ast | Error, Array(Warning))
Source

Instance methods

access(expression : Ast::Node) : Ast::Access | Nil
Source
argument(*, parse_default_value : Bool = true) : Ast::Argument | Nil
Source
array_destructuring
Source
array_literal
Source
ascii_letters_or_numbers(*, extra_char : Char | Nil = nil)

Parses any number of ascii latters or numbers.

Source
ascii_uppercase_and_underscore

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

Source
ascii_word

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

Source
asset_directive
Source
ast

The abstract syntax tree.

Source
await
Source
base_expression
Source
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
Source
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
Source
bool_literal
Source
bracket_access(expression : Ast::Node) : Ast::BracketAccess | Nil
Source
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.

Source
builtin
Source
call(expression : Ast::Node) : Ast::Call | Nil
Source
case_branch(*, for_css : Bool = false) : Ast::CaseBranch | Nil
Source
case_expression(*, for_css : Bool = false) : Ast::Case | Nil
Source
char

Returns the current character.

Source
char

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

Source
char!(expected : Char)

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

Source
chars

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

Source
chars(*next_chars : Char)

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

Source
comment
Source
commented_expression
Source
component
Source
connect
Source
connect_variable
Source
constant
Source
consume

Consumes characters until the yielded value is true.

Source
context
Source
css_definition
Source
css_font_face
Source
css_keyframes
Source
css_nested_at
Source
css_node
Source
css_selector(only_definitions : Bool = false) : Ast::CssSelector | Nil
Source
css_selector_name
Source
decode
Source
defer
Source
destructuring
Source
discard
Source
emit
Source
encode
Source
eof!

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

Source
eof?

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

Source
error(name : Symbol, &) : Nil
Source
errors

The errors found.

Source
expression
Source
field(*, key_required : Bool = true, discard : Bool = false, destructuring : Bool = false) : Ast::Field | Nil
Source
field_access
Source
file

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

Source
for_expression
Source
format_directive
Source
function
Source
gather

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

Source
here_document
Source
highlight_directive
Source
highlight_file_directive
Source
html_attribute(with_dashes : Bool = true) : Ast::HtmlAttribute | Nil
Source
html_body(*, expected_closing_bracket : Proc(Nil), expected_closing_tag : Proc(Nil), tag : Ast::Variable | Ast::Id, with_dashes : Bool)
Source
html_component
Source
html_element
Source
html_fragment
Source
html_style
Source
id(*, track : Bool = true) : Ast::Id | Nil
Source
identifier_constant

Parses a constant identifier.

Source
identifier_type

Parses a type identifier.

Source
identifier_variable

Parses a variable identifier.

Source
if_expression(for_css = false) : Ast::If | Nil
Source
inline_directive
Source
inline_function
Source
input

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

Source
interpolation
Source
interpolation
Source
keyword!(expected : String) : Bool

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

Source
last_non_whitespace_position

Returns the last non whitespace position.

Source
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.

Source
locale
Source
locale_key
Source
many(parse_whitespace : Bool = true, & : -> T | Nil) : Array(T) forall T

Parse many things separated by whitespace.

Source
map_field
Source
module_definition
Source
negated_expression
Source
next_call
Source
next_char

Returns the next character.

Source
number_literal
Source
oneof

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

Source
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.

Source
operator
Source
parenthesized_expression
Source
parse
Source
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

Source
parse_any
Source
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.

Source
pipe(operation : Nil) : Ast::Pipe | Ast::Operation | Nil
Source
position

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

Source
previous_char

Returns the previous character.

Source
property
Source
provide
Source
provider
Source
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).

Source
raw(token : String) : String | Nil

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

Source
raw

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

Source
record(*, skip_empty : Bool = true) : Ast::Record | Nil
Source
record_destructuring
Source
record_update
Source
regexp_literal
Source
return_call
Source
route
Source
routes
Source
signal
Source
size_directive
Source
spread
Source
state
Source
state_setter
Source
statement
Source
step

Moves the cursor forward by one character.

Source
store
Source
string_literal(*, with_interpolation : Bool = true) : Ast::StringLiteral | Nil
Source
style
Source
suite
Source
svg_directive
Source
test
Source
tuple_destructuring
Source
tuple_literal
Source
type
Source
type_definition
Source
type_definition_field(*, raise_on_colon : Bool = true) : Ast::TypeDefinitionField | Nil
Source
type_destructuring
Source
type_variable
Source
type_variant
Source
unary_minus
Source
value(subject : Symbol = :all) : Ast::Variable | Nil
Source
variable(*, track = true, extra_chars = [] of Char) : Ast::Variable | Nil
Source
variable_constant(*, track = true) : Ast::Variable | Nil
Source
whitespace

Consumes all available whitespace.

Source
whitespace!

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

Source
whitespace?

Returns whether the current character is a whitespace.

Source
word(position : Location)

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

Source
word

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

Source
word!(expected : String) : Bool

Consumes a word and steps the cursor forward if successful.

Source
word?(word) : Bool

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

Source

Nested types