class Mint::Parser
- Mint::Parser
- Reference
- Object
Included Modules
Defined in:
parser.crparser/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
- .parse(contents, file) : Ast
- .parse(file) : Ast
- .parse?(contents, file) : Ast | Error
- .parse_any(contents, file) : Ast
- .parse_any(file) : Ast
Instance Method Summary
- #access(expression : Ast::Node) : Ast::Access | Nil
- #argument(*, parse_default_value : Bool = true) : Ast::Argument | Nil
- #array_destructuring : Ast::ArrayDestructuring | Nil
- #array_literal : Ast::ArrayLiteral | Nil
-
#ascii_letters_or_numbers(*, extra_char : Char | Nil = nil)
Parses any number of ascii latters or numbers.
-
#ascii_uppercase_and_underscore
Parses any number of ascii uppercase latters, numbers or underscore and must start with an uppercase letter.
-
#ascii_word : String
Returns the current word (sequence of ascii lowercase letters).
- #asset_directive : Ast::Directives::Asset | Nil
-
#ast : Mint::Ast
The abstract syntax tree.
- #await : Ast::Await | Nil
- #base_expression : Ast::Node | Nil
- #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
- #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
- #bool_literal : Ast::BoolLiteral | Nil
- #bracket_access(expression : Ast::Node) : Ast::BracketAccess | Nil
-
#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.
- #builtin : Ast::Builtin | Nil
- #call(expression : Ast::Node) : Ast::Call | Nil
- #case_branch(*, for_css : Bool = false) : Ast::CaseBranch | Nil
- #case_expression(*, for_css : Bool = false) : Ast::Case | Nil
-
#char : Char
Returns the current character.
-
#char(& : Char -> Bool)
If the character is parsed with the given block, moves the cursor forward.
-
#char!(expected : Char)
If the character is the current character, moves the cursor forward.
-
#chars(& : Char -> Bool)
Consumes characters while the yielded value is true or we reach the end of the file.
-
#chars(*next_chars : Char)
Consumes characters while the yielded value is in one of the given characters.
- #comment : Ast::Comment | Nil
- #commented_expression : Ast::CommentedExpression | Nil
- #component : Ast::Component | Nil
- #connect : Ast::Connect | Nil
- #connect_variable
- #constant : Ast::Constant | Nil
-
#consume(& : -> Bool) : Nil
Consumes characters until the yielded value is true.
- #css_definition : Ast::CssDefinition | Nil
- #css_font_face : Ast::CssFontFace | Nil
- #css_keyframes : Ast::CssKeyframes | Nil
- #css_nested_at : Ast::CssNestedAt | Nil
- #css_node : Ast::Node | Nil
- #css_selector(only_definitions : Bool = false) : Ast::CssSelector | Nil
- #css_selector_name : String | Nil
- #dbg : Ast::Dbg | Nil
- #decode : Ast::Decode | Nil
- #defer : Ast::Defer | Nil
- #destructuring : Ast::Node | Nil
- #discard
- #emit : Ast::Emit | Nil
- #encode : Ast::Encode | Nil
- #env : Ast::Env | Nil
-
#eof! : Bool
Checks if we reached the end of the file, adds an error otherwise.
-
#eof? : Bool
Returns whether or not the cursor is at the end of the file.
- #error(name : Symbol, &) : Nil
-
#errors : Array(Error)
The errors found.
- #expression : Ast::Node | Nil
- #field(*, key_required : Bool = true) : Ast::Field | Nil
- #field_access : Ast::FieldAccess | Nil
-
#file : File
The parsed file, we save it so we can show parse errors.
- #for_expression : Ast::For | Nil
- #format_directive : Ast::Directives::Format | Nil
- #function : Ast::Function | Nil
-
#gather(&) : String | Nil
Starts to parse something, if the cursor moved during, return the parsed string.
- #get : Ast::Get | Nil
- #here_document : Ast::HereDocument | Nil
- #highlight_directive : Ast::Directives::Highlight | Nil
- #highlight_file_directive : Ast::Directives::HighlightFile | Nil
- #html_attribute(with_dashes : Bool = true) : Ast::HtmlAttribute | Nil
- #html_body(*, expected_closing_bracket : Proc(Nil), expected_closing_tag : Proc(Nil), tag : Ast::Variable | Ast::Id, with_dashes : Bool)
- #html_component : Ast::HtmlComponent | Nil
- #html_element : Ast::HtmlElement | Nil
- #html_fragment : Ast::HtmlFragment | Nil
- #html_style : Ast::HtmlStyle | Nil
- #id(*, track : Bool = true) : Ast::Id | Nil
-
#identifier_constant : String | Nil
Parses a constant identifier.
-
#identifier_type : String | Nil
Parses a type identifier.
-
#identifier_variable : String | Nil
Parses a variable identifier.
- #if_expression(for_css = false) : Ast::If | Nil
- #inline_directive : Ast::Directives::Inline | Nil
- #inline_function : Ast::InlineFunction | Nil
-
#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.
- #interpolation : Ast::Interpolation | Nil
- #interpolation(& : -> Ast::Node | Nil) : Ast::Interpolation | Nil
- #js : Ast::Js | Nil
-
#keyword!(expected : String) : Bool
Consumes a word and saves it as a keyword for syntax highlighting.
-
#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.
- #locale : Ast::Locale | Nil
- #locale_key : Ast::LocaleKey | Nil
-
#many(parse_whitespace : Bool = true, & : -> T | Nil) : Array(T) forall T
Parse many things separated by whitespace.
- #map : Ast::Map | Nil
- #map_field : Ast::MapField | Nil
- #module_definition : Ast::Module | Nil
- #negated_expression : Ast::NegatedExpression | Nil
- #next_call : Ast::NextCall | Nil
-
#next_char : Char
Returns the next character.
- #number_literal : Ast::NumberLiteral | Nil
-
#oneof(& : -> T | Nil) : T | Nil forall T
Parses a thing, if succeeds it discards all errors while parsing it.
-
#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.
- #operator : Tuple(String, Ast::Comment | Nil) | Nil
- #parenthesized_expression : Ast::ParenthesizedExpression | Nil
- #parse : Nil
-
#parse(*, track : Bool = true, &)
Parses a thing (an ast node).
- #parse_any : Nil
-
#pipe(operation : Ast::Operation) : Ast::Pipe | Ast::Operation | Nil
This method rolls up an operation where the operator is "|>" into a single call.
- #pipe(operation : Nil) : Ast::Pipe | Ast::Operation | Nil
-
#position : Location
The position of the cursor, which is at the character we are currently parsing.
-
#previous_char : Char
Returns the previous character.
- #property : Ast::Property | Nil
- #provider : Ast::Provider | Nil
-
#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).
-
#raw(token : String) : String | Nil
Parses a raw part of the input until we reach the terminator or an interpolation.
-
#raw(& : -> Bool) : String | Nil
Parses a raw part of the input until we reach the terminator or an interpolation.
- #record(*, skip_empty : Bool = true) : Ast::Record | Nil
- #record_update : Ast::RecordUpdate | Nil
- #regexp_literal : Ast::RegexpLiteral | Nil
- #return_call : Ast::ReturnCall | Nil
- #route : Ast::Route | Nil
- #routes : Ast::Routes | Nil
- #signal : Ast::Signal | Nil
- #spread
- #state : Ast::State | Nil
- #state_setter : Ast::StateSetter | Nil
- #statement : Ast::Statement | Nil
-
#step
Moves the cursor forward by one character.
- #store : Ast::Store | Nil
- #string_literal(*, with_interpolation : Bool = true) : Ast::StringLiteral | Nil
- #style : Ast::Style | Nil
- #suite : Ast::Suite | Nil
- #svg_directive : Ast::Directives::Svg | Nil
- #test : Ast::Test | Nil
- #tuple_destructuring : Ast::TupleDestructuring | Nil
- #tuple_literal : Ast::TupleLiteral | Nil
- #type : Ast::Type | Nil
- #type_definition : Ast::TypeDefinition | Nil
- #type_definition_field(*, raise_on_colon : Bool = true) : Ast::TypeDefinitionField | Nil
- #type_destructuring : Ast::TypeDestructuring | Nil
- #type_variable : Ast::TypeVariable | Nil
- #type_variant : Ast::TypeVariant | Nil
- #unary_minus : Ast::UnaryMinus | Nil
- #use : Ast::Use | Nil
- #value(subject : Symbol = :all) : Ast::Variable | Nil
- #variable(*, track = true, extra_chars = [] of Char) : Ast::Variable | Nil
- #variable_constant(*, track = true) : Ast::Variable | Nil
-
#whitespace : Nil
Consumes all available whitespace.
-
#whitespace! : Bool
Consumes all available whitespace and returns true / false whether there were any.
-
#whitespace? : Bool
Returns whether the current character is a whitespace.
-
#word : String | Nil
Returns the word (non whitespace sequence) a the cursor.
-
#word!(expected : String) : Bool
Consumes a word and steps the cursor forward if successful.
-
#word?(word) : Bool
Returns whether or not the word is at the current position.
Instance methods inherited from module Mint::Helpers
owns?(node : Ast::Node, parent : Ast::Node) : Bool
owns?,
static?(nodes : Array(Ast::Node)) : Boolstatic?(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
Class Method Detail
Instance Method Detail
Parses any number of ascii latters or numbers.
Parses any number of ascii uppercase latters, numbers or underscore and must start with an uppercase letter.
Returns the current word (sequence of ascii lowercase letters).
Parses a block surrounded by brackets.
If the character is parsed with the given block, moves the cursor forward.
Consumes characters while the yielded value is true or we reach the end of the file.
Consumes characters while the yielded value is in one of the given characters.
Starts to parse something, if the cursor moved during, return the parsed string.
The input which is an array of characters because this way it's faster in cases where the original code contains multi-byte characters.
Consumes a word and saves it as a keyword for syntax highlighting.
Parses a list of things, which ends in the terminator character and are separated by the separator character.
Parse many things separated by whitespace.
Parses a thing, if succeeds it discards all errors while parsing it.
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.
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
This method rolls up an operation where the operator is "|>" into a single call. Every other operation is passed trough.
The position of the cursor, which is at the character we are currently parsing.
Parses a raw part of the input until we reach the terminator or an interpolation (if it's needed).
Parses a raw part of the input until we reach the terminator or an interpolation.
Parses a raw part of the input until we reach the terminator or an interpolation.
Consumes all available whitespace and returns true / false whether there were any.
Consumes a word and steps the cursor forward if successful.